3D Pixelation

-Works in Godot 4 & Godot 3.x-
Pixelates the screen output with custom pixel size

**Instructions**
Use shader on a quad mesh placed infront of the camera

**Source**
Method by David Lettier

Shader code
shader_type spatial;
render_mode unshaded;

const int pixel_size = 4; //resolution must be divisible by pixel_size

void fragment() {
	float x = float(int(FRAGCOORD.x) % pixel_size);
	float y = float(int(FRAGCOORD.y) % pixel_size);

	x = FRAGCOORD.x + floor(float(pixel_size) / 2.0) - x;
	y = FRAGCOORD.y + floor(float(pixel_size) / 2.0) - y;

	ALBEDO = texture(SCREEN_TEXTURE, vec2(x, y) / VIEWPORT_SIZE).xyz;
}
Tags
3d, filter, pixel, pixelate, pixelation, pixelator, psx, retro, screen
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

Square Pixelation

guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
NekotoArts
NekotoArts
2 days ago

You could also use:

vec2 pixelated_uv = round(SCREEN_UV * float(pixel_size)) / float(pixel_size);
ALBEDO = texture(SCREEN_TEXTURE, pixelated_uv).rgb;

So that it works with any integer even if its not divisible