2022-06-06 20:40:38 +00:00
|
|
|
#if @skyBlending
|
2023-02-25 19:03:39 +00:00
|
|
|
#include "lib/core/fragment.h.glsl"
|
2022-07-09 20:21:48 +00:00
|
|
|
|
2022-06-06 20:40:38 +00:00
|
|
|
uniform float skyBlendingStart;
|
|
|
|
#endif
|
|
|
|
|
2023-02-25 19:03:39 +00:00
|
|
|
vec4 applyFogAtDist(vec4 color, float euclideanDist, float linearDist, float far)
|
2022-06-06 20:40:38 +00:00
|
|
|
{
|
|
|
|
#if @radialFog
|
|
|
|
float dist = euclideanDist;
|
|
|
|
#else
|
|
|
|
float dist = abs(linearDist);
|
|
|
|
#endif
|
|
|
|
#if @exponentialFog
|
|
|
|
float fogValue = 1.0 - exp(-2.0 * max(0.0, dist - gl_Fog.start/2.0) / (gl_Fog.end - gl_Fog.start/2.0));
|
|
|
|
#else
|
|
|
|
float fogValue = clamp((dist - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
|
|
|
|
#endif
|
2022-06-21 20:28:17 +00:00
|
|
|
#ifdef ADDITIVE_BLENDING
|
2022-07-04 17:31:03 +00:00
|
|
|
color.xyz *= 1.0 - fogValue;
|
2022-06-21 20:28:17 +00:00
|
|
|
#else
|
2022-06-06 20:40:38 +00:00
|
|
|
color.xyz = mix(color.xyz, gl_Fog.color.xyz, fogValue);
|
2022-06-21 20:28:17 +00:00
|
|
|
#endif
|
2022-06-06 20:40:38 +00:00
|
|
|
|
2022-07-09 20:21:48 +00:00
|
|
|
#if @skyBlending
|
2022-06-06 20:40:38 +00:00
|
|
|
float fadeValue = clamp((far - dist) / (far - skyBlendingStart), 0.0, 1.0);
|
2022-06-21 20:28:17 +00:00
|
|
|
fadeValue *= fadeValue;
|
|
|
|
#ifdef ADDITIVE_BLENDING
|
|
|
|
color.xyz *= fadeValue;
|
|
|
|
#else
|
2023-02-25 19:03:39 +00:00
|
|
|
color.xyz = mix(sampleSkyColor(gl_FragCoord.xy / screenRes), color.xyz, fadeValue);
|
2022-06-21 20:28:17 +00:00
|
|
|
#endif
|
2022-06-06 20:40:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2023-02-25 19:03:39 +00:00
|
|
|
vec4 applyFogAtPos(vec4 color, vec3 pos, float far)
|
2022-06-06 20:40:38 +00:00
|
|
|
{
|
2023-02-25 19:03:39 +00:00
|
|
|
return applyFogAtDist(color, length(pos), pos.z, far);
|
2022-06-06 20:40:38 +00:00
|
|
|
}
|