Grey threshold

A simple shader that compares average pixel color with threshold and outputs shifted color in different directions depending on the delta parameter

 

The demo scene is provided by awesome Jaanus Jaggo (Perfoon).

Shader code
shader_type canvas_item;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;

uniform float threshold: hint_range(0.0,1.0) = 0.5;
uniform float delta: hint_range(0.0,1.0) = 0.2;

void fragment(){
	vec4 screen_color = texture(SCREEN_TEXTURE, SCREEN_UV); // Get the color from the screen texture
	
	float avg = (screen_color.r + screen_color.g + screen_color.b) / 3.0;
	
	if (avg< threshold){
		COLOR.rgb = vec3(screen_color.r - delta, screen_color.r - delta, screen_color.r - delta);
	}else{
		COLOR.rgb = vec3(screen_color.r + delta, screen_color.r + delta, screen_color.r + delta);
	}
}
Tags
canvas item, grey filtering
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.
Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Sina Qadri
Sina Qadri
1 month ago

Useful for debugging

TTien63
21 days ago

Perfect! I can now make impact frame with this