VertShader.vsh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. attribute highp vec3 inVertex;
  2. attribute mediump vec3 inNormal;
  3. attribute mediump vec2 inTexCoord;
  4. uniform highp mat4 MVPMatrix;
  5. uniform highp mat4 ShadowProj;
  6. uniform mediump vec3 LightDirModel;
  7. uniform mediump vec3 EyePosModel;
  8. uniform mediump mat3 ModelWorld;
  9. varying mediump vec2 TexCoord;
  10. varying mediump vec3 ShadowCoord;
  11. varying mediump vec2 ReflectCoord;
  12. varying lowp float LightIntensity;
  13. void main()
  14. {
  15. // Transform position
  16. gl_Position = MVPMatrix * vec4(inVertex, 1.0);
  17. // Simple diffuse lighting
  18. LightIntensity = max(dot(inNormal, LightDirModel), 0.0);
  19. // Calculate eye direction in model space
  20. mediump vec3 eyeDir = normalize(inVertex - EyePosModel);
  21. // reflect eye direction over normal and transform to world space
  22. ReflectCoord = vec2(ModelWorld * reflect(eyeDir, inNormal)) * 0.5 + 0.5;
  23. ShadowCoord = (ShadowProj * vec4(inVertex, 1.0)).xyw;
  24. ShadowCoord.xy += ShadowCoord.z;
  25. ShadowCoord.z *= 2.0;
  26. // Pass through texcoords
  27. TexCoord = inTexCoord;
  28. }