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;
}
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

Spatial particle shader

Spatial Ice Shader

Simple spatial CRT effect

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments