Deep Map Effect

depth_texture: The depth texture can be obtained by using the online service, which is free for some features.


zoom_center is the point around which the zoom effect occurs. UV values range from 0 to 1, so vec2(0.5, 0.5) represents the center of the image.


zoom_intensity controls the strength of the zoom effect. Positive values make the image appear to come closer (zoom in), while negative values make it appear to move away (zoom out).


The depth map is used to vary the zoom factor. Pixels with greater depth (lighter in the depth map) will appear to move more than those with less depth (darker in the depth map).

The final effect should be similar to what you describe, where the image seems to move back and forth based on the values of the depth map. You can adjust zoom_intensity to control the intensity of the zoom effect.

Shader code
shader_type canvas_item;

uniform sampler2D depth_texture; // Your depth map
uniform vec2 zoom_center = vec2(0.5, 0.5); // Zoom center in UV coordinates
uniform float zoom_intensity = 0.1; // Zoom intensity, where >0 means zoom in and <0 means zoom out

void fragment() {
    // Get the depth value from the depth map
    float depth = texture(depth_texture, UV).r;

    // Calculate the zoom factor based on depth
    // Closer pixels will have a greater zoom factor and vice versa
    float zoom_factor = 1.0 + (depth - 0.5) * zoom_intensity;

    // Calculate the new UV coordinates for zoom
    // Move each pixel towards the zoom center based on the zoom factor
    vec2 mod_uv = (UV - zoom_center) * zoom_factor + zoom_center;

    // Get the pixel color from the main texture with the new UV coordinates
    COLOR = texture(TEXTURE, mod_uv);
deep map
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

Normal map 2D

Tile Map

2D Fire Effect with colour banding

Notify of

Inline Feedbacks
View all comments