opengl.vert 636 B

12345678910111213141516171819202122232425262728
  1. uniform mat4 mWorldViewProj;
  2. uniform mat4 mInvWorld;
  3. uniform mat4 mTransWorld;
  4. uniform vec3 mLightPos;
  5. uniform vec4 mLightColor;
  6. void main(void)
  7. {
  8. gl_Position = mWorldViewProj * gl_Vertex;
  9. vec4 normal = vec4(gl_Normal, 0.0);
  10. normal = mInvWorld * normal;
  11. normal = normalize(normal);
  12. vec4 worldpos = gl_Vertex * mTransWorld;
  13. vec4 lightVector = worldpos - vec4(mLightPos,1.0);
  14. lightVector = normalize(lightVector);
  15. float tmp2 = dot(-lightVector, normal);
  16. vec4 tmp = mLightColor * tmp2;
  17. gl_FrontColor = gl_BackColor = vec4(tmp.x, tmp.y, tmp.z, 0.0);
  18. gl_TexCoord[0] = gl_MultiTexCoord0;
  19. }