DiffuseVertShader.vsh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. attribute highp vec3 inVertex;
  2. attribute mediump vec3 inNormal;
  3. attribute mediump vec2 inTexCoord;
  4. uniform highp mat4 MVPMatrix;
  5. uniform highp mat3 Model;
  6. // Precalculated constants used for lighting
  7. uniform mediump vec3 LightDir1;
  8. uniform mediump vec3 LightDir2;
  9. uniform mediump vec3 LightDir3;
  10. uniform mediump vec3 LightDir4;
  11. uniform mediump vec4 Ambient;
  12. // varyings
  13. varying lowp vec4 LightColour;
  14. varying mediump vec2 TexCoord;
  15. void main()
  16. {
  17. highp vec4 r1;
  18. highp vec3 norm, r2, r3;
  19. // Transform position
  20. gl_Position = MVPMatrix * vec4(inVertex, 1.0);
  21. // Transform the Normal
  22. norm = normalize(Model * inNormal);
  23. // compute lighting
  24. r1.x = max(0.0, dot(norm, LightDir1)); // White Light
  25. r1.y = max(0.0, dot(norm, LightDir2)); // Blue Light
  26. r1.z = max(0.0, dot(norm, LightDir3)); // Green Light
  27. r1.w = max(0.0, dot(norm, LightDir4)); // Red Light
  28. LightColour.r = (r1.x + r1.w) + Ambient.r; // White Light (BGRA)
  29. LightColour.g = (r1.x + r1.z) + Ambient.g; // Red Light (BGRA)
  30. LightColour.b = (r1.x + r1.y) + Ambient.b; // Green Light (BGRA)
  31. LightColour.a = r1.x + Ambient.a; // Blue Light (BGRA)
  32. // Pass through texcoords
  33. TexCoord = inTexCoord;
  34. }