在 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是实数。
关于glsl - 向量分量中 s,t,p,q 的含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47969475/