Material.frag 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "Uniforms.frag"
  2. #include "Samplers.frag"
  3. #include "Lighting.frag"
  4. #include "Fog.frag"
  5. varying vec2 vTexCoord;
  6. #ifdef VERTEXCOLOR
  7. varying vec4 vColor;
  8. #endif
  9. varying vec4 vVertexLighting;
  10. varying vec4 vScreenPos;
  11. void main()
  12. {
  13. #ifdef DIFFMAP
  14. vec4 diffInput = texture2D(sDiffMap, vTexCoord);
  15. #ifdef ALPHAMASK
  16. if (diffInput.a < 0.5)
  17. discard;
  18. #endif
  19. vec3 diffColor = cMatDiffColor.rgb * diffInput.rgb;
  20. #else
  21. vec3 diffColor = cMatDiffColor.rgb;
  22. #endif
  23. #ifdef VERTEXCOLOR
  24. diffColor *= vColor.rgb;
  25. #endif
  26. #ifdef SPECMAP
  27. vec3 specColor = cMatSpecColor.rgb * texture2D(sSpecMap, vTexCoord).g;
  28. #else
  29. vec3 specColor = cMatSpecColor.rgb;
  30. #endif
  31. // Lights are accumulated at half intensity. Bring back to full intensity now
  32. vec4 lightInput = 2.0 * texture2DProj(sLightBuffer, vScreenPos);
  33. vec3 lightSpecColor = lightInput.a * lightInput.rgb / max(GetIntensity(lightInput.rgb), 0.001);
  34. vec3 finalColor = (vVertexLighting.rgb + lightInput.rgb) * diffColor + lightSpecColor * specColor;
  35. gl_FragColor = vec4(GetFog(finalColor, vVertexLighting.a), 1.0);
  36. }