Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===========================================================================
- //
- // Calculate light
- //
- // It is important to note that the light color is not desaturated
- // due to ZDoom's implementation weirdness. Everything that's added
- // on top of it, e.g. dynamic lights and glows are, though, because
- // the objects emitting these lights are also.
- //
- // This is making this a bit more complicated than it needs to
- // because we can't just desaturate the final fragment color.
- //
- //===========================================================================
- vec4 getLightColor(float fogdist, float fogfactor)
- {
- vec4 color = vColor;
- if (uLightLevel >= 0.0)
- {
- float newlightlevel = 1.0 - R_DoomLightingEquation(uLightLevel, gl_FragCoord.z);
- color.rgb *= newlightlevel;
- }
- else if (uFogEnabled > 0.0)
- {
- // brightening around the player for light mode 2
- if (fogdist < uLightDist)
- {
- color.rgb *= uLightFactor - (fogdist / uLightDist) * (uLightFactor - 1.0);
- }
- //
- // apply light diminishing through fog equation
- //
- color.rgb = mix(vec3(0.0, 0.0, 0.0), color.rgb, fogfactor);
- }
- //
- // handle glowing walls
- //
- if (uGlowTopColor.a > 0.0 && glowdist.x < uGlowTopColor.a)
- {
- color.rgb += desaturate(uGlowTopColor * (1.0 - glowdist.x / uGlowTopColor.a)).rgb;
- }
- if (uGlowBottomColor.a > 0.0 && glowdist.y < uGlowBottomColor.a)
- {
- color.rgb += desaturate(uGlowBottomColor * (1.0 - glowdist.y / uGlowBottomColor.a)).rgb;
- }
- color = min(color, 1.0);
- //
- // apply brightmaps (or other light manipulation by custom shaders.
- //
- color = ProcessLight(color);
- //
- // apply dynamic lights (except additive)
- //
- vec4 dynlight = uDynLightColor;
- if (uLightIndex >= 0)
- {
- ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1);
- if (lightRange.z > lightRange.x)
- {
- //
- // modulated lights
- //
- for(int i=lightRange.x; i<lightRange.y; i+=2)
- {
- vec4 lightpos = lights[i];
- vec4 lightcolor = lights[i+1];
- lightcolor.rgb *= max(lightpos.w - distance(pixelpos.xyz, lightpos.xyz),0.0) / lightpos.w;
- dynlight.rgb += lightcolor.rgb;
- }
- //
- // subtractive lights
- //
- for(int i=lightRange.y; i<lightRange.z; i+=2)
- {
- vec4 lightpos = lights[i];
- vec4 lightcolor = lights[i+1];
- lightcolor.rgb *= max(lightpos.w - distance(pixelpos.xyz, lightpos.xyz),0.0) / lightpos.w;
- dynlight.rgb -= lightcolor.rgb;
- }
- }
- }
- color.rgb = clamp(color.rgb + desaturate(dynlight).rgb, 0.0, 1.4);
- // prevent any unintentional messing around with the alpha.
- return vec4(color.rgb, vColor.a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement