Varying parameters

How does GLSL map varying’s from vertex shader output to fragment shader input?

Are the interpolants (all vertex input attributes) always interpolated regardless of what varying parameters are being specified?

Is it hardware/implementation dependent?

Thanks.

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.

ic ic…I meant vertex output. Sorry.

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?

varying attribute

Varyings are not attributes. Attributes are vertex inputs. Varyings are vertex outputs.

And I answered your question already in the second paragraph.

ic ic…

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.

sent to the frag shader? If they are all interpolated then they should be accessible from the frag shader with no issue.

Again, you’re making less sense than before. What “they” are you talking about being interpolated?

And why have you not read the documentation yet?

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.

Correct?

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.

My question is more about internal/low-level shader pipeline. I was wondering if these keywords (varying/in/out) are even necessary…

I can’t see how more patient could Alfonse be :slight_smile:
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:

  1. vertex inputs
  2. vertex outputs aka fragment inputs
  3. 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.

Ok. got it! Thanks.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.