Unlit.glsl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "Uniforms.glsl"
  2. #include "Samplers.glsl"
  3. #include "Transform.glsl"
  4. #include "ScreenPos.glsl"
  5. #include "Fog.glsl"
  6. varying vec2 vTexCoord;
  7. varying vec4 vWorldPos;
  8. #ifdef VERTEXCOLOR
  9. varying vec4 vColor;
  10. #endif
  11. void VS()
  12. {
  13. mat4 modelMatrix = iModelMatrix;
  14. vec3 worldPos = GetWorldPos(modelMatrix);
  15. gl_Position = GetClipPos(worldPos);
  16. vTexCoord = GetTexCoord(iTexCoord);
  17. vWorldPos = vec4(worldPos, GetDepth(gl_Position));
  18. #ifdef VERTEXCOLOR
  19. vColor = iColor;
  20. //#ifdef TRAIL
  21. // vColor = vec4(normalize(cCameraPos), 1.0);
  22. //#endif
  23. #endif
  24. }
  25. void PS()
  26. {
  27. // Get material diffuse albedo
  28. #ifdef DIFFMAP
  29. vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
  30. #ifdef ALPHAMASK
  31. if (diffColor.a < 0.5)
  32. discard;
  33. #endif
  34. #else
  35. vec4 diffColor = cMatDiffColor;
  36. #endif
  37. #ifdef VERTEXCOLOR
  38. diffColor *= vColor;
  39. #endif
  40. // Get fog factor
  41. #ifdef HEIGHTFOG
  42. float fogFactor = GetHeightFogFactor(vWorldPos.w, vWorldPos.y);
  43. #else
  44. float fogFactor = GetFogFactor(vWorldPos.w);
  45. #endif
  46. #if defined(PREPASS)
  47. // Fill light pre-pass G-Buffer
  48. gl_FragData[0] = vec4(0.5, 0.5, 0.5, 1.0);
  49. gl_FragData[1] = vec4(EncodeDepth(vWorldPos.w), 0.0);
  50. #elif defined(DEFERRED)
  51. gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  52. gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.0);
  53. gl_FragData[2] = vec4(0.5, 0.5, 0.5, 1.0);
  54. gl_FragData[3] = vec4(EncodeDepth(vWorldPos.w), 0.0);
  55. #else
  56. gl_FragColor = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  57. #endif
  58. }