screen filters system?
This commit is contained in:
parent
08a20c683a
commit
2a6b263cae
6 changed files with 98 additions and 2 deletions
43
assets/shaders/lcd.gdshader
Normal file
43
assets/shaders/lcd.gdshader
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
|
||||
|
||||
uniform bool enabled = true;
|
||||
uniform vec2 resolution;
|
||||
uniform vec2 curvature;
|
||||
uniform vec2 scanline_opacity;
|
||||
uniform float brightness;
|
||||
|
||||
vec2 curve_uv(vec2 uv) {
|
||||
uv = uv * 2.0 - 1.0;
|
||||
vec2 offset = abs(uv.yx) / vec2(curvature.x, curvature.y);
|
||||
uv = uv + uv * offset * offset;
|
||||
uv = uv * 0.5 + 0.5;
|
||||
return uv;
|
||||
}
|
||||
|
||||
vec3 scanline_intensity(float uv, float res, float opacity) {
|
||||
float intensity = sin((uv * res - 0.25) * PI * 2.0);
|
||||
intensity = ((0.5 * intensity) + 0.5) * 0.9 + 0.1;
|
||||
return vec3(pow(intensity, opacity));
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
if (enabled) {
|
||||
vec2 curved_uv = SCREEN_UV;
|
||||
vec3 base_color = texture(SCREEN_TEXTURE, curved_uv).rgb;
|
||||
|
||||
base_color += vec3(1.0/256.0);
|
||||
base_color *= scanline_intensity(curved_uv.x, resolution.x, scanline_opacity.y);
|
||||
base_color *= scanline_intensity(curved_uv.y, resolution.y, scanline_opacity.x);
|
||||
base_color *= vec3(brightness);
|
||||
|
||||
if (curved_uv.x < 0.0 || curved_uv.y < 0.0 || curved_uv.x > 1.0 || curved_uv.y > 1.0) {
|
||||
COLOR = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
} else {
|
||||
COLOR = vec4(base_color, 1.0);
|
||||
}
|
||||
} else {
|
||||
COLOR = texture(SCREEN_TEXTURE, SCREEN_UV);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue