generated from krampus/template-godot4
24 lines
705 B
Plaintext
24 lines
705 B
Plaintext
|
/* Binary threshold shader */
|
||
|
|
||
|
shader_type canvas_item;
|
||
|
|
||
|
uniform vec4 color_low: source_color = vec4(0.0, 0.0, 0.0, 1.0);
|
||
|
uniform vec4 color_hi: source_color = vec4(1.0, 1.0, 1.0, 1.0);
|
||
|
|
||
|
uniform float threshold: hint_range(0.0, 1.0) = 0.5;
|
||
|
uniform float contrast: hint_range(0.0, 1.0) = 1.0;
|
||
|
uniform float offset: hint_range(-1.0, 1.0) = 0.0;
|
||
|
|
||
|
|
||
|
void fragment() {
|
||
|
vec3 screen_col = texture(TEXTURE, UV).rgb;
|
||
|
|
||
|
// calculate pixel luminosity
|
||
|
float luminosity = (screen_col.r * 0.299) + (screen_col.g * 0.587) + (screen_col.b * 0.114);
|
||
|
|
||
|
// adjust contrast & offset
|
||
|
luminosity = clamp((luminosity - 0.5 + offset) * contrast + 0.5, 0.0, 1.0);
|
||
|
|
||
|
COLOR.rgba = luminosity > threshold ? color_hi : color_low;
|
||
|
}
|