3

Is not writing anything to gl_FragColor defined as equivalent of doing a discard or simply setting gl_FragColor to vec4(0, 0, 0, 0)?

(For the record, I'm asking this as I'm creating shaders which only writes to gl_FragDepth, for lighting purposes.)

Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90

1 Answers1

4

From the GLSL 4.5 specs...

The following fragment output variables are available in a fragment shader when using the compatibility profile:

out vec4 gl_FragColor;
out vec4 gl_FragData[gl_MaxDrawBuffers];

Writing to gl_FragColor specifies the fragment color that will be used by the subsequent fixed functionality pipeline. If subsequent fixed functionality consumes fragment color and an execution of the fragment shader executable does not write a value to gl_FragColor then the fragment color consumed is undefined.

So no, it's neither a discard, nor setting all zeroes. Different things can happen with different drivers and video cards; it's "undefined".

Pure speculation on my part but it's likely that what ever data happens to be in the physical registers when the shader returns ends up as the output. This would be largely dependent on the previous things the GPU was doing. It might be common for it to be all black, just like neglecting to initialize int *myPointer; in C can quite often end up with zero because it happens to be the initial state of the RAM.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
jozxyqk
  • 16,424
  • 12
  • 91
  • 180