在 WebGL 中,属性、统一变量和可变变量之间有什么区别? [英] In WebGL what are the differences between an attribute, a uniform, and a varying variable?

查看:24
本文介绍了在 WebGL 中,属性、统一变量和可变变量之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在比较这些不同的类型或这些东西是如何工作的时候,我能想到一个类比吗?

Is there an analogy that I can think of when comparing these different types, or how these things work?

另外,统一矩阵是什么意思?

Also, what does uniforming a matrix mean?

推荐答案

直接复制自http://www.lighthouse3d.com/tutorials/glsl-tutorial/data-types-and-variables/.实际网站有更详细的信息,值得一看.

Copied directly from http://www.lighthouse3d.com/tutorials/glsl-tutorial/data-types-and-variables/. The actual site has much more detailed information and would be worthwhile to check out.

变量限定符

限定符赋予变量特殊的含义.下列预选赛可用:

Qualifiers give a special meaning to the variable. The following qualifiers are available:

  • const – 声明是编译时常量.
  • attribute – 每个顶点可能会改变的全局变量,从 OpenGL 应用程序传递到顶点着色器.这个预选赛只能在顶点着色器中使用.对于着色器,这是一个只读变量.请参阅属性部分.
  • uniform – 从 OpenGL 传递的每个图元可能会改变的全局变量 [...]应用到着色器.此限定符可用于两个顶点和片段着色器.对于着色器,这是一个只读变量.见制服部分.
  • variing – 用于在顶点着色器和片段着色器之间插入数据.可用于在顶点着色器中写入,以及在片段着色器中只读.见变化部分.

打个比方,const和uniform就像C/C++中的全局变量,一个是常量,另一个是可以设置的.属性是一个伴随顶点的变量,如颜色或纹理坐标.可变变量可以由顶点着色器改变,但不能由片段着色器改变,因此本质上它们是在沿管道传递信息.

As for an analogy, const and uniform are like global variables in C/C++, one is constant and the other can be set. Attribute is a variable that accompanies a vertex, like color or texture coordinates. Varying variables can be altered by the vertex shader, but not by the fragment shader, so in essence they are passing information down the pipeline.

这篇关于在 WebGL 中,属性、统一变量和可变变量之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆