OpenGL中顶点着色器(vertex shader)和片元着色器(fragment shader)间的数据流

VS和FS之间色数据流 

VS的输入:针对顶点的属性、一致性变量(uniform)

VS的输出:针对顶点的数据

FS的输入:针对片元的属性、一致型变量(uniform)

FS的输出:gl_FragColor;gl_FragDepth...

 VS:对单个顶点的操作

FS:对单个片元的操作

数据流是单向的

VS/FS的输入与输出变量

a)内建的uniform变量(只读)

Variable NameTypeDescription
gl_ModelViewMatrixmat4Current modelView matrix
gl_ProjectionMatrixmat4Current projection matrix
gl_ModelViewProjectionMatrixmat4Product of the modelview and projection matrices
gl_TextureMatrix[n]mat4Texture matrix for texture unit n.The maximum dimension of the array is gl_MaxTureCoords.
gl_NormalMatrixmat3Inverse-transpose of the upper 3*3 of  the modelview matrix
gl_ProjectionMatrixInversemat4Inverse of the projection matrix

b)内建的顶点属性变量("in"类型,只读)

Variable NameTypeSpecifying FunctionDescription
gl_Vertexvec4glVertexVertex's world-spzce coordinate
gl_Colorvec4glColorPrimary color Value
gl_SecondaryColorvec4glSecondaryColorSecondary color value
gl_Normalvec3glNormalLighting normal
gl_MultiTexCoordnvec4glMultiTexCoord(n,....)Texture unit n's texture coordinates,with n=0,...7
gl_FogCoordfloatglFogCoordFog coordinate
gl_VertexIDint -Index value of current vertex
glInstanceIDint -Instance index of current rendering primitive

c)自己定义的”uniform"类型变量(只读)

d)自己定义的“in”类型变量(只读)

e)纹理数据

VS的输出变量

a)VS输出的特定变量(读/写)

Variable NameTypeDescription
gl_Positionvec4Transformed vertex position
gl_PointSizefloatPoint 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[]floatDistances from the vertex to each clipping plane.(This variable repalces gl_Clip Vertex from GLSL 1.20)

b)VS输出的内建顶点属性变量(加out限定符,读/写)

这些变量往往对应于FS中的一个in类型变量

Variable NameTypeDescription
gl_FrontColorvec4Primary color to be used for front-facing primitives
gl_BackColorvec4Primary color to be used for back-facing primitives
gl_FrontSecondaryColorvec4Secondary color to be used for front-facing primitives
gl_BackSecondaryColorvec4Secondary color to be used for back-facing primitives
gl_TextCoord[n]vec4nthTexture coorfinates values
gl_FogFragCoordvec4Fragment fog coordinate value

 可以传输给FS的数据

a)内建的uniform状态变量(只读)

变量典型描述
gl_FragCoordvec4(只读)片段的位置,包括z成分,它表示固定功能所计算的深度值
glFrontFacingbool(只读)指定了这个片段是否属于一个正面图元
gl_Colorvec4片段的主颜色
gl_SecondColorvec4片段的辅助颜色
gl_TexCoord[n]vec4片段的第n纹理坐标
gl_FogFragCoordfloat片段的雾坐标,要么指定为视觉空间中的图元的z坐标,或者插值坐标
gl_PointCoordvec2一个点纹理的片段位置在[0.0,1.0]的范围中,如果当前图元并不是点块纹理或点块纹理被禁用,这个值就是未定义的

b)内建的“in”类型变量

c)自己定义的“uniform”类型变量

d)自己定义的“uniform”类型变量

e)自己定义的“in”类型变量

d)纹理数据

VS的out变量与FS的in变量的对应

VS中的内建out变量FS中的内建in变量
gl_FrontColor/gl_BackColorgl_Color
gl_FrontSecondaryColor/gl_BackSecondaryColorgl_SecondColor
gl_TexCoor[n]gl_TexCoor[n]
gl_FogFragCoordgl_FogFragCoor
 gl_FragCoord
vs中的自定义out变量FS中的自定义in变量
比如:out vec4 pcolor;in vec4 pcolor;

 变量前的限定符

uniform:一致型变量

in:VS中为输入的顶点属性;FS中为片段属性,有一些与VS中的out变量对应。(只读)

out:VS中输出的顶点属性,与FS中的某个in变量对应。FS中为一些特定的输出。(读/写)

 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Estelle_Z

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值