opengl.vert 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Part of the Irrlicht Engine Shader example.
  2. // Simple GLSL vertex shader
  3. // Please note that these example shaders don't do anything really useful.
  4. // They only demonstrate that shaders can be used in Irrlicht.
  5. uniform mat4 mWorldViewProj;
  6. uniform mat4 mInvWorld;
  7. uniform mat4 mTransWorld;
  8. uniform vec3 mLightPos; // actually just camera-pos in this case
  9. uniform vec4 mLightColor;
  10. void main(void)
  11. {
  12. gl_Position = mWorldViewProj * gl_Vertex;
  13. // transform normal somehow (NOTE: for the real vertex normal you would use an inverse-transpose world matrix instead of mInvWorld)
  14. vec4 normal = vec4(gl_Normal, 0.0);
  15. normal = mInvWorld * normal;
  16. normal = normalize(normal);
  17. // (NOTE: not sure why transposed world is used instead of world?)
  18. vec4 worldpos = gl_Vertex * mTransWorld;
  19. vec4 lightVector = worldpos - vec4(mLightPos,1.0);
  20. lightVector = normalize(lightVector);
  21. float tmp2 = dot(-lightVector, normal);
  22. vec4 tmp = mLightColor * tmp2;
  23. gl_FrontColor = gl_BackColor = vec4(tmp.x, tmp.y, tmp.z, 0.0);
  24. gl_TexCoord[0] = gl_MultiTexCoord0;
  25. }