# 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 and b, one interpolation between a and b, between a and b, 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
{"ft_lang_label":"__label__en","ft_lang_prob":0.8707829,"math_prob":0.9145244,"size":1298,"snap":"2020-24-2020-29","text_gpt3_token_len":291,"char_repetition_ratio":0.12905718,"word_repetition_ratio":0.0,"special_character_ratio":0.2211094,"punctuation_ratio":0.14919356,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96940756,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-05-29T02:45:41Z\",\"WARC-Record-ID\":\"<urn:uuid:a0c17af5-426f-42e3-929e-7c04adeb4028>\",\"Content-Length\":\"146953\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f5e47075-a641-4e2a-a074-d5e2a1d943cc>\",\"WARC-Concurrent-To\":\"<urn:uuid:f50cef67-6301-40a5-a2c0-c45ef826e13b>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://gamedev.stackexchange.com/questions/139720/glsl-varying-interpolation-component-wise-reference-in-the-spec/139723\",\"WARC-Payload-Digest\":\"sha1:HZXJDOYZX4CB4PTXEHFJQS4RPHVWYP3G\",\"WARC-Block-Digest\":\"sha1:NLPUKIMDXN7WYV3Z5VB2WYL5K3NUW4AE\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-24/CC-MAIN-2020-24_segments_1590347401260.16_warc_CC-MAIN-20200529023731-20200529053731-00290.warc.gz\"}"}