cubeMapReflection.vert 837 B

12345678910111213141516171819202122232425262728
  1. uniform int StyleUVW ; // 0 = specular reflection, 1 = diffuse reflection, 2 = use model vertex coordinates for uvw.
  2. uniform vec3 CameraPos;
  3. uniform mat4 World;
  4. void main(void)
  5. {
  6. gl_Position = ftransform(); // same as gl_ModelViewProjectionMatrix * gl_Vertex;
  7. // compute the reflection vector, and assign it to texcoord 0
  8. if ( StyleUVW == 0 )
  9. {
  10. vec4 worldPos = World*gl_Vertex;
  11. vec3 viewNormal = normalize(worldPos.xyz - CameraPos); // view vector
  12. gl_TexCoord[0] = vec4( reflect( viewNormal, normalize(gl_Normal) ), 1.0 );
  13. }
  14. else if ( StyleUVW == 1 )
  15. {
  16. // just use the normal for the reflection vector
  17. gl_TexCoord[0] = vec4(normalize(gl_Normal), 1.0);
  18. }
  19. else if ( StyleUVW == 2 )
  20. {
  21. // use vertex-coordinates for texture coordinates
  22. gl_TexCoord[0] = normalize(gl_Vertex);
  23. }
  24. }