Unlit.glsl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #endif
  21. }
  22. void PS()
  23. {
  24. // Get material diffuse albedo
  25. #ifdef DIFFMAP
  26. vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
  27. #ifdef ALPHAMASK
  28. if (diffColor.a < 0.5)
  29. discard;
  30. #endif
  31. #else
  32. vec4 diffColor = cMatDiffColor;
  33. #endif
  34. #ifdef VERTEXCOLOR
  35. diffColor *= vColor;
  36. #endif
  37. // Get fog factor
  38. #ifdef HEIGHTFOG
  39. float fogFactor = GetHeightFogFactor(vWorldPos.w, vWorldPos.y);
  40. #else
  41. float fogFactor = GetFogFactor(vWorldPos.w);
  42. #endif
  43. #if defined(PREPASS)
  44. // Fill light pre-pass G-Buffer
  45. gl_FragData[0] = vec4(0.5, 0.5, 0.5, 1.0);
  46. gl_FragData[1] = vec4(EncodeDepth(vWorldPos.w), 0.0);
  47. #elif defined(DEFERRED)
  48. gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  49. gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.0);
  50. gl_FragData[2] = vec4(0.5, 0.5, 0.5, 1.0);
  51. gl_FragData[3] = vec4(EncodeDepth(vWorldPos.w), 0.0);
  52. #else
  53. gl_FragColor = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  54. #endif
  55. }