Hope someone can offer some advice! I am pretty new to game dev concepts.
I am at a point where I am trying to implement light sources in my Phaser 3 game.
Essentially, I have a bunch of polygons defined for walls and obstacles. I want light sources that can illuminate rooms and have the light blocked by the walls, but move through gaps. I’ve already implemented a pretty good Line of Sight implementation for the active character – using raycasting. But I am wondering what the best way to achieve lighting is now along with that.
I played around with the Light2D pipeline and tried adding Ambient Light and lights that way, but it seems pretty limited – there does not seem to be a way to mask those lights by obstacles, or have them blocked by obstacles.
I have something implemented already that is very similar to this example using masks and ray casting. Are you saying I should use the same technique for all the lights in the scene too?
I could certainly give it a try- though I wonder if performance will slow down a bit from all that.
Also- I’m not sure how to handle things like light intensity and color when using masks. I suppose it could be a mask over a graphics layer? But I’m not sure that would work if the light graphics had a blend mode set such as ADD. (When I tried to add a mask to an ambient light layer using MULTIPLY it just removed the whole graphics instead of the mask area.)
Edit: Ah, I think I was using a BitmapMask when trying to do that over ADD blend mode - I believe I need to use a Geometry mask for that.
If you’re already using a mask, I think you can just mask the light sources as well. If you were already using the Light 2D pipeline, you can keep using it.
Thanks, I got something working pretty well using just various graphics drawn on a render texture with MULTIPLY blend mode, and apply masks to those graphics before drawn.
Would be great if Light2D could let me apply masks to the lights added, but I saw no way to do that.
I looked into your example more but I am not sure if it’ll help. In my custom solution I apply masks after calculating visibility polygons so lights cast shadows, as well as masks to mimic directional lights.
My solution isn’t optimal yet, but would be better if I could use this light pipeline.