Simulating a JPEG effect
Simulating JPEG image compression to further optimize GPU performance.
A shader that simplifies the image by breaking it down into blocks—much like JPEG compression at a low-quality setting.
Use within a ColorRect.
(cover the entire viewport)
(Quality) - controls the compression force.
(Block Size) - specifies the size of the blocks.
Shader code
shader_type canvas_item;
uniform sampler2D screen_tex : hint_screen_texture, filter_nearest;
uniform int block_size : hint_range(2, 32) = 6;
uniform int color_levels : hint_range(2, 32) = 12;
void fragment() {
vec2 size = 1.0 / SCREEN_PIXEL_SIZE;
vec2 center = floor(SCREEN_UV * size / float(block_size)) * float(block_size) + float(block_size) * 0.5;
vec3 c = texture(screen_tex, center / size).rgb;
COLOR = vec4(floor(c * float(color_levels)) / float(color_levels), 1.0);
}

Comments 0
No comments yet.