VertShader.vsh 903 B

12345678910111213141516171819202122232425262728
  1. attribute highp vec4 inVertex;
  2. attribute highp vec3 inNormal;
  3. attribute highp vec2 inTexCoord;
  4. attribute highp vec3 inTangent;
  5. uniform highp mat4 MVPMatrix; // model view projection transformation
  6. uniform highp vec3 LightPosModel; // Light position (point light) in model space
  7. varying lowp vec3 LightVec;
  8. varying mediump vec2 TexCoord;
  9. void main()
  10. {
  11. // Transform position
  12. gl_Position = MVPMatrix * inVertex;
  13. // Calculate light direction from light position in model space
  14. // You can skip this step for directional lights
  15. highp vec3 lightDirection = normalize(LightPosModel - vec3(inVertex));
  16. // transform light direction from model space to tangent space
  17. highp vec3 bitangent = cross(inNormal, inTangent);
  18. highp mat3 tangentSpaceXform = mat3(inTangent, inNormal, bitangent);
  19. LightVec = lightDirection * tangentSpaceXform;
  20. TexCoord = inTexCoord;
  21. }