PDA

View Full Version : emulate NV_depth_clamp on ATI



grisha
06-05-2008, 02:27 PM
I'm looking for a way to clamp depth values to near plane without clipping. I tried small fragment shader:


void main()
{
gl_FragDepth = max( gl_FragCoord.z, 0. );
}

but polygons are still clipped.

oc2k1
06-05-2008, 03:07 PM
the clipping runs before the fragment shader. So the fragments are already clipped away.

grisha
06-06-2008, 09:27 AM
I've finally found solution. This is for ortho projection, for perspective it will need additional check on Zeye - to clip everything behind the eye.



// Vertex shader:
varying float Zw;
void main()
{
vec4 clip = ftransform();
float Zd = clip.z/clip.w;
clip.z = max( Zd, -1. )*clip.w;
Zw = Zd*0.5 + 0.5;
gl_Position = clip;
}

// Fragment shader:
varying float Zw;
void main()
{
gl_FragDepth = max( Zw, 0. );
}