0 votes

What would be the best process for creating a shader to compare the depth maps of multiple overlapping sprites and only drawing the pixel that is highest?

Currently I can do this on a per-sprite basis, but I don't know how to compare multiple sprites. This is what I have so far, it simply compares the depth map to an arbitrary threshold and draws the pixel if it is above it:

shader_type canvas_item;

uniform sampler2D depthmap : hint_black;


void fragment() {

    float threshold = cos(TIME);

    if (texture(depthmap,UV).r >= threshold){
        COLOR = texture(TEXTURE, UV);
    }
    else {
        COLOR = vec4(0.0,0.0,0.0,0.0);
    }
    }

This is my second week learning shaders.

Thanks.

in Engine by (12 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.