# GLSL “varying” interpolation: component-wise? Reference in the spec?

Probably a dumb question, but I can't find (or am not understanding) a conclusive answer in the spec or in other questions (e.g., this one).

For smoothly-interpolated varying vec and mat vertex shader outputs / fragment shader inputs, is each element of the vector or matrix interpolated individually?

GL spec sec. 13.5.1 (clipping) describes linear clip-space interpolation of the "output values associated with a vertex." It also says that those are componentwise for vectors, but doesn't mention matrices.

Similarly, sec. 14.5.1 (rasterizing lines) and sec 14.6 (rasterizing polygons) describe interpolation of an "associated datum f for the fragment". Is each element of a vector or matrix considered an individual "associated datum" and interpolated independently from the other elements of the vector or matrix?

Secs. 11.1.3.10 (shader outputs) and 15.1 (fragment shader variables) mention interpolation but refer elsewhere for the details.

Similarly, in the GLSL spec, sec. 4.5 (interpolation qualifiers) says that interpolation happens but does not distinguish scalars from multi-component variables.

I am looking for a definitive statement about how vecs and mats are interpolated, if there is one. Or let me know if there isn't! Thank you!

(Note: answers can be for any OpenGL version.)

TL;DR: Yes, it is component-wise.

As you said, GLSL specifications have formulas for computing "datum associated with a fragment", like this one:

GLSL 330 spec : 3.5.1 Basic Line Segment Rasterization

The value of an associated datum f for the fragment, whether it be a varying shader output or the clip w coordinate, is found as

     (1 ― t)·fa/wa + t·fb/wb
f = ――――――――――――――――――――――――                                (3.6)
(1 ― t)/wa + t/wb
where fa and fb are the data associated with the starting and ending endpoints of the segment, respectively; wa and wb are the clip w coordinates of the starting and ending endpoints of the segments, respectively.

It may be not entirely clear if "datum" means an entire vector/matrix or separate components, but the point is that it doesn't matter, because multiplication and divison between a scalar and a vector/matrix are defined component-wise.

• Thank you! --- and +1 for the best use of html-tag formatting I have ever seen on SE :) – cxw Apr 10 '17 at 12:45
• So, "component-wise" means that each value is taken and interpolated independent of every other value? For example, between two matrices a and b, there will be one interpolation between a[0] and b[0], one interpolation between a[1] and b[1], between a[2] and b[2], etc? So the interpolation is the same between each component (each item in the arrays) as it would be for just two float varying values? – trusktr Jun 1 '17 at 2:39
• @trusktr Yes, exactly. – HolyBlackCat Jun 1 '17 at 10:51
• ..and presumably 't' is the fraction [0,1] of the way from a to b of that fragment. – Jose_X Dec 29 '18 at 15:46