Re: [osg-users] Shadow vs reflection vs cull visitor

2011-05-19 Thread Wojciech Lewandowski

Hello !

I hope you don't mind I address you directly for this question, but as you 
implemented the view-dependent shadow techniques, you are best placed to 
answer it.


Well... we will see if I will be able to help here.

I am currently investigating a problem that seems to be caused by the 
ordering of RTT passes. I have a scene that uses osgOcean and osgShadow, 
and the shadow INSIDE the refraction (which is an RTT effect) is late 
compared to the shadows OUTSIDE the refraction (i.e. above the water 
level). What I mean by late is that the shadow moves away from the casting 
object if I move the eye around, but stops moving and is in the right 
place as soon as I stop moving the eye. So the refraction pass seems to be 
happening before the shadow pass.


I understand. I know this problem well from my experience.


The nodes are ordered like this:

root
ShadowedScene
   OceanScene
  the scene


And in the OceanScene traverse() method, there is a check if the current 
camera is the shadow pass camera or analysis camera (for DrawBounds 
techniques) and just do a regular traversal in that case. My expectation 
was that the first traversal of the OceanScene would be the shadow pass, 
then the main pass, and so when we do the refraction RTT (during the main 
pass), the shadow map would already be correct for the current frame.


[..] So the main pass is done (culled) before the shadow pass. I can 
understand that the bounds calculation needs to cull the shadow receiving 
scene first, or else we won't know where the shadow map should lie. 
However, I wonder how this even works.


Culling order does not need to be the same as Rendering order. Rendering 
order is defined by PRE_RENDER / POST_RENDER / NESTED_RENDER camera flag. 
Cull visitor on the other hand simply traverses the scene tree in first 
encountered/first processed order.


My understanding is that when the cull visitor traverses a scene graph, it 
accumulates the drawables and state into a list. It does this in the order 
it visits notes, and might reorder based on state or other criteria 
(distance to camera for the transparent bin, for example).


Sorting is done in Draw stage as far as I know.

So given the code above, how does the cullShadowCastingScene() manage to 
place the drawables for the shadow pass before the ones for the main pass, 
even though the cullShadowReceivingScene() (culling the main pass) is 
before?


Each camera has render order flag and associated RenderStage+RenderBin set. 
Cull visitor simply fills these render stage bins and state graphs without 
checking which will be rendered first. They are waiting for Draw phase to be 
rendered and they are then drawn in order defined by cameras. Main question 
here I believe is how to ensure that PRE_RENDER cameras will render in 
certain desired order. And honestly I don't know definite answer to this 
question. My tests with analysis  shadow cameras seem to suggest that first 
traversed by cull visitor will be rendered first. For DrawBounds method 
order of culling is 1: scene / 2: analysis / 3: shadow. Scene has standard 
order (i am not sure but suppose its NESTED) and analysis and  shadow are 
PRE_RENDER. So if analysis comes before shadow  (which I made sure it does) 
it means that first PRE_RENDER camera traversed by cull visitor will be 
drawn first.


I think for osgOcean's refraction pass to contain correct shadows, I would 
need to do something similar, i.e. place the drawables for that pass after 
the shadow pass, but before the main pass, in the render list. I'm 
actually surprised that's not what happens already, since the sequence 
should be:



cullShadowReceivingScene()
   -- eventually calls OceanScene::traverse()
 -- does cull for refraction RTT camera
 -- then does cull for main pass
cullShadowCastingScene()
   -- does shadow pass, somehow placing results before main pass, which 
for all it knows should contain the refraction pass


And the above order of cull visits explains the effect. I assume refraction 
RTT camera is PRE_RENDER cam like analisys and shadow. So its rendered first 
because its culled first.  You would need to put refraction cull after 
cullShadowCastingScene() to be sure it will get rendered at the right 
moment, I guess.



Thanks in advance,


You are welcome, but I doubt I helped ;-)
Cheers,

Wojtek

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


Re: [osg-users] Shadow vs reflection vs cull visitor

2011-05-19 Thread Jean-Sébastien Guay

Hi Wojtek,


Well... we will see if I will be able to help here.


Yes, I am sure you will! :-)


Each camera has render order flag and associated RenderStage+RenderBin
set.


Ah yes, I had forgotten about the render order number (integer to order 
more finely between PRE_RENDER cameras and so on). Perhaps that's the 
answer here?


And I checked, the main pass camera is POST_RENDER with a 
_renderOrderNum of 0.



And the above order of cull visits explains the effect. I assume
refraction RTT camera is PRE_RENDER cam like analisys and shadow. So its
rendered first because its culled first. You would need to put
refraction cull after cullShadowCastingScene() to be sure it will get
rendered at the right moment, I guess.


You're my hero!

I just set the refraction camera as PRE_RENDER, but with a number higher 
than the shadow pass and analysis cameras (I chose 1 since the shadow 
pass camera is PRE_RENDER 0), and it now happens before the main pass 
(since that is POST_RENDER 0), but after the shadow and analysis passes!


Thanks a million, I owe you yet another beer.

Though I kind of hate hard-coding the render order in osgOcean, since 
the shadow pass could be any render order number imaginable and it won't 
necessarily work then, but at least now it works with the default shadow 
technique. I think we might need a render passes manager in OSG that 
would work out the order of all passes in all libraries whether they 
know about each other or not... I know, wishful thinking :-)


Thanks again,

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


Re: [osg-users] Shadow vs reflection vs cull visitor

2011-05-19 Thread Paul Martz

On 5/19/2011 2:07 PM, Wojciech Lewandowski wrote:

[..] So the main pass is done (culled) before the shadow pass. I can
understand that the bounds calculation needs to cull the shadow receiving
scene first, or else we won't know where the shadow map should lie. However, I
wonder how this even works.


Culling order does not need to be the same as Rendering order. Rendering order
is defined by PRE_RENDER / POST_RENDER / NESTED_RENDER camera flag. Cull visitor
on the other hand simply traverses the scene tree in first encountered/first
processed order.


If you have multiple sibling Cameras with the same render order, their draw 
order is determined by their order in the scene graph (or by the CullVisitor, in 
other words).


The CullVisitor is assembling a graph of RenderBins. RenderStage derives from 
RenderBin. Each Camera keeps a cache of RenderStages indexed by CullVisitor 
address. Every time the CullVisitor encounters a Camera node (and the order 
isn't NESTED_RENDER), it inserts the Camera's RenderStage for that CullVisitor 
into the render graph.


Your Viewer object and/or SceneView has an implicit root Camera, and its 
corresponding RenderStage is the root node of the render graph. If that root 
Camera has two PRE_RENDER Camera children, child 0 and child 1, then the child 0 
Camera RenderStage gets added to the root Camera RenderStage's list of 
pre-render stages first, and the child 1 Camera RenderStage goes into that list 
second. During draw, RenderStage::draw() is called on the list of pre-render 
stages in the order they appear in the list -- in this case, the same order they 
were encountered by the CullVisitor.


All of the root Camera RenderStage's pre-render children are drawn before 
::draw() gets called on the root Camera RenderStage.


I hope that helps.
   -Paul

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


Re: [osg-users] Shadow vs reflection vs cull visitor

2011-05-19 Thread Wojciech Lewandowski

Hi,

I am glad you could solve it. I was not aware of _renderOrderNum index. So 
thanks, I have learned important new stuff today ;-)


I guess you had to override either Ocean or LispSM techniuque already. So 
you may set _renderOrderNum in overriden code. Depending on which one you 
overrode, I believe you may either set 1 for Refraction camera or  -1 for 
Analysis and Shadow cams.


Cheers,
Wojtek


Hi Wojtek,


Well... we will see if I will be able to help here.


Yes, I am sure you will! :-)


Each camera has render order flag and associated RenderStage+RenderBin
set.


Ah yes, I had forgotten about the render order number (integer to order
more finely between PRE_RENDER cameras and so on). Perhaps that's the
answer here?

And I checked, the main pass camera is POST_RENDER with a
_renderOrderNum of 0.


And the above order of cull visits explains the effect. I assume
refraction RTT camera is PRE_RENDER cam like analisys and shadow. So its
rendered first because its culled first. You would need to put
refraction cull after cullShadowCastingScene() to be sure it will get
rendered at the right moment, I guess.


You're my hero!

I just set the refraction camera as PRE_RENDER, but with a number higher
than the shadow pass and analysis cameras (I chose 1 since the shadow
pass camera is PRE_RENDER 0), and it now happens before the main pass
(since that is POST_RENDER 0), but after the shadow and analysis passes!

Thanks a million, I owe you yet another beer.

Though I kind of hate hard-coding the render order in osgOcean, since
the shadow pass could be any render order number imaginable and it won't
necessarily work then, but at least now it works with the default shadow
technique. I think we might need a render passes manager in OSG that
would work out the order of all passes in all libraries whether they
know about each other or not... I know, wishful thinking :-)

Thanks again,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.dyndns-web.com/
___
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] Shadow vs reflection vs cull visitor

2011-05-19 Thread Paul Martz

On 5/19/2011 2:51 PM, Paul Martz wrote:

On 5/19/2011 2:07 PM, Wojciech Lewandowski wrote:

[..] So the main pass is done (culled) before the shadow pass. I can
understand that the bounds calculation needs to cull the shadow receiving
scene first, or else we won't know where the shadow map should lie. However, I
wonder how this even works.


Culling order does not need to be the same as Rendering order. Rendering order
is defined by PRE_RENDER / POST_RENDER / NESTED_RENDER camera flag. Cull visitor
on the other hand simply traverses the scene tree in first encountered/first
processed order.


If you have multiple sibling Cameras with the same render order, their draw
order is determined by their order in the scene graph (or by the CullVisitor, in
other words).


Scratch that statement, in light of the render order num discussion in this 
thread. :-)


On the other hand, if the render order number is *also* the same...
   -Paul
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Shadow vs reflection vs cull visitor

2011-05-19 Thread Jean-Sébastien Guay

Hi Wojtek,

Just a quick follow-up on this:


I guess you had to override either Ocean or LispSM techniuque already.


I was wondering, if I ever need to override LispSM's ViewData class, how 
would I go about it? I guess I need to override the *ShadowMap class as 
well so that it instantiates my new derived ViewData class instead of 
the default one in the *ShadowMap class itself?


I think you've said this before but it's been a while and I can't find 
it in the archives.


Thanks,

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


Re: [osg-users] Shadow vs reflection vs cull visitor

2011-05-19 Thread Jean-Sébastien Guay

Hi Wojtek,


I guess you had to override either Ocean or LispSM techniuque already.
So you may set _renderOrderNum in overriden code. Depending on which one
you overrode, I believe you may either set 1 for Refraction camera or -1
for Analysis and Shadow cams.


Actually I'm working on osgOcean a lot lately (and I'm co-developer on 
it so I have commit access). So this is going straight into the osgOcean 
code. Since the default shadow techniques in OSG all use PRE_RENDER #0 
for their shadow pass cameras, it's a safe change to set the refraction 
one (and other PRE_RENDER passes in osgOcean) to PRE_RENDER #1.


Thanks for your help,

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


Re: [osg-users] Shadow vs reflection vs cull visitor

2011-05-19 Thread Jean-Sébastien Guay

Hi Paul,


On the other hand, if the render order number is *also* the same...


Thanks for going over the basics again for me, I knew all that but for 
some reason had completely forgotten about the render order number 
(_renderOrderNum)...


So yeah, the RenderStages are ordered in order of _renderOrder 
(PRE_RENDER before NESTED_RENDER before POST_RENDER), if 2 cameras have 
the same _renderOrder they are ordered by _renderOrderNum, and if they 
have the same _renderOrder AND _renderOrderNum they are ordered in the 
order they were traversed by the CullVisitor (their order in the graph).


That explains both why the shadow pass renders before the main pass in 
StandardShadowMap::ViewData::cull(), and why I was getting the results I 
was getting for the shadows in the refraction, as Wojtek said:


cullShadowReceivingScene()  (main pass camera is POST_RENDER #0)
  .. eventually goes into OceanScene::traverse()
.. eventually culls refraction camera (PRE_RENDER #0)
cullShadowCastingScene() (shadow pass camera is PRE_RENDER #0)

So the order of rendering of the cameras (or RenderStages to be more 
correct) was:


refraction (PRE_RENDER #0 traversed before shadow pass camera)
shadow pass (PRE_RENDER #0 traversed after refraction camera)
main pass (POST_RENDER #0)

which explains why the refraction was using the shadow map from the 
previous frame, the shadow map for this frame wasn't rendered yet.


I knew the error was ordering of the passes, I just didn't know why the 
order was wrong. So I'm explaining this as much for myself as for others.


Now I've set the refraction pass _renderOrderNum to 1 (it could be any 
number  0 so it occurs after the shadow pass) and everything is fine.


Thanks Wojtek and Paul for reminding me of lots of little things, and 
filling in gaps in my knowledge, thanks to you I was able to fix this 
bug and my users are happy once again :-)


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