glsl - 向量分量中 s,t,p,q 的含义是什么?

标签 glsl shader webgl webgl2

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.stpqv.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/

相关文章:

c++ - 制作shader将vertexArray作为canvas而不是window

android - Android 上的 OpenGL 漫射照明

上下文丢失后 webglcontextrestored 事件未触发

three.js - 如何使用 WebRTC 流式传输 webGL Canvas ?

opengl - 现代 OpenGL 的正交投影问题

python - 如何将片段着色器图像更改保存到图像输出文件?

c++ - 无法在 OpenGL 中获取 GLSL 着色器

javascript - Chrome - 调试 WebGL 崩溃 ("Rats! WebGL hit a snag.")

OpenGL 4.4/ES 3.0 和缓存 channel 之间的顶点数据

具有新偏移量的three.js webgl自定义着色器共享纹理