gl_FragDepth: undeclared identifier

Hi, I’m having some trouble with a GLSL shader on a MacBookPro (NVIDIA 9600) running Leopard.

When compiling the shader it complains that gl_FragDepth is undeclared. This shader runs nicely on linux

The code in question is the following function:

void calcFragDepth()
 gl_FragDepth = (log(log_depth_C * logDepthVertexPosClip.z + log_depth_offset) / log(log_depth_C * log_depth_far + log_depth_offset));

Any idea what I’m doing wrong?


Copy-pasting that into Shader Builder works fine here (after declaring all of those variables.)

You aren’t, by chance, attempting to write to gl_FragDepth in the vertex shader, are you?

ah, that’s it! I wasn’t actually writing to gl_FragDepth in the vertex shader, but that piece of code was included in the file even though it was never called.

I’ve made an include system and that function was in a utility file that was included in both the vertex and fragment shaders.

OSX is apparently a bit more sensitive than Linux on this point :slight_smile:

Thanks a lot for clearing that up for me!