4 level posterization

Quick shader that posterizes with 4 levels – can easily add more levels by adding another color, threshold, and else if statement.

The way I use it is by creating a mesh instance plane in front of the camera and applying the shader to the plane.

Shader code
shader_type spatial;
render_mode unshaded;

uniform vec4 level1 : hint_color = vec4(0,0,0,1);
uniform vec4 level2 : hint_color = vec4(0.5,0.5,0.5,1);
uniform vec4 level3 : hint_color = vec4(1,1,1,1);
uniform vec4 level4 : hint_color = vec4(1,1,1,1);

uniform float threshold1 	: hint_range(0.0,1.0) = .1;
uniform float threshold2 	: hint_range(0.0,1.0) = .4;
uniform float threshold3	: hint_range(0.0,1.0) = .6;


void fragment(){
	ALBEDO = texture(SCREEN_TEXTURE, SCREEN_UV).rgb;
	float rgb_avg = (ALBEDO.r + ALBEDO.g + ALBEDO.b)/3.0;
	if(rgb_avg < threshold1){
		ALBEDO = level1.rgb;
	}else if(rgb_avg < threshold2){
		ALBEDO = level2.rgb;
	}else if(rgb_avg < threshold3){
		ALBEDO = level3.rgb;
	}else{
		ALBEDO = level4.rgb;
	}
}
Tags
4-bit, gameboy, posterization
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.

Related shaders

4-Level Posterization (Fragment)

Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
steezeburger
2 years ago

This looks so cool!

I’m a newb though, could you explain a bit more about how you use it?

I added a MeshInstance2D as a child to my player camera, and added this shader as a material to that MeshInstance2D, but it does not appear to be working. I’m not sure that is what you meant by “mesh instance plane in front of the camera” though! Can you please elaborate?

Thanks for the cool shader!

Xombie404
Xombie404
1 year ago
Reply to  steezeburger
Rob
Rob
3 months ago

Is there an updated version for Godot 4? This one no longer seems to work.