FragShader.fsh 949 B

123456789101112131415161718192021222324252627282930
  1. uniform sampler2D sReflectTex;
  2. uniform sampler2D sNormalMap;
  3. uniform bool bHighDetail;
  4. varying mediump vec3 EyeDirection;
  5. varying mediump vec2 TexCoord;
  6. void main()
  7. {
  8. if (bHighDetail)
  9. {
  10. // Get the normal direction per pixel from the normal map
  11. // The tNormal vector is defined in surface local coordinates (tangent space).
  12. mediump vec3 normal = texture2D(sNormalMap, TexCoord).rgb * 2.0 - 1.0;
  13. // reflect(): For the incident vector I and surface orientation N, returns the reflection direction:
  14. // I - 2 * dot(N, I) * N, N must already be normalized in order to achieve the desired result.
  15. mediump vec3 reflectDir = reflect(normal, EyeDirection);
  16. mediump vec2 reflectCoord = (reflectDir.xy) * 0.5 + 0.5;
  17. // Look-up in the 2D texture using the normal map disturbance
  18. gl_FragColor = texture2D(sReflectTex, reflectCoord);
  19. }
  20. else
  21. {
  22. gl_FragColor = texture2D(sReflectTex, TexCoord);
  23. }
  24. }