FastVertShader.vsh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /******************************************************************************
  2. * Vertex Shader (Fast method)
  3. *******************************************************************************
  4. This technique uses the dot product between the light direction and the normal
  5. to generate an x coordinate. The dot product between the half angle vector
  6. (vector half way between the viewer's eye and the light direction) and the
  7. normal to generate a y coordinate. These coordinates are used to lookup the
  8. intensity of light from the special image, which is accessible to the shader
  9. as a 2d texture. The intensity is then used to shade a fragment and hence
  10. create an anisotropic lighting effect.
  11. ******************************************************************************/
  12. attribute highp vec3 inVertex;
  13. attribute highp vec3 inNormal;
  14. uniform highp mat4 MVPMatrix;
  15. uniform highp vec3 msLightDir;
  16. uniform highp vec3 msEyePos;
  17. varying mediump vec2 TexCoord;
  18. void main()
  19. {
  20. // transform position
  21. gl_Position = MVPMatrix * vec4(inVertex, 1);
  22. // Calculate eye direction in model space
  23. highp vec3 msEyeDir = normalize(msEyePos - inVertex);
  24. // Calculate vector half way between the vertexToEye and light directions.
  25. // (division by 2 ignored as it is irrelevant after normalisation)
  26. highp vec3 halfAngle = normalize(msEyeDir + msLightDir);
  27. // Use dot product of light direction and normal to generate s coordinate.
  28. // We use GL_CLAMP_TO_EDGE as texture wrap mode to clamp to 0
  29. TexCoord.s = dot(msLightDir, inNormal);
  30. // Use dot product of half angle and normal to generate t coordinate.
  31. TexCoord.t = dot(halfAngle, inNormal);
  32. }