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

256 colour pixelation

3D Pixelation via material

guest

11 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
NekotoArts
3 years 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

Jason Kim
Jason Kim
2 years ago
Reply to  NekotoArts

not working

Arcadev
Arcadev
2 years ago

Great Shader, however when I apply it I can’t see particle effects. how do I fix it?

CalzarStudios
CalzarStudios
2 years ago
Reply to  Arcadev

you put the render prority to -1

Civilian
Civilian
2 years ago

Made an account just to say thanks, the shader worked like a charm. Would recommend setting the priority of the quad mesh to a lower value so it doesn’t block any other objects in your game, in case someone else runs into the same problems I did.

Gwynoak
Gwynoak
2 years ago

Dude, I was messing with texture and model level shaders for hours and this looks PERFECT for what I needed. I lose it every time I think about it. It looks SO GOOD and its literally a 3D plane mesh crammed in front of the player camera. They’re wearing pixelated beer goggles and that makes me laugh because you’d never know.

Flail
Flail
1 year ago

Great shader. But when used in a 3d scene with a Sprite3D, there are some black borders that appear along the side of the sprite. Is there anyway to solve this? I tried changing the Alpha Cut, but I still need “Opaque Pre-pass” and with this option there are these black borders that sometime appear.

burger
burger
1 year ago

Great shader, but for some reason i can’t see anything that has some sort of transparency? If i make a material with some transparency it is fully invisible in game with this, and this also happens with Label3Ds. Anyone having the same problem?

Sanzo
7 months ago

Thanks but it doesn’t work, it says “E 0:00:00:851  SCREEN_TEXTURE has been removed in favor of using hint_screen_texture with a uniform.
To continue with minimal code changes add ‘uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;’ near the top of your shader.
 <C++ Source> :13
” and sincei m stupid i can’t fix it myself, replacing screen_texture with hint_screen_texture didn’t work.

xtrapsp
xtrapsp
6 months ago
Reply to  Sanzo
shader_type spatial;
render_mode unshaded;


uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;


const int pixel_size = 4;


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).rgb;
}