#include "shaders/scene/lightmodel_software.glsl" #include "shaders/scene/material.glsl" //=========================================================================== // // 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(Material material) { // calculate fog factor float fogdist = 0.0; float fogfactor = 0.0; if (uFogEnabled != 0) { if (uFogEnabled == 1 || uFogEnabled == -1) { fogdist = max(16.0, pixelpos.w); } else { fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); } fogfactor = exp2 (uFogDensity * fogdist); } vec4 color = vColor; if (uLightLevel >= 0.0) { float newlightlevel = 1.0 - R_DoomLightingEquation(uLightLevel); color.rgb *= newlightlevel; } else if (uFogEnabled > 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); // these cannot be safely applied by the legacy format where the implementation cannot guarantee that the values are set. #if !defined LEGACY_USER_SHADER && !defined NO_LAYERS // // apply glow // color.rgb = mix(color.rgb, material.Glow.rgb, material.Glow.a); // // apply brightmaps // color.rgb = min(color.rgb + material.Bright.rgb, 1.0); #endif // // apply lightmaps // if (vLightmap.z >= 0.0) { color.rgb += texture(LightMap, vLightmap).rgb; } // // apply dynamic lights // vec4 frag = vec4(ProcessMaterialLight(material, color.rgb), material.Base.a * vColor.a); // // colored fog // if (uFogEnabled < 0) { frag = vec4(mix(uFogColor.rgb, frag.rgb, fogfactor), frag.a); } return frag; } // The color of the fragment if it is fully occluded by ambient lighting vec3 AmbientOcclusionColor() { float fogdist; float fogfactor; // // calculate fog factor // if (uFogEnabled == -1) { fogdist = max(16.0, pixelpos.w); } else { fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); } fogfactor = exp2 (uFogDensity * fogdist); return mix(uFogColor.rgb, vec3(0.0), fogfactor); }