Trass3r
Trass3r

Reputation: 6287

Where do glsl interpolation qualifiers go?

GLSL interpolation qualifiers can be used in various places: https://www.khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Interpolation_qualifiers

But it isn't really explained whether they have to match (e.g. vertex out and fragment in) resp. what happens if they don't. The compiler does not seem to complain.

Upvotes: 2

Views: 1418

Answers (2)

Nicol Bolas
Nicol Bolas

Reputation: 474076

How interpolation qualifiers work with regard to interface matching has shifted in OpenGL over the various versions.

Pre-GL 4.3, interpolation qualifiers on inputs must match the corresponding output variable's interpolation qualifier from the preceding stage. Post-4.3, matching is unnecessary.

In both cases, it's reasonable to say that the only qualifiers the compiler will care about are the ones specified by the fragment shader's input variables. After all, in the pre-GL 4.3 case that requires exact matching, if the shader providing data to the FS uses a qualifier, the FS must use the same qualifier. And 4.3+, the standard explicitly says that only the fragment shader's qualifiers matter.

So if you want to know how a value will be interpolated, look at the fragment shader.

Upvotes: 2

Ripi2
Ripi2

Reputation: 7198

The wiki may be incomplete.

If you read the GLSL 4.6 Specification, item 4.5, "Interpolation Qualifiers" you see:

It is a link-time error if, within the same stage, the interpolation qualifiers of variables of the same name do not match.

EDIT:
As @NicolBolas pointed out, "within the same stage" is not the case.

Again in the GLSL spec, item 4.3.4 "Input Variables" we can read:

The fragment shader inputs form an interface with the last active shader in the vertex processing pipeline. For this interface, the last active shader stage output variables and fragment shader input variables of the same name must match in type and qualification, with a few exceptions: The storage qualifiers must, of course, differ (one is in and one is out). Also, interpolation qualification (e.g. flat) and auxiliary qualification (e.g. centroid) may differ. These mismatches are allowed between any pair of stages. When interpolation or auxiliary qualifiers do not match, those provided in the fragment shader supersede those provided in previous stages. If any such qualifiers are completely missing in the fragment shaders, then the default is used, rather than any qualifiers that may have been declared in previous stages. That is, what matters is what is declared in the fragment shaders, not what is declared in shaders in previous stages.

Upvotes: 2

Related Questions