Files
project-vivi/Assets/Visuals/Shaders/post_process_vignette.glsl
T
2026-09-19 10:06:28 -04:00

47 lines
1.6 KiB
GLSL

#[compute]
#version 450
// Invocations in the (x, y, z) dimension
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(rgba16f, set = 0, binding = 0) uniform image2D screen_texture;
// Our push constant
layout(push_constant, std430) uniform Params {
vec2 raster_size;
vec2 reserved;
vec4 vignette_colour;
float vignette_pupil;
float vignette_iris;
vec2 reserved2;
} params;
// void chromatic_abberation(inout vec3 mix_colour, in vec2 screen_uv, in vec2 screen_pixel_size)
// {
// float distance_from_centre = smoothstep(params.ca_centre_offset, 1.0f, distance(vec2(0.5f, 0.5f), screen_uv) * 2.0f);
// mix_colour.r = imageLoad(screen_texture, vec2(screen_uv.x + (params.ca_blur_offset * screen_pixel_size.x * distance_from_centre), screen_uv.y)).r;
// mix_colour.b = imageLoad(screen_texture, vec2(screen_uv.x - (params.ca_blur_offset * screen_pixel_size.x * distance_from_centre), screen_uv.y)).b;
// }
// The code we want to execute in each invocation
void main() {
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec2 screen_uv = gl_GlobalInvocationID.xy / params.raster_size;
vec4 color = imageLoad(screen_texture, uv);
// Custom code below this line
// chromatic_abberation(color.rgb, screen_uv, screen_pixel_size);
float distance_to_centre = distance(screen_uv, vec2(0.5f, 0.5f)) * 2.0f;
color.rgb = mix(color.rgb, params.vignette_colour.rgb, smoothstep((params.vignette_pupil * 2.0f) - 1.0f, 1.0f + params.vignette_iris, distance_to_centre) * params.vignette_colour.a);
// Custom code above this line
imageStore(screen_texture, uv, color);
}