18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 20:54:59 +01:00

Clouds and fog tweaks

This commit is contained in:
2026-11-17 01:02:52 +01:00
parent 9071d3f4d3
commit 91c2d3aba9
10 changed files with 380 additions and 63 deletions

View File

@@ -55,6 +55,9 @@ const int CLOUD_SCATTER_OCTAVES = 6;
// light falls off fastest (about a 30th of the reach at 4 steps) and the steps get close to even when there are many of them
const float CLOUD_LIGHT_GROWTH = 24.0;
// the phase of the view for each order of the scattering (cloud_sunlight): the same for every sample of a ray, worked out once
float cloud_scatter_phase[CLOUD_SCATTER_OCTAVES];
float henyey_greenstein(float cosangle, float g)
{
// times 4 pi: 1 for an even scattering
@@ -77,8 +80,12 @@ vec3 cloud_sky_light(float up)
}
// light of the sun reaching a point inside a layer through the cloud towards it, with the light scattered many times
// (octaves after Wrenninge), and the phase of the view
float cloud_sunlight(int index, vec3 position, float cosangle, int steps, float powder, bool detail)
// (octaves after Wrenninge), and the phase of the view (cloud_scatter_phase). Offset: where in its step each sample is taken
// (0-1), another place for every sample of the view and every frame. taken always in the middle, a far sample (the last step is
// some 40% of the reach) came into the cloud at the same place for all the pixels around, and the shaded sides of the clouds
// were cut into bands of grey along it; moved about, the bands turn into a noise the samples of the ray and the blending over
// frames (clouds_temporal.comp) smooth out
float cloud_sunlight(int index, vec3 position, int steps, float powder, bool detail, float offset)
{
vec3 sun = weather_sun_direction.xyz;
cloud_layer_s layer = cloud_layers[index];
@@ -92,7 +99,7 @@ float cloud_sunlight(int index, vec3 position, float cosangle, int steps, float
float step = reach * (growth - 1.0) / (pow(growth, float(steps)) - 1.0);
for (int s = 0; s < steps; s++)
{
vec3 point = position + sun * (travelled + 0.5 * step);
vec3 point = position + sun * (travelled + offset * step);
travelled += step;
// the nearest steps with the detail noise: the small billows shade one another, lit on top and grey beneath
depth += cloud_layer_density(index, point, cloud_height(point), detail && (s < CLOUD_LIGHT_DETAIL_STEPS)) * step;
@@ -101,26 +108,25 @@ float cloud_sunlight(int index, vec3 position, float cosangle, int steps, float
float light = 0.0;
float amount = 1.0;
float fade = 1.0;
float spread = 1.0;
for (int octave = 0; octave < CLOUD_SCATTER_OCTAVES; octave++)
{
light += amount * exp(-depth * fade) * cloud_phase(cosangle, spread) * (octave == 0 ? powder : 1.0);
light += amount * exp(-depth * fade) * cloud_scatter_phase[octave] * (octave == 0 ? powder : 1.0);
amount *= 0.5;
fade *= 0.5;
spread *= 0.5;
}
return light;
}
// optical depth of the cloud over a point up to Reach above it, from Samples of the coarse density: under a lump and deep in a
// thick cloud the sky light is held back, at the tops and the thin edges it is not, so the shaded sides take the form of the cloud
float cloud_sky_depth(int index, vec3 position, float height, float reach, int samples)
// thick cloud the sky light is held back, at the tops and the thin edges it is not, so the shaded sides take the form of the cloud.
// Offset: where in its part of the reach each sample is taken (0-1), as in cloud_sunlight()
float cloud_sky_depth(int index, vec3 position, float height, float reach, int samples, float offset)
{
float depth = 0.0;
for (int s = 0; s < samples; s++)
{
// up along the vertical: the height grows by the same distance (cloud_height bends only with the horizontal distance)
float up = reach * (float(s) + 0.5) / float(samples);
float up = reach * (float(s) + offset) / float(samples);
depth += cloud_layer_density(index, position + vec3(0.0, up, 0.0), height + up, false);
}
return depth * reach / float(samples);
@@ -164,6 +170,16 @@ void main()
int skysteps = (lightsteps >= 4) ? 2 : 1;
bool detail = quality.w > 0.5;
float jitter = fract(interleaved_noise(vec2(texel)) + float(frame) * 0.618034);
// where the samples of the light are taken in their steps: another sequence than the one of the samples of the view
float lightjitter = fract(interleaved_noise(vec2(texel) + vec2(37.0, 17.0)) + float(frame) * 0.754878);
{
float spread = 1.0;
for (int octave = 0; octave < CLOUD_SCATTER_OCTAVES; octave++)
{
cloud_scatter_phase[octave] = cloud_phase(cosangle, spread);
spread *= 0.5;
}
}
vec3 scattered = vec3(0.0);
float transmittance = 1.0;
@@ -222,13 +238,15 @@ void main()
if (density <= 0.0)
continue;
float powder = mix(1.0, 1.0 - exp(-density / max(layer.shape.y, 1e-6) * CLOUD_POWDER), powderview);
float sunshare = (sunup > 0.0) ? cloud_sunlight(index, position, cosangle, lightsteps, powder, detail) : 0.0;
// every sample of the view takes the samples of its light at another place of their steps
float lightoffset = fract(lightjitter + float(s) * 0.754878);
float sunshare = (sunup > 0.0) ? cloud_sunlight(index, position, lightsteps, powder, detail, lightoffset) : 0.0;
// the light of the sky reaches inside through the cloud above, that of the ground through the cloud below: the base of a
// thick cloud is darker than its top, and greyer, lit only by the ground and the sky at its sides
float column = layer.shape.y * layer.shape.x;
float top = cloud_layer_bounds(layer).y;
float reach = clamp(top - height, 0.0, CLOUD_SKY_REACH);
float sky = exp(-CLOUD_SKY_FADE * cloud_sky_depth(index, position, height, reach, skysteps) - CLOUD_AMBIENT_FADE * column * max(top - height - reach, 0.0));
float sky = exp(-CLOUD_SKY_FADE * cloud_sky_depth(index, position, height, reach, skysteps, fract(lightoffset + 0.569840)) - CLOUD_AMBIENT_FADE * column * max(top - height - reach, 0.0));
float below = column * max(height - layer.heights.x, 0.0);
vec3 light = sunlight * sunshare + (ambienttop * mix(CLOUD_SKY_FLOOR, 1.0, sky) + ambientbottom * exp(-CLOUD_AMBIENT_FADE * below));
float through = exp(-density * step);