Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which output variables from the vertex shader will be interpolated?

I noticed that out vec4 vertexColor variable in the vertex shader will be interpolated when entering the fragment shader in vec4 vertexColor. My question is, will all variables with the "out" modifier be interpolated or only a certain type?

like image 749
tomeadom Avatar asked Dec 17 '25 12:12

tomeadom


1 Answers

All user-defined inputs to the fragment shader are interpolated. How they are interpolated is a matter of the layout interpolation qualifier. By default, in will use smooth, but you can specify noperspective (interpolation in screen space with no perspective correction) or flat. The later performs "interpolation" by giving all fragments the value of the variable assigned to the provoking vertex of the primitive. Integral types being input by the FS must use flat, but the default is still smooth, so you will get a compile error if you don't explicitly specify flat for them.

Note that while you asked about vertex shader outputs, the answer is about fragment shader inputs. There's a reason for that.

First, there are multiple shader stages that can exist before the fragment shader. The values given to the FS come from the last active vertex processing shader stage: geometry shader, tessellation evaluation shader, or vertex shader. Mesh shaders (a relatively recent extension) change what vertex processing stages exist, but the last one is still the one that feeds the fragment shader.

So just talking about the "vertex shader" would be incomplete.

Second, interpolation qualifiers on vertex processing stage outputs are ignored. The only ones that matter are those on the fragment shader inputs. This is a relatively recent change, in terms of GLSL version numbers. Before GLSL 4.30, the final vertex processing stage outputs needed to have the same qualifiers as the corresponding fragment shader inputs. Since 4.30, they don't but the vertex output qualifiers are just ignored; only the fragment shader input qualifiers matter.

like image 153
Nicol Bolas Avatar answered Dec 19 '25 05:12

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!