18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 00:24:57 +01:00

Reduce clouds noise

This commit is contained in:
2026-11-17 01:38:17 +01:00
parent 91c2d3aba9
commit b91f1f5747
4 changed files with 22 additions and 13 deletions

View File

@@ -139,9 +139,10 @@ static_assert(offsetof(inject_block, occlusion_projection_view) == 288, "the lay
// the level of the depth pyramid of the clouds left out behind the scenery (clouds_march.comp: texels of 32 pixels of the scene) // the level of the depth pyramid of the clouds left out behind the scenery (clouds_march.comp: texels of 32 pixels of the scene)
int const CLOUD_OCCLUSION_LEVEL{4}; int const CLOUD_OCCLUSION_LEVEL{4};
// gfx.clouds.interleave: one pixel of every block of this many by this many is marched a frame, and how much of the image a pixel // gfx.clouds.interleave: one pixel of every block of this many by this many is marched a frame, and how much of the image a pixel
// marched in the frame takes from it: more than with all of them marched (0.15), as its turn comes once in a few frames // marched in the frame takes from it: less than with all of them marched (0.15), as there's a quarter of the samples a frame to
// even out the grain of the far clouds with, whose steps are the longest
int const CLOUD_INTERLEAVE{2}; int const CLOUD_INTERLEAVE{2};
float const CLOUD_INTERLEAVE_BLEND{0.3f}; float const CLOUD_INTERLEAVE_BLEND{0.08f};
struct integrate_constants struct integrate_constants
{ {
glm::ivec3 grid; glm::ivec3 grid;
@@ -566,9 +567,7 @@ void vulkan14_renderer::render_weather_view(glm::mat4 const &Projection, glm::ma
constants.size = weather.view_size; constants.size = weather.view_size;
constants.inverse_projection = inverseprojection; constants.inverse_projection = inverseprojection;
constants.view_to_world = viewtoworld; constants.view_to_world = viewtoworld;
// the turns a pixel had, not the frames: its samples are moved along their steps by the number of its turn, and with a pixel constants.frame = m_weatherstate.frame();
// marched every fourth frame the frames would move them by nearly the same every time
constants.frame = m_weatherstate.frame() / (stride * stride);
constants.quality = glm::vec4{static_cast<float>(level.steps), static_cast<float>(level.light_steps), Global.gfx_clouds_distance, level.detail ? 1.f : 0.f}; constants.quality = glm::vec4{static_cast<float>(level.steps), static_cast<float>(level.light_steps), Global.gfx_clouds_distance, level.detail ? 1.f : 0.f};
constants.rows = glm::ivec2{0, weather.view_size.y}; constants.rows = glm::ivec2{0, weather.view_size.y};
weather.march.dispatch(commands, {vk14::storage_image(weather.clouds_color->view()), vk14::storage_image(weather.clouds_depth->view()), pyramiddescriptor}, constants, weather.march.dispatch(commands, {vk14::storage_image(weather.clouds_color->view()), vk14::storage_image(weather.clouds_depth->view()), pyramiddescriptor}, constants,

View File

@@ -171,7 +171,7 @@ void main()
bool detail = quality.w > 0.5; bool detail = quality.w > 0.5;
float jitter = fract(interleaved_noise(vec2(texel)) + float(frame) * 0.618034); 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 // 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 lightjitter = fract(interleaved_noise(vec2(texel) + vec2(37.0, 17.0)) + float(frame) * 0.618034);
{ {
float spread = 1.0; float spread = 1.0;
for (int octave = 0; octave < CLOUD_SCATTER_OCTAVES; octave++) for (int octave = 0; octave < CLOUD_SCATTER_OCTAVES; octave++)
@@ -239,14 +239,16 @@ void main()
continue; continue;
float powder = mix(1.0, 1.0 - exp(-density / max(layer.shape.y, 1e-6) * CLOUD_POWDER), powderview); float powder = mix(1.0, 1.0 - exp(-density / max(layer.shape.y, 1e-6) * CLOUD_POWDER), powderview);
// every sample of the view takes the samples of its light at another place of their steps // 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); // (kept off the ends of the steps: the whole of a step is enough to smooth the bands out, and the less the samples move
// the less the light of a pixel changes from frame to frame)
float lightoffset = 0.15 + 0.7 * fract(lightjitter + float(s) * 0.414214);
float sunshare = (sunup > 0.0) ? cloud_sunlight(index, position, lightsteps, powder, detail, lightoffset) : 0.0; 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 // 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 // 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 column = layer.shape.y * layer.shape.x;
float top = cloud_layer_bounds(layer).y; float top = cloud_layer_bounds(layer).y;
float reach = clamp(top - height, 0.0, CLOUD_SKY_REACH); float reach = clamp(top - height, 0.0, CLOUD_SKY_REACH);
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 sky = exp(-CLOUD_SKY_FADE * cloud_sky_depth(index, position, height, reach, skysteps, 0.15 + 0.7 * fract(lightoffset + 0.569840)) - CLOUD_AMBIENT_FADE * column * max(top - height - reach, 0.0));
float below = column * max(height - layer.heights.x, 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)); vec3 light = sunlight * sunshare + (ambienttop * mix(CLOUD_SKY_FLOOR, 1.0, sky) + ambientbottom * exp(-CLOUD_AMBIENT_FADE * below));
float through = exp(-density * step); float through = exp(-density * step);

View File

@@ -217,9 +217,15 @@ void main()
int lightsteps = int(quality.y); int lightsteps = int(quality.y);
int skysteps = (lightsteps >= 4) ? 2 : 1; int skysteps = (lightsteps >= 4) ? 2 : 1;
bool detail = quality.w > 0.5; bool detail = quality.w > 0.5;
float jitter = fract(interleaved_noise(vec2(texel)) + float(frame) * 0.618034); // with a part of the pixels marched a frame (stride over 1) the pixels of a block share the place of their samples along the
// steps: the block gets one of its pixels marched every frame, and clouds_temporal.comp gives it to all of them, so the samples
// a pixel takes in over the frames go on from frame to frame as with all the pixels marched, evenly spread along the step.
// a place of its own for each pixel would leave every pixel with a few samples spread by chance, and the far clouds, whose steps
// are the longest, grainy
vec2 cell = vec2((mode == 0) ? texel / max(stride, 1) : texel);
float jitter = fract(interleaved_noise(cell) + 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 // 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 lightjitter = fract(interleaved_noise(cell + vec2(37.0, 17.0)) + float(frame) * 0.618034);
{ {
float spread = 1.0; float spread = 1.0;
for (int octave = 0; octave < CLOUD_SCATTER_OCTAVES; octave++) for (int octave = 0; octave < CLOUD_SCATTER_OCTAVES; octave++)
@@ -294,14 +300,16 @@ void main()
continue; continue;
float powder = mix(1.0, 1.0 - exp(-density / max(layer.shape.y, 1e-6) * CLOUD_POWDER), powderview); float powder = mix(1.0, 1.0 - exp(-density / max(layer.shape.y, 1e-6) * CLOUD_POWDER), powderview);
// every sample of the view takes the samples of its light at another place of their steps // 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); // (kept off the ends of the steps: the whole of a step is enough to smooth the bands out, and the less the samples move
// the less the light of a pixel changes from frame to frame)
float lightoffset = 0.15 + 0.7 * fract(lightjitter + float(s) * 0.414214);
float sunshare = (sunup > 0.0) ? cloud_sunlight(index, position, lightsteps, powder, detail, lightoffset) : 0.0; 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 // 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 // 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 column = layer.shape.y * layer.shape.x;
float top = cloud_layer_bounds(layer).y; float top = cloud_layer_bounds(layer).y;
float reach = clamp(top - height, 0.0, CLOUD_SKY_REACH); float reach = clamp(top - height, 0.0, CLOUD_SKY_REACH);
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 sky = exp(-CLOUD_SKY_FADE * cloud_sky_depth(index, position, height, reach, skysteps, 0.15 + 0.7 * fract(lightoffset + 0.569840)) - CLOUD_AMBIENT_FADE * column * max(top - height - reach, 0.0));
float below = column * max(height - layer.heights.x, 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)); vec3 light = sunlight * sunshare + (ambienttop * mix(CLOUD_SKY_FLOOR, 1.0, sky) + ambientbottom * exp(-CLOUD_AMBIENT_FADE * below));
float through = exp(-density * step); float through = exp(-density * step);

View File

@@ -58,7 +58,7 @@ void main()
// pixel between two of them reaches as far both ways). their range holds the history, and the nearest stands for a pixel of // pixel between two of them reaches as far both ways). their range holds the history, and the nearest stands for a pixel of
// another frame which has no history // another frame which has no history
// the share of the pixels of this frame next to a pixel of another frame, of the share of a pixel of this frame // the share of the pixels of this frame next to a pixel of another frame, of the share of a pixel of this frame
const float BESIDE_SHARE = 0.35; const float BESIDE_SHARE = 0.65;
int spacing = max(stride, 1); int spacing = max(stride, 1);
ivec2 past = (texel + spacing - phase) % spacing; ivec2 past = (texel + spacing - phase) % spacing;
bool fresh = all(equal(past, ivec2(0))); bool fresh = all(equal(past, ivec2(0)));