I've been writing programs using OpenGL. Recently, I started learning OpenGL Shading Language. I'm a newbie; so please be detailed in your answers.
My questions are:
I am only familiar with "varying" variable which is passed from Vertex Shaders to Fragment Shaders to be interpolated between vertices. Other than that, I know nothing else.
In OpenGL 3+ :
varying
is deprecatedconst
is for... well, constants !uniform
is for per draw call (at most) valuesin
is for input from the previous pipeline stage, i.e. per vertex (or per fragment) values at most, per primitive if using glAttribDivisor and hardware instanciationout
is for output to the next stageRegarding outputs for fragment shaders : in OpenGL3 and up, most of the built-in variables for fragment shader output (such as gl_FragColor
, with the notable exception of gl_FragDepth
) are deprecated and should be replaced with user-defined out
variables.
If you are outputting to the default framebuffer, whatever you declare as the output of the fragment shader ends up in the color buffer. If you've bound an FBO with multiple color buffers (i.e. multiple render targets), you'll need to manually bind each of your out
variables to the correct color buffer index via glBindFragDataLocationIndexed
.
All the details you could ever want about both the GLSL ('server') side and the OpenGL ('client') side can be found :