#Occlusion Silhouette not working with lighting

1 messages · Page 1 of 1 (latest)

remote gyro
#

I'm working on implementing a basic occlusion silhouette. The way I'm trying to achieve it is first my character is assembled out of multiple shaded sprites and drawn onto a SubViewport. the ViewportTexture is then routed to two different Sprite2Ds, one ysorted and one with a high z index and the silhouette shader applied. The shader is supposed to see if screen_texture matches sprite_texture and if it does, the character is visible and drawn normally (the silhouette is invisible) but if it doesn't match that means the character was occluded and teh silhouette color is drawn instead. It works in isolation, but the effect is broken if the sprites are affected by lighting (PointLight2Ds) or time of day (CanvasModulate node) effects. It's like the silhouette is not getting the effects applied to it and therefore doesn't match the screen is my best guess.

here is the shader code:

render_mode blend_mix;

uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;

uniform vec4 silhouette_color : source_color = vec4(0.0, 0.0, 0.0, 0.5);

uniform float color_tolerance : hint_range(0.0, 0.1) = 0.01;

void fragment() {
    vec4 sprite_color = texture(TEXTURE, UV);
    
    if (sprite_color.a <= 0.001) {
        discard;
    }
    
    vec4 screen_color = texture(screen_texture, SCREEN_UV);
    
    bool colors_match = all(lessThan(abs(screen_color - sprite_color), vec4(color_tolerance)));
    
    if (colors_match) {
        COLOR = sprite_color;
    } else {
        COLOR = vec4(silhouette_color.rgb, silhouette_color.a * sprite_color.a);
    }
}```
remote gyro
#

fixed it! just needed to make the render mode of Sprite (the non-silhoutte one) into unshaded with this simple shader code:

render_mode unshaded;```
sleek drift
#

@remote gyro Hey this was ages ago, but I've also been banging my head against the wall trying to solve this exact problem. I need occlusion silhouetting, but I don't want transparent effects to affect the player, only opaque occlusion. Do you have any more you could share on your solution? Thanks :)

#

The way I've been doing it so far hasn't been with a SubViewport, so I'd be interested to learn about it