54 lines
2.6 KiB
Plaintext
54 lines
2.6 KiB
Plaintext
shader_type spatial;
|
|
render_mode blend_mix, skip_vertex_transform, depth_test_disabled, unshaded, cull_back, shadows_disabled, fog_disabled, specular_disabled, specular_occlusion_disabled, ambient_light_disabled;
|
|
|
|
group_uniforms ChromaticAbberation;
|
|
uniform bool ca_enabled = false;
|
|
uniform lowp float ca_blur_offset : hint_range(0.0f, 10.0f, 0.01) = 2.5f;
|
|
uniform lowp float ca_centre_offset : hint_range(0.0f, 1.0f, 0.01) = 0.0f;
|
|
group_uniforms;
|
|
|
|
group_uniforms Vignette;
|
|
uniform bool vignette_enabled = false;
|
|
uniform lowp vec4 vignette_colour : source_color = vec4(0.0f, 0.0f, 0.0f, 0.4f);
|
|
uniform lowp float vignette_pupil : hint_range(0.0f, 0.9975f, 0.01f) = 0.8f;
|
|
uniform lowp float vignette_iris : hint_range(0.0025f, 5.0f, 0.01f) = 0.4f;
|
|
group_uniforms;
|
|
|
|
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_linear;
|
|
const vec2 vertices[4] = { vec2(10.0f, -10.0f), vec2(10.0f, 100.0f), vec2(-100.0f, -10.0f), vec2(-100.0f, 100.0f) };
|
|
//const vec3 debug_colours[4] = { vec3(1.0f, 0.0f, 0.0f), vec3(1.0f, 1.0f, 0.0f), vec3(1.0f, 0.0f, 1.0f), vec3(0.0f, 0.0f, 1.0f) };
|
|
|
|
void chromatic_abberation(inout vec3 mix_colour, in vec2 screen_uv, in vec2 screen_pixel_size)
|
|
{
|
|
float distance_from_centre = smoothstep(ca_centre_offset, 1.0f, distance(vec2(0.5f, 0.5f), screen_uv.xy) * 2.0f);
|
|
|
|
vec4 green_channel = texture(screen_texture, screen_uv);
|
|
vec4 red_channel = texture(screen_texture, vec2(screen_uv.x + (ca_blur_offset * screen_pixel_size.x * distance_from_centre), screen_uv.y));
|
|
vec4 blue_channel = texture(screen_texture, vec2(screen_uv.x - (ca_blur_offset * screen_pixel_size.x * distance_from_centre), screen_uv.y));
|
|
mix_colour = vec3(red_channel.r, green_channel.g, blue_channel.b);
|
|
}
|
|
|
|
void vignette(inout vec3 mix_colour, in vec2 screen_uv)
|
|
{
|
|
float distance_to_centre = distance(screen_uv, vec2(0.5f, 0.5f)) * 2.0f;
|
|
mix_colour.rgb = mix(mix_colour.rgb, vignette_colour.rgb, smoothstep((vignette_pupil * 2.0f) - 1.0f, 1.0f + vignette_iris, distance_to_centre) * vignette_colour.a);
|
|
}
|
|
|
|
|
|
void vertex()
|
|
{
|
|
//VERTEX = (inverse(CANVAS_MATRIX) * inverse(SCREEN_MATRIX) * vec4(vertices[VERTEX_ID], 1.0f, 1.0f)).xy; // For Canvas
|
|
POSITION = vec4(vertices[VERTEX_ID].xy, 1.0f, 1.0f); // For 3D
|
|
}
|
|
|
|
void fragment()
|
|
{
|
|
//COLOR = texture(screen_texture, SCREEN_UV); // For Canvas
|
|
ALBEDO = texture(screen_texture, SCREEN_UV).rgb; // For 3D
|
|
|
|
// Post-process effects are mixed together one after the other.
|
|
// To change the order of effects, simply change the function order.
|
|
if (ca_enabled) chromatic_abberation(ALBEDO, SCREEN_UV, 1.0 / VIEWPORT_SIZE);
|
|
if (vignette_enabled) vignette(ALBEDO, SCREEN_UV);
|
|
}
|