Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of s,t,p,q in Vector components?

In the WebGL reference card, there is the documentation about Vector components.

While it seems to me that i can use also {x, y, z, w}, I am not able to understand if it is mandatory to use {s, t, p, q} when reading from Textures.

Use when accessing vectors that represent texture coordinates

What is the meaning of the {s, t, p, q} letters? It is just only a matter of convention for readable code or is there something more that i am missing?

like image 877
deblocker Avatar asked Dec 25 '17 14:12

deblocker


1 Answers

See WebGL Specification Vesion 1.0:

4.3 Supported GLSL Constructs

A WebGL implementation must only accept shaders which conform to The OpenGL ES Shading Language, Version 1.00 ...

See the OpenGL ES Shading Language 1.00 Specification :

5.5 Vector Components

The names of the components of a vector or scalar are denoted by a single letter. As a notational convenience, several letters are associated with each component based on common usage of position, color or texture coordinate vectors. The individual components can be selected by following the variable name with period ( . ) and then the component name.

The component names supported are:

  • {x, y, z, w} Useful when accessing vectors that represent points or normals

  • {r, g, b, a} Useful when accessing vectors that represent colors

  • {s, t, p, q} Useful when accessing vectors that represent texture coordinates

The component names x, r, and s are, for example, synonyms for the same (first) component in a vector. Note that the third component of the texture coordinate set, r in OpenGL ES, has been renamed p so as to avoid the confusion with r (for red) in a color.

You can also use v[0], v[1], v[2], v[3] to access the components of a the vector.

This means for a vec4 v;, v.stpq is exactly the same as v.xyzw or v.rgba.

The s, t naming comes from the Plane (geometry), where a plan can be described parametrically as the set of all points of the form R = R0 + sV + tW. (R and R0 are points, V and W are vectors, s and t are real numbers.

like image 151
Rabbid76 Avatar answered Jan 01 '23 19:01

Rabbid76