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

2019-02-25 02:30发布

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?

标签: glsl webgl
1条回答
做个烂人
2楼-- · 2019-02-25 03:25

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.


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.

查看更多
登录 后发表回答