I have some code that uses osg::ClipPlane to clip a hierarchy of meshes. All I do is create some plane equations relative to the root node's transform and set the planes as attributes that affect the entire tree.
This works pretty well. When I look at the output in gDEBugger, I can see that the clip equations are invoked after glLoadMatrix is called on the root transform. glEnable is called on the clip planes before any of the geometry in the hierarchy is drawn.
Currently, I need to port this functionality to a vertex shader for a project. Clipping in a shader is pretty straightforward, but I'm getting a little tripped up on what transformation space the clip planes should be in and how to transfer that to the vertex shader.
According to the glClipPlane docs, the plane equations are transformed to view space. In my shader, I'm passing the plane equations in as uniforms. For this to work on all vertices, I need to ensure that the clip plane equations have been transformed by the inverse transpose of the model view matrix. The only way that I can think of doing that is creating a uniform update callback which always updates the plane equations based on the camera's current model view matrix.
This seems a little clunky to me, but I wasn't sure how else to do it. Is there a simpler way that I'm overlooking? This fixed function pipeline model was convenient since it did a lot of this work for me, but it seems like I have to do on my own if I go the programmable pipeline route. Is this a correct assessment?
Thanks! And sorry if this is a bit long-winded.
-Dave
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=44278#44278
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
This is only applicable if you want to perform clipping in the same space as the
OpenGL FFP. Once you start using shaders, this is optional, and you can perform
clipping in some other space if it's more convenient. It's up to you.
> In my shader, I'm passing the plane equations in as uniforms. For this to work on all vertices, I need to ensure that the clip plane equations have been transformed by the inverse transpose of the model view matrix. The only way that I can think of doing that is creating a uniform update callback which always updates the plane equations based on the camera's current model view matrix.
If you're using a GLSL 1.20 shader, your shader would just multiply the clip
plane by the built-in uniform gl_ModelViewMatrixInverseTranspose.
-Paul
If you need to get same result as opengl FFP, you should add following line in your vertex shader: gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;
IIRC you need #version 120 to use this. Then all clip planes enabled via glEnable would work with shaders
07.12.2011, 22:36, "Dave Jones" <dave_...@hotmail.com>: