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;
}
}
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!
spacial shader types are for 3d objects I’m pretty sure,
https://docs.godotengine.org/en/latest/tutorials/shaders/shader_reference/spatial_shader.html
Is there an updated version for Godot 4? This one no longer seems to work.