Deferred.frag 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "Uniforms.frag"
  2. #include "Samplers.frag"
  3. #include "Fog.frag"
  4. varying vec2 vTexCoord;
  5. varying vec4 vVertexLighting;
  6. varying vec3 vNormal;
  7. #ifdef NORMALMAP
  8. varying vec3 vTangent;
  9. varying vec3 vBitangent;
  10. #endif
  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 NORMALMAP
  27. mat3 tbn = mat3(vTangent, vBitangent, vNormal);
  28. vec3 normal = tbn * DecodeNormal(texture2D(sNormalMap, vTexCoord));
  29. #else
  30. vec3 normal = vNormal;
  31. #endif
  32. #ifdef SPECMAP
  33. float specIntensity = cMatSpecColor.g * texture2D(sSpecMap, vTexCoord).g;
  34. #else
  35. float specIntensity = cMatSpecColor.g;
  36. #endif
  37. float specPower = cMatSpecColor.a / 255.0;
  38. gl_FragData[0] = vec4(GetFog(vVertexLighting.rgb * diffColor, vVertexLighting.a), 1.0);
  39. gl_FragData[1] = GetFogFactor(vVertexLighting.a) * vec4(diffColor, specIntensity);
  40. gl_FragData[2] = vec4(normal * 0.5 + 0.5, specPower);
  41. #ifndef HWDEPTH
  42. gl_FragData[3] = vec4(EncodeDepth(vVertexLighting.a), 0.0);
  43. #endif
  44. }