heliostat/src/shaders/threshold.gdshader

24 lines
705 B
Plaintext
Raw Normal View History

2024-07-21 20:38:56 +00:00
/* 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;
}