mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 19:44:58 +01:00
Clouds and fog tweaks
This commit is contained in:
@@ -3,7 +3,14 @@
|
||||
// the clouds of the main view smoothed over frames: the image of this frame (clouds_march.comp, ray started at another
|
||||
// distance every frame) blended into the one of the previous frames, found where the clouds were by the distance of the
|
||||
// clouds, the rotation and the move of the camera. the history is held to the range of the neighbourhood of this frame,
|
||||
// so moving clouds and a turning camera don't leave trails
|
||||
// so moving clouds and a turning camera don't leave trails. the pixels the scenery hid (alpha -1 from clouds_march.comp, which
|
||||
// didn't march them) keep what the history holds where they were, as it is: when the scenery uncovers them there's something to
|
||||
// blend into.
|
||||
// with a part of the pixels marched a frame (stride over 1: the ones at phase in the blocks of stride x stride pixels, the others
|
||||
// hold what they were given in their turn, some frames ago and for the view of that frame) the pixels of this frame are blended
|
||||
// in as they are; the others take the pixels of this frame next to them, evened out, with a smaller share, so every pixel gets
|
||||
// something of every frame and the turns of the pixels don't show as a pattern. the history is held to the range of the pixels
|
||||
// of this frame around
|
||||
|
||||
#define LAYOUT_COMPUTE 1
|
||||
#include "common.glsl"
|
||||
@@ -27,6 +34,9 @@ layout(push_constant) uniform kernel_constants
|
||||
vec3 previous_camera;
|
||||
// share of this frame in the result; 1 when there is no history
|
||||
float blend;
|
||||
// the pixels marched in this frame: the ones at phase in the blocks of stride x stride pixels (1: all of them)
|
||||
int stride;
|
||||
ivec2 phase;
|
||||
};
|
||||
|
||||
void main()
|
||||
@@ -35,34 +45,80 @@ void main()
|
||||
if (any(greaterThanEqual(texel, size)))
|
||||
return;
|
||||
vec4 current = texelFetch(current_color, texel, 0);
|
||||
bool hidden = current.a < 0.0;
|
||||
// no clouds, where there's nothing to keep
|
||||
if (hidden)
|
||||
current = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
if (blend >= 1.0)
|
||||
{
|
||||
imageStore(result, texel, current);
|
||||
return;
|
||||
}
|
||||
// the range of the neighbourhood
|
||||
vec4 low = current;
|
||||
vec4 high = current;
|
||||
for (int y = -1; y <= 1; y++)
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
vec4 neighbour = texelFetch(current_color, clamp(texel + ivec2(x, y), ivec2(0), size - 1), 0);
|
||||
low = min(low, neighbour);
|
||||
high = max(high, neighbour);
|
||||
}
|
||||
// the pixels of this frame around: the one the pixel is, or the one before it, and those a stride away on both sides (a
|
||||
// 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
|
||||
// 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;
|
||||
int spacing = max(stride, 1);
|
||||
ivec2 past = (texel + spacing - phase) % spacing;
|
||||
bool fresh = all(equal(past, ivec2(0)));
|
||||
ivec2 base = texel - past;
|
||||
vec4 low = vec4(1e30);
|
||||
vec4 high = vec4(-1e30);
|
||||
vec4 nearest = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
float nearestdistance = 1e30;
|
||||
bool ranged = false;
|
||||
// the pixels of this frame on both sides of a pixel of another frame, which is half way between them
|
||||
vec4 beside = vec4(0.0);
|
||||
float besidecount = 0.0;
|
||||
if (!hidden)
|
||||
{
|
||||
for (int y = -1; y <= (past.y == 0 ? 1 : 2); y++)
|
||||
for (int x = -1; x <= (past.x == 0 ? 1 : 2); x++)
|
||||
{
|
||||
ivec2 place = base + ivec2(x, y) * spacing;
|
||||
if (any(lessThan(place, ivec2(0))) || any(greaterThanEqual(place, size)))
|
||||
continue;
|
||||
vec4 neighbour = texelFetch(current_color, place, 0);
|
||||
if (neighbour.a < 0.0)
|
||||
continue;
|
||||
low = min(low, neighbour);
|
||||
high = max(high, neighbour);
|
||||
ranged = true;
|
||||
vec2 away = vec2(place - texel);
|
||||
float distance2 = dot(away, away);
|
||||
if (distance2 < nearestdistance)
|
||||
{
|
||||
nearestdistance = distance2;
|
||||
nearest = neighbour;
|
||||
}
|
||||
if (x >= 0 && y >= 0 && x <= min(past.x, 1) && y <= min(past.y, 1))
|
||||
{
|
||||
beside += neighbour;
|
||||
besidecount += 1.0;
|
||||
}
|
||||
}
|
||||
// what a pixel of another frame holds is of the view of that frame
|
||||
if (!fresh)
|
||||
current = (besidecount > 0.0) ? beside / besidecount : nearest;
|
||||
}
|
||||
vec2 ndc = (vec2(texel) + 0.5) / vec2(size) * 2.0 - 1.0;
|
||||
vec4 near = inverse_projection * vec4(ndc, 1.0, 1.0);
|
||||
vec3 direction = normalize(mat3(view_to_world) * normalize(near.xyz / near.w));
|
||||
float span_distance = texelFetch(current_depth, texel, 0).r;
|
||||
vec3 position = direction * span_distance - previous_camera;
|
||||
vec4 clip = previous_projection_view * vec4(position, 1.0);
|
||||
float share = blend;
|
||||
float share = hidden ? 0.0 : blend * (fresh ? 1.0 : BESIDE_SHARE);
|
||||
vec4 history = current;
|
||||
if (clip.w > 0.0)
|
||||
{
|
||||
vec2 coords = clip.xy / clip.w * 0.5 + 0.5;
|
||||
if (all(greaterThanEqual(coords, vec2(0.0))) && all(lessThanEqual(coords, vec2(1.0))))
|
||||
history = clamp(textureLod(history_color, coords, 0.0), low, high);
|
||||
{
|
||||
history = textureLod(history_color, coords, 0.0);
|
||||
if (ranged)
|
||||
history = clamp(history, low, high);
|
||||
}
|
||||
else
|
||||
share = 1.0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user