WebGL 着色器变量列表?

Tom*_*nto 2 javascript graphics shader webgl

例如:

var VertexShaderText = [

'attribute vec2 vertPosition;',

'void main()',
'{',
'  gl_Position = vec4(vertPosition, 0.0, 1.0);',
'}'
].join('\n');
Run Code Online (Sandbox Code Playgroud)

除了 gl_Position 之外,是否有一个在线列表列出了您可以使用的所有 WebGL 着色器变量?

gma*_*man 5

您可以在规范WebGL 参考卡中找到它

参考卡列出了所有这些

内置输入、输出和常数 [7]

着色器程序使用特殊变量与管道的固定功能部分进行通信。输出特殊变量可以在写入后读回。输入特殊变量是只读的。所有特殊变量都有全局作用域。

顶点着色器特殊变量 [7.1]

Outputs:
Variable                    Description                   Units or coordinate system
--------------------------------------------------------------------------------------
highp vec4    gl_Position;  transformed vertex position   clip coordinates
mediump float gl_PointSize; transformed point size        pixels
                            (point rasterization only)
Run Code Online (Sandbox Code Playgroud)

片段着色器特殊变量 [7.2]

片段着色器可以写入 gl_FragColor 或 gl_FragData[] 的一个或多个元素,但不能同时写入两者。gl_FragData 数组的大小由内置常量 gl_MaxDrawBuffers 给出。

Inputs:
Variable                     Description                  Units or coordinate system
-----------------------------------------------------------------------------------------------
mediump vec4 gl_FragCoord;   fragment position within     window coordinates 
                             frame buffer 
bool         gl_FrontFacing; fragment belongs to a        Boolean
                             front-facing primitive 
mediump vec2 gl_PointCoord;  fragment position within a   0.0 to 1.0
                             point (point rasterization   for each
                             only)                        component

Outputs:
Variable                     Description                  Units or coordinate system
-----------------------------------------------------------------------------------------------
mediump vec4 gl_FragColor;   fragment color               RGBA color
mediump vec4 gl_FragData[n]  fragment color for           RGBA color 
                             color attachment n
Run Code Online (Sandbox Code Playgroud)

具有最小值的内置常量 [7.4]

Built-in Constant                                  Minimum value
----------------------------------------------------------------
const mediump int gl_MaxVertexAttribs              8
const mediump int gl_MaxVertexUniformVectors       128
const mediump int gl_MaxVaryingVectors             8
const mediump int gl_MaxVertexTextureImageUnits    0
const mediump int gl_MaxCombinedTextureImageUnits  8
const mediump int gl_MaxTextureImageUnits          8
const mediump int gl_MaxFragmentUniformVectors     16
const mediump int gl_MaxDrawBuffers                1
Run Code Online (Sandbox Code Playgroud)

内置统一状态 [7.5]

指定窗口坐标中的深度范围。如果一个实现在片段语言中不支持 highp 精度,并且状态被列为 highp,那么该状态在片段语言中将仅作为 mediump 可用。

struct gl_DepthRangeParameters {
  highp float near; // n
  highp float far;  // f
  highp float diff; // f - n
};
uniform gl_DepthRangeParameters gl_DepthRange;
Run Code Online (Sandbox Code Playgroud)