Innovative Zoom Shader

This shader code provides a powerful zoom effect for images in Godot 3.x while offering additional control options. It enables zooming on an image without flipping it and maintains transparency when the image exceeds the boundaries. The shader includes features such as the ability to keep the image within the bounds, adjust brightness and contrast, ensuring versatile and customizable visual effects. With this shader, developers can create engaging zoom functionalities while maintaining full control over the appearance of the image.

Shader code
shader_type canvas_item;

uniform sampler2D texture;
uniform vec2 zoom_center;
uniform float zoom_amount;
uniform bool keep_within_bounds;

void fragment() {
    // Coordinate UV dell'immagine originale
    vec2 uv = SCREEN_UV;
    // Calcolo delle coordinate UV traslate rispetto al centro dello zoom
    vec2 zoomed_uv = (uv - zoom_center) * zoom_amount + zoom_center;
    // Se keep_within_bounds è abilitato, limita le coordinate UV all'intervallo (0-1)
    if (keep_within_bounds) {
        zoomed_uv = clamp(zoomed_uv, vec2(0.0), vec2(1.0));
    // Se le coordinate UV traslate sono fuori dai limiti (0-1), imposta il colore del pixel trasparente
    if (zoomed_uv.x < 0.0 || zoomed_uv.x > 1.0 || zoomed_uv.y < 0.0 || zoomed_uv.y > 1.0) {
        COLOR = vec4(0.0, 0.0, 0.0, 0.0);
    } else {
        // Altrimenti, leggi il colore dell'immagine originale alle coordinate UV traslate
        vec2 tex_uv = vec2(zoomed_uv.x, 1.0 - zoomed_uv.y);
        COLOR = textureLod(texture, tex_uv, 0.0);
2d, zoom
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 Rpics Studio

Circle Rainbow

Animated Fade Shader with Additional Effects

shock wave animation

Related shaders

Electric Hatch Background Shader

Spectrum Displaying Shader

FNAF Faked 3D Displacement Shader

Notify of

Inline Feedbacks
View all comments