3D Pixelation via material
with this shader you can set personal level of pixelation for each object
INSTRUCTION:
-just drop this shader to next pass in resource
my first shader and yes im gonna fix that crops
Shader code
shader_type spatial;
render_mode unshaded;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture;
uniform int pixel_size = 4;
void vertex() {
float nw = (1.0*float(pixel_size));
if (NORMAL.x == 1.0 || NORMAL.y == 1.0 || NORMAL.z == 1.0 || NORMAL.x == -1.0 || NORMAL.y == -1.0 || NORMAL.z == -1.0){
VERTEX *= 1.0+0.01*nw;
}
if ((NORMAL.x != 1.0 && NORMAL.y != 0.0 && NORMAL.z != 0.0) && (NORMAL.y != 1.0 && NORMAL.x != 0.0 && NORMAL.z != 0.0) && (NORMAL.z != 1.0 && NORMAL.x != 0.0 && NORMAL.y != 0.0) && (NORMAL.x != -1.0 && NORMAL.y != 0.0 && NORMAL.z != 0.0) && (NORMAL.y != -1.0 && NORMAL.x != 0.0 && NORMAL.z != 0.0) && (NORMAL.z != -1.0 && NORMAL.x != 0.0 && NORMAL.y != 0.0)){
VERTEX += NORMAL*0.01*nw;
}
}
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;
vec4 oldtext = texture(SCREEN_TEXTURE,SCREEN_UV*1.0);
vec4 pixelatedtext = texture(SCREEN_TEXTURE, vec2(x, y) / (VIEWPORT_SIZE));
if (pixelatedtext.a==0.0 && oldtext.a==0.0){
discard;
}
ALBEDO = pixelatedtext.rgb;
}
This is a GREAT shader! I was looking for something that would let me do exactly what this does and it’s on the front page just waiting for me to stumble upon it! Easy to use, works great, and very good at what it does! Thank you so much for making this!!!
This is great! It does however seem to affect everything else that is around it, this is what happens to a background object if I place it on a sphere, it also gets pixelated https://postimg.cc/RNXW3w4c do you know any way to fix it?
I am constantly trying to find a solution to this problem. But so far, all the methods that I have found require much more effort than the method with a 2×2 mesh infront of cam.
Couldn’t it be done with some sort of depth test?
sadly not :/
i tried but no success.