Using only part of a variable variable

Let's say I have a variable variable between any two stages of the GLSL shader (for example, the vertex and fragment stage) declared as vec4:

in/out/varying vec4 texCoord;

What happens if I use only part of this variable (say through swizzling) in both shaders, i.e. I write only its part in the vertex shader and read only the same part in the fragment shader?

// vertex shader
texCoord.st = ...

// fragment shader
... = texture2D(..., texCoord.st);

Is it a guarantee (i.e. specification) to always give reasonable results? It seems reasonable that this is so, but I'm not too good at the intricacies of the language of GLSL lawyers and don "I don’t know if this variable is interpreted somehow by the" incomplete "compiler / linker, because it is not completely written down at the previous stage. I I'm sure that the values texCoord.pqwill be undefined in any case, but does it affect the reliability texCoord.sttoo or does the whole system as a whole work at a pure component level?

GLSL , , , "" , , ( , ). GLSL, , , gl_TexCoord[] GLSL 1.10.

+6
2

, , . , , 100% , , . OpenGL 4.5 Core Profile Specification OpenGL 4.50.

, GLSL 4.3.4

in. OpenGL . [...] .

4.3.6 :

out. OpenGL. [...] . . , ; .

5.8 "" ,

( ) , undefined.

.st , , , .

11.1.2.1 GL:

, , , , , . , .

" " , undefined, , undefined , . ( 14.5.1 14.6.1) , .

11.1.2.1 :

, , . , shader , MAX_VERTEX_OUTPUT_COMPONENTS , .

, , 4 a vec4 , .

+4

:

.

, :

  • ?

    . , swizzling, , swizzle , swizzle. , undefined. undefined .

  • undefined ?

    . - . .

, .

+2

Source: https://habr.com/ru/post/1016888/


All Articles