mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-04 11:19:30 +01:00
Draw volumetric clouds, their shadows, a volumetric fog and catalogue stars from a new weather system in the GL 4.6 renderer
This commit is contained in:
@@ -1,30 +1,41 @@
|
||||
// fog between the camera and a fragment, see fog_volume.glsl and weather_common.glsl. a draw with a fog_density of 0 is not
|
||||
// fogged; one with another density than the regular one (the glare of lamps) gets the optical depth scaled by the ratio
|
||||
#include <fog_volume.glsl>
|
||||
|
||||
// rgb: light the fog adds, a: what it lets through
|
||||
vec4 fog_at_fragment()
|
||||
{
|
||||
if (fog_density <= 0.0)
|
||||
return vec4(0.0, 0.0, 0.0, 1.0);
|
||||
vec4 fog = fog_along_view(f_pos.xyz, gl_FragCoord.xy);
|
||||
float scale = fog_density / max(fog_light.w, 1e-12);
|
||||
if (abs(scale - 1.0) > 1e-3)
|
||||
{
|
||||
float transmittance = exp(log(max(fog.a, 1e-8)) * scale);
|
||||
fog.rgb *= (1.0 - transmittance) / max(1.0 - fog.a, 1e-4);
|
||||
fog.a = transmittance;
|
||||
}
|
||||
return fog;
|
||||
}
|
||||
|
||||
vec3 get_fog_color()
|
||||
{
|
||||
vec3 fog_color_v = fog_color;
|
||||
if (lights_count >= 1U && lights[0].type == LIGHT_DIR) {
|
||||
float sun_amount = max(dot(normalize(f_pos.xyz), normalize(-lights[0].dir)), 0.0);
|
||||
fog_color_v += lights[0].color * pow(sun_amount, 30.0);
|
||||
}
|
||||
return fog_color_v;
|
||||
vec4 fog = fog_at_fragment();
|
||||
return fog.rgb / max(1.0 - fog.a, 1e-4);
|
||||
}
|
||||
|
||||
float get_fog_amount()
|
||||
{
|
||||
float z = length(f_pos.xyz);
|
||||
// float fog_amount_v = 1.0 - z * fog_density; // linear
|
||||
// float fog_amount_v = exp( -fog_density * z ); // exp
|
||||
float fog_amount_v = exp2( -fog_density * fog_density * z * z * 1.442695 ); // exp2
|
||||
|
||||
fog_amount_v = 1.0 - clamp(fog_amount_v, 0.0, 1.0);
|
||||
return fog_amount_v;
|
||||
return 1.0 - fog_at_fragment().a;
|
||||
}
|
||||
|
||||
vec3 apply_fog(vec3 color)
|
||||
{
|
||||
return mix(color, get_fog_color(), get_fog_amount());
|
||||
vec4 fog = fog_at_fragment();
|
||||
return color * fog.a + fog.rgb;
|
||||
}
|
||||
|
||||
vec3 add_fog(vec3 color, float amount)
|
||||
{
|
||||
return color + get_fog_color() * get_fog_amount() * amount;
|
||||
return color + fog_at_fragment().rgb * amount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user