VertShader.vsh 756 B

123456789101112131415161718192021222324252627
  1. attribute highp vec4 inVertex;
  2. attribute highp vec3 inNormal;
  3. attribute highp vec2 inTexCoord;
  4. uniform highp mat4 MVPMatrix;
  5. uniform highp vec3 LightDirection;
  6. uniform highp vec3 EyePosition;
  7. varying mediump float CosViewAngle;
  8. varying mediump float LightIntensity;
  9. varying mediump vec2 TexCoord;
  10. void main()
  11. {
  12. gl_Position = MVPMatrix * inVertex;
  13. highp vec3 eyeDirection = normalize(EyePosition - inVertex.xyz);
  14. // Simple diffuse lighting
  15. LightIntensity = max(dot(LightDirection, inNormal), 0.0);
  16. // Cosine of the angle between surface normal and eye direction
  17. // We clamp at 0.1 to avoid ugly aliasing at near 90° angles
  18. CosViewAngle = max(dot(eyeDirection, inNormal), 0.1);
  19. TexCoord = inTexCoord;
  20. }