> -----
> From: Robert Osfield
> Sent: Tuesday, May 20, 2008 10:47 PM
> 
> Hi Ben,
> 
> I've just done a quick review and the code looks correct to me.
> 
> > Now ShadowMap comes along, and the above code computes (0x4 & 0x2) == 0.
> A visitor mask of 0 finds nothing.  That's not right.
> 
> No it's perfectly correct

I'm sorry, but a node mask of 0 matches no nodes, and that's definitely not 
correct; this Visitor is supposed to find nodes which are drawn and cast 
shadows.  If it finds no nodes, it's not correct.  The question is, how can we 
fix it?

> this is how traversal masks are meant to be
> used.  However, if bits being used by the viewer are the same as the
> ones used by effects like osgShadow then there will be conflict

Yes, but they are not the same bits.  osgShadow is using bits 0x1 and 0x2.  The 
viewer is using bit 0x4.  It specifically is not using the same bits as 
osgshadow, to avoid the conflict.

> the only way to solve this is set the appropriate bits.  I can see use
> In your example where the viewers traversal mask is 0x4, this would be
> a very extreme setting - only accepting one bit for traversal is
> extremely picky.

I used an extreme example only to make a clear example of how the logic is 
wrong.  Consider the same example with a traversal mask of 0xfffffffc and the 
problem is the same: (traversalMask & CastsShadowMask) == 0.

The code:

> > cv.setTraversalMask( traversalMask &
> >   getShadowedScene()->getCastsShadowTraversalMask() );

Using a binary 'and' here only produces a non-zero result if the view mask and 
the osgshadow mask are overlapping.  In other words, the statement above fails 
as soon as the view mask is changed from 0xffffffff to something else.

As i wrote:

> > I can only imagine the ShadowMap author meant, they wanted to traverse
> nodes with _both_ bits set, both visible and casting.  But, AFAIK,
> NodeVisitor doesn't do AND, it only does OR.  That is, a traversal will
> always proceed when _any_ bit matches, not when _all_ bits match.  So the
> above is a bug from misunderstanding how NodeVisitor works.
> >
> > To replace the code with this, would at least fix the general case:
> >
> > cv.setTraversalMask( getShadowedScene()->getCastsShadowTraversalMask() );
> >
> > However, that doesn't correctly omit nodes which are casting but not
> drawn, e.g. mask=0x3 using the values above.  Perhaps it's just not
> possible for node traversal to do the correct thing?  Or maybe, there is
> some more powerful visitor capability in OSG that would save the day here?

The question remains, can a NodeVisitor be made to do a logical AND, instead of 
logical OR?  That's one way to make the code work.  Maybe there is another way 
to fix it i'm not seeing?

-Ben

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

Reply via email to