I’m trying to create something that only shows up when it is outside of the light (player vision.) The reason I am specifically using light is because it has built-in shadows and I’d like this to show up if in a shadow as well.
How can I make it so that this right is transparent where it is currently black and partially transparent where it is grey? The PointLight2d is centered at the top left of the screen and is a banded white to transparent gradient.
What I imagine the code could look like for the effect I want:
void light() {
COLOR = vec4(COLOR.rgb, 1.0 - LIGHT_COLOR.a);
}
This doesn’t work because COLOR isn’t modifiable during the light() function so far as I can tell.
An alternate solution that I tried was to do an inverse of this gradient for this light layer and have the out of the player vision be the “light”. Unfortunately, that doesn’t work with shadows.
Let me know what ideas you have! I’m still trying to figure out how to get shaders to do what I want.
Afaik there’s no other way than to render a separate mask pass and composit. Put a full screen rect, a copy of your light, and copies of all of your occluders into a subviewport, set rect’s material to “light only” and set subviewport to use transparent background. The pixels that the light doesn’t see should end up transparent.
In object’s shader, use subviewport texture’s inverse alpha as object’s alpha.
Oof, that’s not ideal, though I think I see what you’re saying and that makes sense that it would work. At that point it makes me want to dig into godot’s code to see where they do LIGHT_ONLY as I imagine it could be a small change if I do it there. Probably gonna backburner this until I have more dire need of it though unless another solution comes up.
Thanks again for the quick reply. Gonna leave this open for a bit to see if anyone else has ideas before closing it.
hmm, maybe I can try it out then. I figured that creating another viewport and doing another pass would be a lot. If that’s not the case, then the only thing that leaves me worried is copying all of the occluders as the tilemap contains most of those and copying the tilemap wouldn’t be cheap.