Added and improved screen shaders, switched to viewport stretch mode, improved overall visual style

This commit is contained in:
ChaoticByte 2024-09-25 23:50:35 +02:00
parent bf1bf94f63
commit 471c496003
No known key found for this signature in database
7 changed files with 95 additions and 20 deletions

View file

@ -1,41 +1,54 @@
shader_type canvas_item;
render_mode unshaded;
// uniforms
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_linear_mipmap;
// simple edge detection
// constants
const vec3 BLACK = vec3(0);
const float glow_strength = 0.5;
const float glow_size_lod = 3.0;
const int outline_radius = 1;
// simple edge detection based on black
bool is_edge(int radius, vec2 screen_uv, vec2 screen_pixel_size) {
bool ed_found_black = false;
bool ed_found_bg = false;
bool ed_found_color = false;
// check neighbor pixels
for (int x = -radius; x < radius+1; x++) {
for (int y = -radius; y < radius+1; y++) {
vec4 p = texture(screen_texture, screen_uv + (vec2(float(x), float(y)) * screen_pixel_size));
if (p.rgb == vec3(0.0)) {
ed_found_black = true;
if (p.rgb == BLACK) {
ed_found_bg = true;
} else {
ed_found_color = true;
}
}
}
return ed_found_black && ed_found_color;
return ed_found_bg && ed_found_color;
}
//
void fragment() {
// get screen texture
vec4 screen = texture(screen_texture, SCREEN_UV);
// apply edge detection
int radius = max(int(0.003 * (1.0/SCREEN_PIXEL_SIZE.y)), 1); // with a relative radius
if (is_edge(radius, SCREEN_UV, SCREEN_PIXEL_SIZE)) {
COLOR = screen;
} else {
COLOR = vec4(0, 0, 0, 1);
if (is_edge(outline_radius, SCREEN_UV, SCREEN_PIXEL_SIZE)) {
if (screen.rgb != BLACK) { // would be incompatible with target backgrounds != black
COLOR = screen;
}
}
// apply glow
// blur a relative radius -> x * log(1.0/SCREEN_PIXEL_SIZE.y)
// using log, because the LOD value seems to affect the blur radius exponentially
vec4 glow = textureLod(screen_texture, SCREEN_UV, 0.5 * log(1.0/SCREEN_PIXEL_SIZE.y));
if (screen.rgb == vec3(0.0)) {
COLOR = mix(COLOR, glow, 0.4) + (glow * 0.3);
vec4 glow = textureLod(screen_texture, SCREEN_UV, glow_size_lod);
if (screen.rgb == BLACK) {
COLOR += glow * glow_strength;
}
// set alpha to 1
COLOR.a = 1.0;
}

View file

@ -0,0 +1,29 @@
shader_type canvas_item;
render_mode unshaded;
// uniforms
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_linear_mipmap;
uniform sampler2D vignette_mask;
// constants
const float rgb_distortion_v_mult = 0.9;
const float rgb_distortion_v_exp = 2.0;
const float rgb_distortion_v_min = 0.04;
const float rgb_distortion_v_max = 0.12;
//
void fragment() {
float v = texture(vignette_mask, SCREEN_UV).r;
// rgb & blur distortion
float v_ = clamp(
pow(v * rgb_distortion_v_mult, rgb_distortion_v_exp),
rgb_distortion_v_min,
rgb_distortion_v_max
);
COLOR.r = textureLod(screen_texture, SCREEN_UV - (v_ * 0.01), v).r;
COLOR.g = textureLod(screen_texture, SCREEN_UV + (v_ * 0.01), v).g;
COLOR.b = textureLod(screen_texture, SCREEN_UV, v).b;
}

View file

@ -0,0 +1,10 @@
[gd_resource type="GradientTexture2D" load_steps=2 format=3 uid="uid://bwlgypt4xjocj"]
[sub_resource type="Gradient" id="Gradient_h26vj"]
[resource]
gradient = SubResource("Gradient_h26vj")
width = 640
height = 640
fill = 1
fill_from = Vector2(0.5, 0.5)