creating a pixelation filter for the camera

Godot Version

4.7.1 stable

Question

I need help creating a pixelation filter for the camera in my 3D game. I know this is done using shaders, but I’m not sure exactly how to implement it. I want an effect that makes it look as if the game’s resolution has been drastically lowered and pixel smoothing has been disabled.Ask your question here! Try to give as many details as possible

Why not actually lower your games resolution and use nearest texture filtering?

I’m surprised godotshaders.com doesn’t have a minimal example of such a shader.

By rounding/flooring the UV coordinates you can get harsh square texture reads

shader_type canvas_item;

uniform sampler2D screen: hint_screen_texture;
uniform float pixel_count = 100;

void fragment() {
	vec2 pix_uv = round(UV * pixel_count) / pixel_count;
	vec4 color = texture(screen, pix_uv);
	
	COLOR = color;
}

Put this shader on a ColorRect covering the screen