Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The reason for gl_FragColor's removal [closed]

Tags:

opengl

glsl

Why do we have to define a new vec4 variable now, and the predefined gl_FragColor is removed?

like image 883
suyen729 Avatar asked Nov 01 '25 11:11

suyen729


1 Answers

Framebuffers can contain multiple attached images, permitting fragment shaders to write multiple output values. gl_FragColor is just a single vec4, so it does not accurately match the capabilities of the hardware.

Now, you could then turn around and ask why gl_FragData was removed, since that is an array sufficiently largest to represent the maximum number of attached images. That was removed because gl_FragData is a vec4[] array. That means it is an array of floating-point vectors. But not all attachment images have to use floating point image formats. You can use integer image formats too (not just normalized integer, but true integers).

If you want to write an integer value to an integer image attached to the FBO, the value from the fragment shader has to be an integer. So the variable representing that output needs to be an integer type, not a floating-point type. You can't do that with an array; each individual output variable needs to be able to have a separate type.

That can only happen if you allow users to declare specific output variables themselves. And once you give the user the power to do that, gl_FragData and gl_FragColor serve no purpose.

like image 122
Nicol Bolas Avatar answered Nov 04 '25 12:11

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!