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

查看:92
本文介绍了在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?

推荐答案

直接从

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传递的每个原始变量可能更改的全局变量 应用于着色器.该限定符可以在两个顶点中使用 和片段着色器.对于着色器,这是一个只读变量. 请参见统一"部分.
  • varying –用于在顶点着色器和片段着色器之间插入数据.可用于在顶点着色器中编写,并且 在片段着色器中为只读.请参阅变体"部分.
  • 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 ++中的全局变量一样,一个是常量,另一个可以设置.属性是一个伴随顶点的变量,例如颜色或纹理坐标.可变变量可以由顶点着色器更改,但不能由片段着色器更改,因此从本质上讲,它们是沿管道传递信息.

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天全站免登陆