ModelFShader.fsh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #define ENABLE_TEXTURE
  2. #ifdef ENABLE_TEXTURE
  3. uniform sampler2D ModelTexture;
  4. #endif
  5. #ifdef ENABLE_FOG_DEPTH
  6. uniform lowp vec3 FogColour;
  7. uniform mediump float RcpMaxFogDepth;
  8. #endif
  9. #ifdef ENABLE_LIGHTING
  10. varying lowp float LightIntensity;
  11. #endif
  12. #ifdef ENABLE_TEXTURE
  13. varying mediump vec2 TexCoord;
  14. #endif
  15. #ifdef ENABLE_FOG_DEPTH
  16. varying mediump float VertexDepth;
  17. #endif
  18. void main()
  19. {
  20. #ifdef ONLY_ALPHA
  21. gl_FragColor = vec4(vec3(0.5),0.0);
  22. #else
  23. #ifdef ENABLE_TEXTURE
  24. #ifdef ENABLE_FOG_DEPTH
  25. // Mix the object's colour with the fogging colour based on fragment's depth
  26. lowp vec3 vFragColour = texture2D(ModelTexture, TexCoord).rgb;
  27. // Perform depth test and clamp the values
  28. lowp float fFogBlend = clamp(VertexDepth * RcpMaxFogDepth, 0.0, 1.0);
  29. #ifdef ENABLE_LIGHTING
  30. vFragColour.rgb = mix(vFragColour.rgb * LightIntensity, FogColour.rgb, fFogBlend);
  31. #else
  32. vFragColour.rgb = mix(vFragColour.rgb, FogColour.rgb, fFogBlend);
  33. #endif
  34. gl_FragColor = vec4(vFragColour,1.0);
  35. #else
  36. #ifdef ENABLE_LIGHTING
  37. gl_FragColor = vec4(texture2D(ModelTexture, TexCoord).rgb * LightIntensity, 1.0);
  38. #else
  39. gl_FragColor = vec4(texture2D(ModelTexture, TexCoord).rgb, 1.0);
  40. #endif
  41. #endif
  42. #else
  43. // Solid colour is used instead of texture colour
  44. #ifdef ENABLE_LIGHTING
  45. gl_FragColor = vec4(vec3(0.3,0.3,0.3)* LightIntensity, 1.0);
  46. #else
  47. gl_FragColor = vec4(vec3(0.3,0.3,0.3), 1.0);
  48. #endif
  49. #endif
  50. #endif
  51. }