Hi Marcel,
My depth buffers for deferred shading are usually setup like this:
texture->setUseHardwareMipMapGeneration(false);
texture->setSourceFormat(GL_DEPTH_COMPONENT);
texture->setSourceType(GL_FLOAT);
texture->setInternalFormat(GL_DEPTH32F_STENCIL8);
texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP);
texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP);
texture->setWrap(osg::Texture2D::WRAP_R,osg::Texture2D::CLAMP);
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);
Which seems to work well, on all my tested GPUs.
I never tested the color-buffer approach however, as it removes
hierarchical z-culling and other hardwired optimizations. How much
slower is it in your experience?
cheers
Sebastian
Hi,
I think the used data type for the depth texture is set wrong. A depth buffer
does not use a floating point type but a fixed point type.
When you access the texture in a shader you get values in the range of [0,1].
But it is stored as a 24 bit integer value in the texture. Just like a RGBA8
texture stores values from 0 to 255, they are returned as normalized [0,1]
values in the shader.
This may not be a huge problem as it seems to work anyways(either OSG or your
graphics driver is correcting this). But it could lead to undefined behaviour
on another machine.
You should set the source type to GL_UNSIGNED_BYTE. I now this looks strange as
this would only be 8 byte per component, but it is used in every OpenGL
tutorial I have seen so far. It seems to be the correct way.
As an alternative you could also use a GL_R32F or GL_LUMINANCE(deprecated in
OpenGL 4.0!) texture for your depth buffer.
For this you need to bind it to as a regular color buffer and write a shader
that calculates the depth. You could either directly write p_viewspace.z or
normalize it to the [0,1] range with (-p_viewspace.z-near)/(far-near).
With this approach you get a better precission and automatically get rid of
some nasty shadow mapping artifacts like moiré patterns.
The problem is that you lose hardware support and can not use "sampler2DShadow"
in your shader code. This could make the implementation a bit slower.
Thank you!
Cheers,
Marcel
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56691#56691
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org