在比较这些不同类型时,我能想到一个类比吗?或者这些东西是如何工作的?
此外,统一矩阵是什么意思?
最佳答案
直接复制自http://www.lighthouse3d.com/tutorials/glsl-tutorial/data-types-and-variables/ 。实际网站有更详细的信息,值得查看。
Variable Qualifiers
Qualifiers give a special meaning to the variable. The following qualifiers are available:
- const – The declaration is of a compile time constant.
- attribute – Global variables that may change per vertex, that are passed from the OpenGL application to vertex shaders. This qualifier can only be used in vertex shaders. For the shader this is a read-only variable. See Attribute section.
- uniform – Global variables that may change per primitive [...], that are passed from the OpenGL application to the shaders. This qualifier can be used in both vertex and fragment shaders. For the shaders this is a read-only variable. See Uniform section.
- varying – used for interpolated data between a vertex shader and a fragment shader. Available for writing in the vertex shader, and read-only in a fragment shader. See Varying section.
打个比方,const和uniform就像C/C++中的全局变量,一个是常量,一个是可以设置的。属性是伴随顶点的变量,如颜色或纹理坐标。不同的变量可以由顶点着色器更改,但不能由片段着色器更改,因此本质上它们是在管道中传递信息。
关于variables - 在 WebGL 中,属性、统一变量和变化变量之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17537879/