Closed amir-arad closed 2 years ago
source of light outside the stage
What do you mean exactly with this point?
reduce the shadow of each pixel to a boolean value:
This sounds like it would come down to looking up the brightness value in the overall scene mask, see: https://github.com/TarVK/pixi-shadows/issues/7
Ideally, a way to know which DisplayObject is actually blocking light
That's a tough one with this pipeline. The current setup renders all shadow casters to 1 texture, then queries the texture for determining occlusion. The only way to know what object blocked a light (shadow) source in a given direction, would be to encode this data visually. So this would require you to encode the identifier of the shadow caster into the caster itself using for instance some filter to color the whole caster a specific integer color. Then then a pass of a filter similar to the shadowMapFilter could be performed to instead store the blocking color (object ID) in a given direction. This filter can be rendered to a texture such that the texture can then later be queried to extract this info.
even more fantastic will be a mode where the shadow is not black but transparent
Sounds like this could be achieved by adding either an additional filter ontop of the shadow mask filter, or by modifying the existing filter to use a specific color and transparency. Moreover, you would need to alter the shadow filter here to not multiply the original color by the intensity of the masks, but instead use the masks as an overlay on top of the original. Or you could even just not use it as a filter at all and simply extract the texture, and create a corresponding sprite and add the sprite in your scene below certain objects so you have proper layering.
All in all I would recommend not using the graphics pipeline for gameplay mechanics though. In case you have highly complex shapes, it may be a fair option, but generally speaking, I would really do this kind of stuff purely on the CPU using some good algorithms and data structures. A sweep-line algorithm that performs a radial (increasing angle) sweep instead of a sideways sweep, combined with some efficient spatial data structures for querying all relevant objects in range, would be appropriate for this. It would run very efficiently in near linear time, and you can easily extract and use all the data you would like here. It would have to operate on way less data and be screen resolution independent, while resulting in data that's of much higher resolution than what you would get with these shadows. But of course if you don't have much experience with these sorts of things, it may also take a bit more effort to get it going. Unfortunately I don't have any good resources for this, I myself just recently followed a nice university course about geometric algorithms.
thank you (again)
I'm working on my game Starwards, and I would like to have these features so that I can use this plugin to render the field of view of a top-down space game: (I dont expect anyone to implement them for me or even accept the added complexity they introduce to the codebase, but I think it's better to have a chance of discussion and would appreciate any advice while designing and implementing it myself)