0
votes

I'm learning to write fragment shaders, but as I'm playing with blending modes, I'm confused about incoming values of gl_FragColor.

When main() is called in the frag shader, before it's modified within main(), what is the value of gl_FragColor? Is it always vec4(0.0, 0.0, 0.0, 1.0)? Is it the value of of previous passes at that same pixel? Is it something else? How is the value determined?

1
As derhass states, it's purely an output value. Input values for your fragshader depend on the application, they could be a defined variable passed from a previous (frag)shader, or resolved from a texture with sampler2D, etcCrystalRain

1 Answers

4
votes

gl_FragColor is an output value, not an input one. The GLSL 1.0 ES spec states:

Reading from these variables before writing to them results in an undefined value

So you can't rely on it being set to antything particular at all.