Spatial Pixelation
TV witness protection style / censoring 3D pixelation.
Shader code
shader_type spatial;
render_mode unshaded, depth_draw_always, cull_back;
uniform float pixelation : hint_range(0.001, 0.1) = 0.01;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
void vertex() {
POSITION = PROJECTION_MATRIX * MODELVIEW_MATRIX * vec4(VERTEX, 1.0);
}
void fragment() {
// Get screen UV
vec2 screen_uv = SCREEN_UV;
// Calculate pixelated UV
vec2 pixel_uv = vec2(
floor(screen_uv.x / pixelation) * pixelation,
floor(screen_uv.y / pixelation) * pixelation
);
// Sample the screen texture with pixelated UV
vec4 screen_color_pixelized = texture(SCREEN_TEXTURE, pixel_uv);
// Output the pixelated color
ALBEDO = screen_color_pixelized.rgb;
ALPHA = screen_color_pixelized.a;
}