+1 vote

Hello,

I am working on adding a drop shadow to my game using shaders, and it works fine when testing from the editor or when I run an HTML5 build of the game
enter image description here

However, when I run the same shader on mobile there are gaps between the shadow and the objects it is running on
enter image description here

Here is my shader code:

shader_type canvas_item;

// The offset of the shadow from the main sprite
uniform vec2 offset = vec2(-1.0, 2.0);
// The color of the shadow to display
uniform vec4 shadow_color: hint_color = vec4(0.098, 0.164, 0.337, 1.0);
// The value to compare against to check if it is the background colour
uniform vec4 background_color: hint_color = vec4(0.282, 0.494, 0.690, 1.0);

void fragment() {
    // Get the pixel value of the pixel that will contain the shadow
    vec4 tex = texture(SCREEN_TEXTURE,SCREEN_UV,0.0);

    // Get the coords of the original pixel to see if it needs a shadow
    vec2 src_tex_location = SCREEN_UV - vec2(SCREEN_PIXEL_SIZE.x * offset.x , SCREEN_PIXEL_SIZE.y * offset.y);

    // Get the pixel value of what is supposed to exist
    vec4 offset_tex = texture(SCREEN_TEXTURE,src_tex_location,0.0);

    // Check if this pixel matches the background color
    vec3 tex_diff = tex.rgb - background_color.rgb;
    float tex_diff_max = max(max(abs(tex_diff.r), abs(tex_diff.g)), abs(tex_diff.b));

    // If the pixel is a background color, check offset pixel if it should be a shadow
    if( tex_diff_max < 0.001 ) {
        vec3 offset_pixel = offset_tex.rgb - background_color.rgb;
        float offset_pixel_max = max(max(abs(offset_pixel.r), abs(offset_pixel.g)), abs(offset_pixel.b));

        // If it doesn't match the background pixel, make a shadow
        if( offset_pixel_max > 0.001 ) {
            COLOR = shadow_color;
        } else {
            COLOR = tex;
        }
    // If it is not a background color, it shouldn't have a shadow
    } else {
        COLOR = tex
    }
}
Godot version 3.2.2
in Engine by (13 points)

same issue, waiting for awnser

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.