Vector组件中的s,t,p,q是什么意思?
What is the meaning of s,t,p,q in Vector components?
在WebGL reference card中,有关于Vector组件的文档。
虽然在我看来我也可以使用 {x, y, z, w},但我无法理解在从纹理读取时是否必须使用 {s, t, p, q} .
Use when accessing vectors that represent texture coordinates
{s, t, p, q} 字母的含义是什么?这只是可读代码的约定问题,还是我还缺少其他东西?
见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 ...
参见 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.
您还可以使用 v[0]
、v[1]
、v[2]
、v[3]
来访问向量的组件。
这意味着对于 vec4 v;
,v.stpq
与 v.xyzw
或 v.rgba
完全相同。
s
、t
命名来自 Plane (geometry),其中计划可以参数化地描述为 R = 形式的所有点的集合R0 + sV + tW。 (R和R0是点,V和W是向量,s和t是实数。
在WebGL reference card中,有关于Vector组件的文档。
虽然在我看来我也可以使用 {x, y, z, w},但我无法理解在从纹理读取时是否必须使用 {s, t, p, q} .
Use when accessing vectors that represent texture coordinates
{s, t, p, q} 字母的含义是什么?这只是可读代码的约定问题,还是我还缺少其他东西?
见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 ...
参见 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.
您还可以使用 v[0]
、v[1]
、v[2]
、v[3]
来访问向量的组件。
这意味着对于 vec4 v;
,v.stpq
与 v.xyzw
或 v.rgba
完全相同。
s
、t
命名来自 Plane (geometry),其中计划可以参数化地描述为 R = 形式的所有点的集合R0 + sV + tW。 (R和R0是点,V和W是向量,s和t是实数。