mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-29 22:07:28 +01:00
50 lines
2.0 KiB
Plaintext
50 lines
2.0 KiB
Plaintext
#version 460 core
|
|
#define STAGE_COMPUTE 1
|
|
// colours of the fog towards the horizon by the angle from the azimuth of the sun, from the sky-view table of the atmosphere,
|
|
// written into the weather buffer (weather_common.glsl: fog_horizon). the far fog then has the colour of the sky behind it.
|
|
// the atmosphere blends into the old sky as opengl46_sky does it, by its share, white balance and brightness
|
|
|
|
#define LAYOUT_COMPUTE 1
|
|
#include "common.glsl"
|
|
#include "atmosphere_common.glsl"
|
|
|
|
layout(local_size_x = FOG_HORIZON_SAMPLES) in;
|
|
|
|
layout(set = PASS_SET, binding = SKY_VIEW_TEX) uniform sampler2D sky_view_lut;
|
|
|
|
layout(std430, set = COMPUTE_SET, binding = 0) buffer weather_scratch
|
|
{
|
|
vec4 weather_words[];
|
|
};
|
|
|
|
// the parameters of the kernel (push constants)
|
|
layout(push_constant) uniform kernel_constants
|
|
{
|
|
// first vec4 of fog_horizon in the weather buffer
|
|
int offset;
|
|
// x: share of the atmosphere, y: its brightness, z: desaturation by the overcast, w: brightest the colour gets
|
|
vec4 params;
|
|
vec3 white_balance;
|
|
// the colour of the old fog, which the atmosphere replaces by its share
|
|
vec3 old_color;
|
|
};
|
|
|
|
void main()
|
|
{
|
|
uint index = gl_LocalInvocationID.x;
|
|
float angle = float(index) / float(FOG_HORIZON_SAMPLES - 1) * ATMO_PI;
|
|
vec3 sun = normalize(atmo_sun_direction.xyz);
|
|
vec2 flat_sun = (dot(sun.xz, sun.xz) > 1e-8) ? normalize(sun.xz) : vec2(1.0, 0.0);
|
|
vec2 side = vec2(-flat_sun.y, flat_sun.x);
|
|
vec2 flat_view = flat_sun * cos(angle) + side * sin(angle);
|
|
// a little above the horizon, where the far fog meets the sky
|
|
vec3 direction = normalize(vec3(flat_view.x, 0.035, flat_view.y));
|
|
vec3 color = textureLod(sky_view_lut, atmo_skyview_uv_world(direction, sun), 0.0).rgb * white_balance * params.y;
|
|
color = min(color, vec3(params.w));
|
|
float luminance = dot(color, vec3(0.2126, 0.7152, 0.0722));
|
|
color = mix(color, vec3(luminance), params.z);
|
|
if (any(isnan(color)))
|
|
color = old_color;
|
|
weather_words[offset + int(index)] = vec4(mix(old_color, color, params.x), 1.0);
|
|
}
|