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?
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 coordinatesThe component names
x
,r
, ands
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 renamedp
so as to avoid the confusion withr
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With