Pixei Transition Shader

Pixelation Transition Shader
This shader creates a pixelated tile–based transition between two textures.
It gradually reveals the new texture over the old one by adjusting the size of the pixel blocks, producing a smooth and visually appealing scene swap.

Usage Notes:

 

  • Scene transitions: provide snapshots of the current scene and the target scene as from_tex and to_tex.

  • The shader animates the pixelation effect to reveal the new scene. The transition goes from clear → highly pixelated → clear.

     

Transition Behavior:

 

  • At progress = 0 → fully shows from_tex (clear).

  • At progress = 0.5 → shows the most pixelated version of the image.

  • At progress = 1 → fully shows to_tex (clear).

  • The pixelation dynamically adjusts based on progress to create a smooth animation.

Shader code
shader_type canvas_item;

// ========================
// 输入纹理
// ========================
uniform sampler2D from_tex;
uniform sampler2D to_tex;

// ========================
// 过渡控制
// ========================
uniform float progress : hint_range(0.0, 1.0) = 0.0;

// ========================
// 像素分辨率控制
// ========================
uniform float min_tiles = 1.0;    // 最低分辨率(最像素化)
uniform float max_tiles = 200.0;  // 最高分辨率(过渡中接近原图)

void fragment() {
    vec2 screen_size = vec2(1.0) / SCREEN_PIXEL_SIZE;
    vec2 fragCoord = UV * screen_size;

    // 定义最终采样的UV坐标
    vec2 sample_uv = UV;

    // 仅在 0 < progress < 1 时启用像素化采样
    if (progress > 0.0 && progress < 1.0) {
        // 过渡曲线:0→0.5→1 对应 清晰→最像素→清晰
        float transition_curve = abs(progress - 0.5) * 2.0;
        float count = mix(min_tiles, max_tiles, transition_curve);
        count = floor(count);

        // 计算瓦片尺寸并做中心采样
        vec2 tileSize = screen_size / count;
        vec2 sample_pos = floor(fragCoord / tileSize) * tileSize + tileSize * 0.5;
        sample_uv = sample_pos / screen_size;
    }

    // 过渡混合纹理
    vec4 from_col = texture(from_tex, sample_uv);
    vec4 to_col   = texture(to_tex, sample_uv);
    COLOR = mix(from_col, to_col, progress);
}
Live Preview
Tags
2d shader, canvas_item, godot 4, transition,fade
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.

More from muzi1983

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments