Re: [osg-users] Multiple ClearNodes in a scene, or 2D layering of 3D geometry

2009-05-15 Thread Robert Osfield
Hi Chris,

On Fri, May 15, 2009 at 2:10 AM, Chris 'Xenon' Hanson
xe...@alphapixel.com wrote:
  I will expand on the abstract explanation, and then reveal my optimal 
 solution -- which
 is a bit of a hack, but is still the most elegant.


  Basically we have VPB terrain for a very large area, but low detail. Within 
 it, we have
 a smaller world, which the user cannot leave. This terrain is also built with 
 VPB, at a
 much higher detail. This small world needs to be rebuilt frequently with 
 different data,
 and we don't wish to rebuild the entire surrounding world each time. this is 
 because the
 surrounding world doesn't change, and we don't want to spend all the time 
 rebuilding the
 surrounding world to the same degree of detail as the inset local world. It's 
 kind of like
 a skydome/box/environment technique, but it's a world-dome/box/environment. 
 It has to be
 rendered with Z-test and Z-write enabled to sort out self-occlusion, whereas 
 a skydome can
 often skip Z-test/z-write as long as it's a sphere and you use backface 
 culling.

Depth partioning then :-)


  The solution is to render the surrounding world, then wipe the Z-buffer, 
 then render the
 local world. this means that even if the local world terrain surface drops 
 below the
 surrounding world in the middle, it still obscures the exterior world. Things 
 could get
 weird close to the edge of the local world, but we prevent that from being an 
 issue by
 restrictions on the local world and near-edge movement.

  What I did was this:

  Render surrounding world in RenderBin -3.
  Create an empty piece of dummy Geometry (with a Geode) and render it in 
 RenderBin -2.
  Render the local world in RenderBin -1.

  The dummy geometry has a draw callback on it that issues a raw OpenGL 
 glClear() only on
 the Z-buffer channel. It doesn't disrupt the OpenGL state in any way, just 
 wipes the Z-buffer.

  It works great. no second cameras to track, no RTT, no goofy stuff. The only 
 cost is a
 full-screen Z-clear operation.

  Thanks to everyone for their suggestions.


So you're simulating using two slave Camera's for each of the depth
ranges.  osgViewer is capable of doing depth partioning although the
osgdepthpartition example hasn't yet been ported across to take
advantage of the flexibility of osgViewer,  it is something on my TODO
list.

By putting the management of the dept partitioning into the viewer
rather than the scene you remove viewing specific code form the scene
graph, and make it possible to load any scene into the viewer and have
it manage the depth partitioning automatically.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Multiple ClearNodes in a scene, or 2D layering of 3D geometry

2009-05-14 Thread Robert Osfield
Hi Chris,

On Thu, May 14, 2009 at 1:01 AM, Chris 'Xenon' Hanson
xe...@alphapixel.com wrote:
 The Goal: Render both of them, but with object A _always_ obscured by
 object B, regardless of what their Z values (which are mostly
 coincident) would normally dictate.

This type of task is exactly what the stencil buffer is good for.  The
OSG supports stencil buffer natively.  See the osgreflect example.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Multiple ClearNodes in a scene, or 2D layering of 3D geometry

2009-05-14 Thread Chris 'Xenon' Hanson
Robert Osfield wrote:
 This type of task is exactly what the stencil buffer is good for.  The
 OSG supports stencil buffer natively.  See the osgreflect example.

  I thought of that too, but it seemed like overkill since all I needed was a 
bulk Z clear
at the right time. Plus, I couldn't immediately describe to myself how the 
stencil buffer
would accomplish this. Don't you still need to wipe the Z values in order for 
the Object B
fragments to overwrite the Object A fragments (both of which have to be 
generated with Z
write and Z test enabled to self-occlude properly)?

 Robert.

-- 
Chris 'Xenon' Hanson, omo sanza lettere  Xenon AlphaPixel.com
PixelSense Landsat processing now available! http://www.alphapixel.com/demos/
There is no Truth. There is only Perception. To Perceive is to Exist. - Xen
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Multiple ClearNodes in a scene, or 2D layering of 3D geometry

2009-05-14 Thread Jean-Sébastien Guay

Hi Chris,


Paul suggested using multiple Camera objects in the Scene
and playing with the heirarchy, reference frame and identity matrix to
make a sub-camera track its parent.


That's probably what I would have tried too. It seems weird to me that 
the ClearNode clears at the start of rendering and not just when it's 
reached in the draw traversal, but perhaps that's the intended behavior.


Let us know what solution you come up with, it's an interesting problem. 
Just out of curiosity, what is the context for which you need this?


J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Multiple ClearNodes in a scene, or 2D layering of 3D geometry

2009-05-14 Thread Robert Osfield
On Thu, May 14, 2009 at 1:32 PM, Chris 'Xenon' Hanson
xe...@alphapixel.com wrote:
 Robert Osfield wrote:
 This type of task is exactly what the stencil buffer is good for.  The
 OSG supports stencil buffer natively.  See the osgreflect example.

  I thought of that too, but it seemed like overkill since all I needed was a 
 bulk Z clear
 at the right time. Plus, I couldn't immediately describe to myself how the 
 stencil buffer
 would accomplish this. Don't you still need to wipe the Z values in order for 
 the Object B
 fragments to overwrite the Object A fragments (both of which have to be 
 generated with Z
 write and Z test enabled to self-occlude properly)?

Well if just want to do a clear of the z buffer then the tool to use
an osg::Camera for the second pass, and have this camera use a
relative reference frame and identity view and projection matrices so
it doesn't change the view, but enable the clear of the depth buffer
but not the colour buffer.  This is very similar to how one can do
HUD's using Camera's, the only different being the how one sets the
ReferenceFrame.

FYI, ClearNode controls the clear of the RenderStage that it's nested
within.  A pre/post draw Camera is implemented in the rendering
back-end as a RenderStage (a nested Camera just ruses it RenderStage
it's within).  But... you don't really need the ClearNode has the
Camera has it's own settings you can use.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Multiple ClearNodes in a scene, or 2D layering of 3D geometry

2009-05-14 Thread Paul Martz
I Robert -- No, I don't think stencil applies here. Chris might not have
described the rendering task precisely. What he is trying to do is a sort of
smart depth partition, in which he knows that part of his scene graph is
always the background, and another part of always the foreground. So if he
can just clear depth after rendering the background, he has all that he
needs.

Now that I see how similar this is to depth partitioning, I wonder if slave
cameras are the way to go? They will both have the same view (but probably
different near/far planes).

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

-Original Message-
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert
Osfield
Sent: Thursday, May 14, 2009 2:38 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Multiple ClearNodes in a scene,or 2D layering of 3D
geometry

Hi Chris,

On Thu, May 14, 2009 at 1:01 AM, Chris 'Xenon' Hanson xe...@alphapixel.com
wrote:
 The Goal: Render both of them, but with object A _always_ obscured by 
 object B, regardless of what their Z values (which are mostly
 coincident) would normally dictate.

This type of task is exactly what the stencil buffer is good for.  The OSG
supports stencil buffer natively.  See the osgreflect example.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Multiple ClearNodes in a scene, or 2D layering of 3D geometry

2009-05-14 Thread Chris 'Xenon' Hanson
Paul Martz wrote:
 I Robert -- No, I don't think stencil applies here. Chris might not have
 described the rendering task precisely. What he is trying to do is a sort of
 smart depth partition, in which he knows that part of his scene graph is
 always the background, and another part of always the foreground.

  Paul is right. I tried to simplify it to make it easier to explain, but 
probably messed
it up.

  I will expand on the abstract explanation, and then reveal my optimal 
solution -- which
is a bit of a hack, but is still the most elegant.


  Basically we have VPB terrain for a very large area, but low detail. Within 
it, we have
a smaller world, which the user cannot leave. This terrain is also built with 
VPB, at a
much higher detail. This small world needs to be rebuilt frequently with 
different data,
and we don't wish to rebuild the entire surrounding world each time. this is 
because the
surrounding world doesn't change, and we don't want to spend all the time 
rebuilding the
surrounding world to the same degree of detail as the inset local world. It's 
kind of like
a skydome/box/environment technique, but it's a world-dome/box/environment. It 
has to be
rendered with Z-test and Z-write enabled to sort out self-occlusion, whereas a 
skydome can
often skip Z-test/z-write as long as it's a sphere and you use backface culling.

  The solution is to render the surrounding world, then wipe the Z-buffer, then 
render the
local world. this means that even if the local world terrain surface drops 
below the
surrounding world in the middle, it still obscures the exterior world. Things 
could get
weird close to the edge of the local world, but we prevent that from being an 
issue by
restrictions on the local world and near-edge movement.

  What I did was this:

  Render surrounding world in RenderBin -3.
  Create an empty piece of dummy Geometry (with a Geode) and render it in 
RenderBin -2.
  Render the local world in RenderBin -1.

  The dummy geometry has a draw callback on it that issues a raw OpenGL 
glClear() only on
the Z-buffer channel. It doesn't disrupt the OpenGL state in any way, just 
wipes the Z-buffer.

  It works great. no second cameras to track, no RTT, no goofy stuff. The only 
cost is a
full-screen Z-clear operation.

  Thanks to everyone for their suggestions.


  BTW, should we document that there really should only be one ClearNode in the 
scene
graph at a time, and what effect exactly it actually has?


-- 
Chris 'Xenon' Hanson, omo sanza lettere  Xenon AlphaPixel.com
PixelSense Landsat processing now available! http://www.alphapixel.com/demos/
There is no Truth. There is only Perception. To Perceive is to Exist. - Xen
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Multiple ClearNodes in a scene, or 2D layering of 3D geometry

2009-05-14 Thread Jean-Sébastien Guay

Hi Chris,


  I will expand on the abstract explanation, and then reveal my optimal 
solution -- which
is a bit of a hack, but is still the most elegant.


[...]

Wow, yeah that's a nice setup and good solution to it. I'll probably be 
able to use a similar technique in our simulators. Thanks for sharing 
more detail about your situation and solution!



  BTW, should we document that there really should only be one ClearNode in the 
scene
graph at a time, and what effect exactly it actually has?


Well, if the doxygen description of the class didn't clearly state that, 
then yes, it should be added, of course. I just read the description, 
and it contains other details but this (and the fact that it actually 
clears at the start of the frame and not when the node is reached in the 
draw traversal) is not mentioned.


J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org