I finally got around to looking at this problem again, so I wanted to post some 
more details on my solution as guided by Fred and Farshid's conversation in the 
thread linked above. Farshid's cull callback attached to the pre-render camera 
is the correct solution, the key being that the traversal operation has to 
happen before the near/far values are read out. I think I missed that (obvious) 
fact the first time I tried to solve it this way. There are a few more gotchyas 
to consider:

1) The cull visitor does some extra clamping of the near plane after the camera 
traversal returns. This logic is important if you plan to have the camera 
inside your geometry's bounds, like if you're using a first person manipulator 
to walk around your model. In that case the computed near plane can be a large 
negative number since one of the bounding-box borders is behind the camera. The 
logic you need to add is extracted from CullVisitor::popProjectionMatrix(). It 
consists of a call to computeNearFarPlane() (which Farshid has in his example), 
plus a call to clampProjecitonMatrix(...) which clamps the near plane to a 
proper positive value. You can call getProjectionMatrix() on the CullVisitor to 
get the current projection matrix that you need to pass into the clamp 
function. Note that getProjectionMatrix() returns a ref, so you probably want 
to make a copy of the matrix since the clamp function modifies it and you don't 
want that to happen twice (once when you call it on the
  ref, and again when the CullVisitor calls popProjectionMatrix). After this 
call the projection matrix and near/far values will be identical to the 
projection matrix that will be used to render the pre-render camera.

2) Be sure to set the pre-render camera near/far mode to 
COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES (or _PRIMITIVES if you choose), but 
whatever camera you push the planes to should be set to 
DO_NOT_COMPUTE_NEAR_FAR. Otherwise it will overwrite your settings on its cull 
pass.

With this, I was able to get my near/far clipping working correctly.

Thanks,
- Andy

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56609#56609





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to