+2 votes

I have two simple translucent circle sprites that I'm using as fake shadows (shown below) under some characters (not shown below). When the characters get close enough, sometimes their shadow circles can overlap - which is fine - but thanks to the default blending it doesn't look right. I want the shadow circles that do overlap to be visually merged/mixed so they maintain the same opacity, but instead they add together where they overlap like this:

overlapping circles

I have to imagine there's some way to make this work with a shader, but I'm so bad at shaders that I can't seem to figure it out. Does anyone know how to solve this?

Godot version v3.5.stable.official [991bb6ac7]
in Engine by (24 points)

Not sure if it's a solution or not, but if you create a new CanvasItemMaterial for the sprite, you can set the Blend Mode on the material. I'm really not that familiar with the available modes, but maybe you can get the result you want?

I gave that a try. Add and Sub both rendered a blank shadow - couldn't even see it. Mul rendered a black rectangle instead for some reason. And Premult Alpha seemed to render the exact same way as Mix. So no dice there.

That's an interesting thread and seems to be the exact problem I'm having here. I noticed there's some final comment on there from 2021 speculating that Godot 4 will have something called a CanvasGroup which might solve this - although that doesn't help me at all since I'm still on 3.5. Thanks for the link, though.

1 Answer

0 votes

In a fragment shader you can force the alpha value to be constant. You can input the value as a float uniform and apply this value to the output COLOR.a value.

by (202 points)

My shadow texture essentially has a constant alpha as it is. A constant alpha in a shader wouldn't change anything would it? I think the core cause of this problem is that it draws every shadow sprite separately and then has to somehow mix them together when compositing or something like that.

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 Frequently asked questions and 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 [email protected] with your username.