I've been messing around with GlSlang these last couple of days, since the new drivers came out. Thus far I've done infinite shadow volumes using the vertex shader, normal mapping and parallax mapping. I've been trying to extend my parallax mapping shader to offset the fragment depth values, but I'm getting strange behaviour from the shader. To test it out properly I wrote a simple program which simply renders a green quad with one shader and a red quad with another shader at exactly the same position. The red quad is rendered second using a GL_EQUAL depth test and the green quad is rendered with shaders which change the depth of the fragments. If I run them with the following shaders:
green quad shader:
void main()
{
gl_FragColor = gl_Color;
}
red quad shader:
void main()
{
gl_FragColor = gl_Color;
}
I get the expected result - the red quad is rendered. If I use:
green quad shader:
void main()
{
gl_FragColor = gl_Color;
gl_FragDepth = gl_FragCoord.z;
}
red quad shader:
void main()
{
gl_FragColor = gl_Color;
}
Again, as expected, the red quad is rendered. If I use:
green quad shader:
void main()
{
gl_FragColor = gl_Color;
gl_FragDepth = 0;
}
red quad shader:
void main()
{
gl_FragColor = gl_Color;
}
As expected the red quad is
not rendered because the depths no longer match. But if I use:
green quad shader:
void main()
{
gl_FragColor = gl_Color;
gl_FragDepth = gl_FragCoord.z + 1;
}
red quad shader:
void main()
{
gl_FragColor = gl_Color;
}
Then the red quad
is rendered, despite the fact it should have a different depth value. It doesn't even matter what constant I use. I tried +/- 0.00001, 0.01, 1, 100 and 100000 and the result was always the same. I've written depth values from ARB_ and NV_ fragment_programs before and don't remember encountering any problems like this. Is this a possible driver bug or am I just completely forgetting how to use depth values? Enigma