Advertisement
jewalky

Untitled

Mar 2nd, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. //===========================================================================
  2. //
  3. // Calculate light
  4. //
  5. // It is important to note that the light color is not desaturated
  6. // due to ZDoom's implementation weirdness. Everything that's added
  7. // on top of it, e.g. dynamic lights and glows are, though, because
  8. // the objects emitting these lights are also.
  9. //
  10. // This is making this a bit more complicated than it needs to
  11. // because we can't just desaturate the final fragment color.
  12. //
  13. //===========================================================================
  14.  
  15. vec4 getLightColor(float fogdist, float fogfactor)
  16. {
  17. vec4 color = vColor;
  18.  
  19. if (uLightLevel >= 0.0)
  20. {
  21. float newlightlevel = 1.0 - R_DoomLightingEquation(uLightLevel, gl_FragCoord.z);
  22. color.rgb *= newlightlevel;
  23. }
  24. else if (uFogEnabled > 0.0)
  25. {
  26. // brightening around the player for light mode 2
  27. if (fogdist < uLightDist)
  28. {
  29. color.rgb *= uLightFactor - (fogdist / uLightDist) * (uLightFactor - 1.0);
  30. }
  31.  
  32. //
  33. // apply light diminishing through fog equation
  34. //
  35. color.rgb = mix(vec3(0.0, 0.0, 0.0), color.rgb, fogfactor);
  36. }
  37.  
  38. //
  39. // handle glowing walls
  40. //
  41. if (uGlowTopColor.a > 0.0 && glowdist.x < uGlowTopColor.a)
  42. {
  43. color.rgb += desaturate(uGlowTopColor * (1.0 - glowdist.x / uGlowTopColor.a)).rgb;
  44. }
  45. if (uGlowBottomColor.a > 0.0 && glowdist.y < uGlowBottomColor.a)
  46. {
  47. color.rgb += desaturate(uGlowBottomColor * (1.0 - glowdist.y / uGlowBottomColor.a)).rgb;
  48. }
  49. color = min(color, 1.0);
  50.  
  51. //
  52. // apply brightmaps (or other light manipulation by custom shaders.
  53. //
  54. color = ProcessLight(color);
  55.  
  56. //
  57. // apply dynamic lights (except additive)
  58. //
  59.  
  60. vec4 dynlight = uDynLightColor;
  61.  
  62. if (uLightIndex >= 0)
  63. {
  64. ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1);
  65. if (lightRange.z > lightRange.x)
  66. {
  67. //
  68. // modulated lights
  69. //
  70. for(int i=lightRange.x; i<lightRange.y; i+=2)
  71. {
  72. vec4 lightpos = lights[i];
  73. vec4 lightcolor = lights[i+1];
  74.  
  75. lightcolor.rgb *= max(lightpos.w - distance(pixelpos.xyz, lightpos.xyz),0.0) / lightpos.w;
  76. dynlight.rgb += lightcolor.rgb;
  77. }
  78. //
  79. // subtractive lights
  80. //
  81. for(int i=lightRange.y; i<lightRange.z; i+=2)
  82. {
  83. vec4 lightpos = lights[i];
  84. vec4 lightcolor = lights[i+1];
  85.  
  86. lightcolor.rgb *= max(lightpos.w - distance(pixelpos.xyz, lightpos.xyz),0.0) / lightpos.w;
  87. dynlight.rgb -= lightcolor.rgb;
  88. }
  89. }
  90. }
  91. color.rgb = clamp(color.rgb + desaturate(dynlight).rgb, 0.0, 1.4);
  92.  
  93. // prevent any unintentional messing around with the alpha.
  94. return vec4(color.rgb, vColor.a);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement