Are the interpolants (all vertex input attributes) always interpolated regardless of what varying parameters are being specified?
What? Vertex input attributes are not interpolated across anything. The only things that get interpolated are vertex (or geometry) outputs.
And yes; the vertex shader outputs are always interpolated. Exactly how they’re interpolated depends on what modifiers you give the input/output variables. See the GLSL spec for more details.
But my question is are all possible vertex output always interpolated and whatever I pick as a varying attribute then it’s received by the fragment? or only attributes specified as varying get interpolated?
then why do we need to specify “out” in vertex shader, and “in” in the fragment shader, if they r all interpolated regardless? We can just pick whatever we want as an input in the main() inside the fragment shader. Does that make sense?
then why do we need to specify “out” in vertex shader, and “in” in the fragment shader, if they r all interpolated regardless? We can just pick whatever we want as an input in the main() inside the fragment shader. Does that make sense?
The only values that are sent to the fragment shader from the vertex/geometry shader are those that are designated as output variables. Regular global variables, uniforms, etc, are not sent to the fragment shader.
What you’re talking about makes increasingly less sense as you go along. Maybe you should read the GLSL specification.
My understanding is that interpolants (vertex input) are all register values for all possible input to vertex processing pipeline (colors, texture coords, vertex pos, normals,…)
Now the fragment shader can pick which one to read from the interpolated values vs. pick which one to interpolate.
Am I correct?
And the in/out keywords are a way to declare these variables as being hw register aliases.
A vertex shader reads inputs and uniforms, does some arbitrary computations on these, and writes outputs. Vertex shader inputs are attributes passed in through vertex buffers. Vertex shader outputs are either passed as inputs to a geometry shader or directly interpolated across a primitive and used as inputs to the fragment shader.
A fragment shader reads inputs and uniforms, does some arbitrary computations of these, and writes outputs. The fragment shader inputs are values that were interpolated across the primitive for this particular sample. The fragment shader outputs are written to one or more framebuffers, in accord with the blending parameters.
If that’s too complicated, here’s a diagram:
Vertex shader Fragment shader
inputs outputs inputs outputs
position \ / gl_Position
normal >compute< lightSpaceNorm-Intp->lightSpaceNorm\ /outColor
texCoord1/ \ diffuseCoord---Intp->diffuseCoord--->compute<
Data flows from left to right. Intp stands for Interpolate.
The fragment shader cannot read vertex shader input, because that data has been consumed, processed, and discarded long before this instance of the fragment shader was activated.
I can’t see how more patient could Alfonse be
He described in detail the interpolation process you are interested in. The need for ‘in/out’ is pretty obvious: try to imagine a shader program without them.
I think as others have said, you’re confusing things. In the old world (pre geometry shaders), in terms of per-vertex/pixel data flow you have:
vertex inputs
vertex outputs aka fragment inputs
fragment outputs
Compiler has to know which is which so it can manage the data flow properly (build an expression DAG, throw away unused code, store outputs in the right places, etc.)
Class #2 (vtx out / frag in) was identified by “varying”. “varying” in vertex shader implicitly meant output. “varying” in fragment shader implicitly meant input. It works, and it was good.
Then along came geometry shaders to muck up this simple world. varying isn’t sufficient there to identify inputs and outputs because you might have varying inputs “and” outputs. And thus the ARB spoke “in”/“out” into existance (AFAIK). With this, there’s no ambiguity whether the identifier is an input or an output. And so the compilers were happy once more.