注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

hhfighting的博客

以责人之心责己,以恕己之心恕人

 
 
 

日志

 
 
 
 

Opengl Vertex Shader  

2012-10-31 00:30:11|  分类: 3D reconstructio |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

顶点处理器用于进行顶点变换、法向量变换与归一化、纹理坐标生成与变换、光照计算等操作。

1   内置特殊变量gl_Position = ftransform(); 

自己写顶点着色器的时候,gl_Position 是不可少的。gl_Position contains the final transformed position of the vertex that should  be drawn.
This code means running my vertex through the standard fixed function transform logic. The specific function is following:

attribute vec3 position;
uniform projectionMatrix;
uniform modelviewMatrix;

main() {
// Other logic here, setting up varyings, etc.
gl_Position = projectionMatrix * modelviewMatrix * vec4(position, 1.0);
//gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
}

2 Attributes
  • vec4 gl_Vertex;   顶点坐标(in world space)
  • vec4 gl_Position;   顶点坐标(in eye space)

上述两个定点坐标的变换,见1

  • vec3 gl_Normal;  顶点法向量
  • vec4 gl_Color;   顶点主颜色 note that gl_color read in by the vertex shader.

为该变量赋值,会出现警告:assignment to attribute gl_Color

  • vec4 gl_FrontColor;  正面顶点主颜色
  • vec4 gl_BackColor;   背面顶点主颜色
  • vec4 gl_SecondaryColor;  顶点从颜色
  • vec4 gl_FrontSecondaryColor;  正面顶点从主颜色
  • vec4 gl_BackSecondaryColor;   背面顶点从颜色
  • vec4 gl_MultiTexCoord0;  顶点纹理坐标,对应纹理单元0
  • vec4 gl_MultiTexCoord1;
  • vec4 gl_MultiTexCoord2;
  • vec4 gl_MultiTexCoord3;
  • vec4 gl_MultiTexCoord4;
  • vec4 gl_MultiTexCoord5;
  • vec4 gl_MultiTexCoord6;
  • vec4 gl_MultiTexCoord7;
  • float gl_FogCoord;    顶点雾化坐标

3 some related matrix (uniform)
  • mat4 gl_ModelViewMatrix --------computed when glMatrixMode is GL_MODELVIEW, easily replaced by simply providing a view matrix in your code.  ModelView transform is to convert from object space to eye space.
  • mat4 gl_ProjectionMatrix --------computed when glMatrixMode is GL_PROJECTION, and once again you're almost certainly already using a replacement for this.
  • mat4 gl_ModelViewProjectionMatrix--------gl_ModelViewProjectionMatrix = gl_ProjectionMatrix * gl_ModelViewMatrix.
  • mat4 gl_TextureMatrix[texture unit]

If use opengl fixed function pipeline to generate texture mapping, we can initialize this matrix by the following code:

glActiveTextureARB( GL_TEXTURE0_ARB ); glTexGeni(GL_S, GL_EYE_PLANE, &TexGenMatrix[0]); glTexGeni(GL_T, GL_EYE_PLANE, &TexGenMatrix[4]); glTexGeni(GL_R, GL_EYE_PLANE, &TexGenMatrix[8]); glTexGeni(GL_Q, GL_EYE_PLANE, &TexGenMatrix[12]);


  • mat4 gl_NormalMatrix-----calculate lighting of any sort, is the inverse transpose of the upper 3*3 matrix of the modelView matrix.
related inverse matrix(modelview matrix--->inverse--->transpose). You use it multiply the normals when the object is rotated so that the object is lit properly.
  • mat4 gl_ModelViewMatrixInverse
  • mat4 gl_ProjectionMatrixInverse
  • mat4 gl_ModelViewProjectionMatrixInverse
  • mat4 gl_TextureMatrixInverse

4 some function
(1) normalize
normalize the normal---Returns a vector in the same direction as the original vector but with a length of 1.
Note that if the vertex normals were not normalized, not only the length would not be unit, but also the direction would be wrong in the general case. Hence, Even if a vector isn't used in vertex shader, but we use it in fragment shader, we must also normalize it on the vertex shader.
(2) clamp
(3) mix
(4) ftransform()
Returns the transformed input vertex such that it matches the output of the fixed-function vertex pipeline.
5 variable type:
(1) varying:
The value of varying variables are able to be passed on to the second kind of shader (fragment shader).
(2) uniform:
从应用程序传给顶点着色器的参数。
  评论这张
 
阅读(476)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017