VS和FS之间色数据流
VS的输入:针对顶点的属性、一致性变量(uniform)
VS的输出:针对顶点的数据
FS的输入:针对片元的属性、一致型变量(uniform)
FS的输出:gl_FragColor;gl_FragDepth...
VS:对单个顶点的操作
FS:对单个片元的操作
数据流是单向的
VS/FS的输入与输出变量
a)内建的uniform变量(只读)
Variable Name | Type | Description |
gl_ModelViewMatrix | mat4 | Current modelView matrix |
gl_ProjectionMatrix | mat4 | Current projection matrix |
gl_ModelViewProjectionMatrix | mat4 | Product of the modelview and projection matrices |
gl_TextureMatrix[n] | mat4 | Texture matrix for texture unit n.The maximum dimension of the array is gl_MaxTureCoords. |
gl_NormalMatrix | mat3 | Inverse-transpose of the upper 3*3 of the modelview matrix |
gl_ProjectionMatrixInverse | mat4 | Inverse of the projection matrix |
b)内建的顶点属性变量("in"类型,只读)
Variable Name | Type | Specifying Function | Description |
gl_Vertex | vec4 | glVertex | Vertex's world-spzce coordinate |
gl_Color | vec4 | glColor | Primary color Value |
gl_SecondaryColor | vec4 | glSecondaryColor | Secondary color value |
gl_Normal | vec3 | glNormal | Lighting normal |
gl_MultiTexCoordn | vec4 | glMultiTexCoord(n,....) | Texture unit n's texture coordinates,with n=0,...7 |
gl_FogCoord | float | glFogCoord | Fog coordinate |
gl_VertexID | int | - | Index value of current vertex |
glInstanceID | int | - | Instance index of current rendering primitive |
c)自己定义的”uniform"类型变量(只读)
d)自己定义的“in”类型变量(只读)
e)纹理数据
VS的输出变量
a)VS输出的特定变量(读/写)
Variable Name | Type | Description |
gl_Position | vec4 | Transformed vertex position |
gl_PointSize | float | Point size(in pixels)of output vertex.Tis value overrides the current OpenGL setting if glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) has been called |
gl_ClipDistance[] | float | Distances from the vertex to each clipping plane.(This variable repalces gl_Clip Vertex from GLSL 1.20) |
b)VS输出的内建顶点属性变量(加out限定符,读/写)
这些变量往往对应于FS中的一个in类型变量
Variable Name | Type | Description |
gl_FrontColor | vec4 | Primary color to be used for front-facing primitives |
gl_BackColor | vec4 | Primary color to be used for back-facing primitives |
gl_FrontSecondaryColor | vec4 | Secondary color to be used for front-facing primitives |
gl_BackSecondaryColor | vec4 | Secondary color to be used for back-facing primitives |
gl_TextCoord[n] | vec4 | nthTexture coorfinates values |
gl_FogFragCoord | vec4 | Fragment fog coordinate value |
可以传输给FS的数据
a)内建的uniform状态变量(只读)
变量 | 典型 | 描述 |
gl_FragCoord | vec4 | (只读)片段的位置,包括z成分,它表示固定功能所计算的深度值 |
glFrontFacing | bool | (只读)指定了这个片段是否属于一个正面图元 |
gl_Color | vec4 | 片段的主颜色 |
gl_SecondColor | vec4 | 片段的辅助颜色 |
gl_TexCoord[n] | vec4 | 片段的第n纹理坐标 |
gl_FogFragCoord | float | 片段的雾坐标,要么指定为视觉空间中的图元的z坐标,或者插值坐标 |
gl_PointCoord | vec2 | 一个点纹理的片段位置在[0.0,1.0]的范围中,如果当前图元并不是点块纹理或点块纹理被禁用,这个值就是未定义的 |
b)内建的“in”类型变量
c)自己定义的“uniform”类型变量
d)自己定义的“uniform”类型变量
e)自己定义的“in”类型变量
d)纹理数据
VS的out变量与FS的in变量的对应
VS中的内建out变量 | FS中的内建in变量 |
gl_FrontColor/gl_BackColor | gl_Color |
gl_FrontSecondaryColor/gl_BackSecondaryColor | gl_SecondColor |
gl_TexCoor[n] | gl_TexCoor[n] |
gl_FogFragCoord | gl_FogFragCoor |
gl_FragCoord |
vs中的自定义out变量 | FS中的自定义in变量 |
比如:out vec4 pcolor; | in vec4 pcolor; |
变量前的限定符
uniform:一致型变量
in:VS中为输入的顶点属性;FS中为片段属性,有一些与VS中的out变量对应。(只读)
out:VS中输出的顶点属性,与FS中的某个in变量对应。FS中为一些特定的输出。(读/写)