[osg-users] performing manual depth test in shader code (for changing rendering style)

51 views
Skip to first unread message

Christian Buchner

unread,
Dec 2, 2014, 8:04:06 AM12/2/14
to OpenSceneGraph Users

Hi,

our client wants me to have some obscured 3D objects visible even if there's e.g. a building in front of it.  Order independent transparency rendering techniques such as depth peeling are too costly when it involves a city model with hundreds of buildings.

So I was thinking to simply change the rendering style whenever the fragment of my obscured object would not pass the depth test.

But I have no idea how one would implement a depth test in the fragment shader and adapt the rendering style based on its outcome. Is it really necessary to first render the entire scene into an FBO with a texture attached as a depth buffer so that you can sample this depth texture later? This seems extremely costly to me, as it would involve another full geometry pass.

Are there any osg examples that access the depth buffer from a shader?

Christian

Robert Osfield

unread,
Dec 2, 2014, 8:58:42 AM12/2/14
to OpenSceneGraph Users
Hi Christian,


As far as I'm aware your can't read the depth buffer from any of the shaders.

What you can do instead is use a multi-pass approach where you render the scene to a depth and colour texture and then read both in the shader during a second pass.  The second pass needn't render the whole scene, but could if this is what you wanted - typically you'd just render a screen aligned quad to fill in the final colour and depth buffers from the texture and then do any extra's you want.

In your case you probably don't need to play tricks with shaders.  You could render the scene without the objects of interests as normal, then in a second pass clear the depth buffer then render the objects that you want to force on top.   Another technique would be to use the stencil buffer.

Robert.

 

 

Christian Buchner

unread,
Dec 2, 2014, 9:28:37 AM12/2/14
to OpenSceneGraph Users

Simply switching off the z buffer test would be too simplistic, as it would not indicate visually if the object is unobstructed, partially obstructed or not obstructed at all.

But thank you for the hint to use the stencil buffer. This may be a decent way to move forward. Combining this with multiple render bins (passes) might allow me to get the desired effect.

Christian


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


Reply all
Reply to author
Forward
0 new messages