Files
CosmicClash/Game/shaders/post_process.gdshader

28 lines
1019 B
Plaintext

shader_type canvas_item;
render_mode unshaded;
uniform sampler2D screen_texture : hint_screen_texture, filter_linear;
uniform float chromatic_aberration : hint_range(0.0, 0.02) = 0.0;
uniform float vignette_strength : hint_range(0.0, 1.0) = 0.22;
void fragment() {
vec2 radial = UV - vec2(0.5);
vec2 chroma = radial * chromatic_aberration;
vec4 center = texture(screen_texture, UV);
vec3 color = center.rgb;
// The branch is driven by one uniform for the whole draw, so non-turbo
// frames avoid two redundant screen taps without causing warp divergence.
if (chromatic_aberration > 0.0001) {
color.r = texture(screen_texture, UV + chroma).r;
color.b = texture(screen_texture, UV - chroma).b;
}
// Aspect-correct vignette, always subtle and tightened slightly on turbo.
vec2 aspect_radial = radial;
aspect_radial.x *= SCREEN_PIXEL_SIZE.y / SCREEN_PIXEL_SIZE.x;
float vignette = smoothstep(0.38, 0.78, length(aspect_radial));
color *= 1.0 - vignette * vignette_strength;
COLOR = vec4(color, 1.0);
}