TarVK / pixi-shadows

Adds dynamic shadows to PixiJS
https://tarvk.github.io/pixi-shadows/dist/
MIT License
53 stars 14 forks source link

Check sprite's "light level" #7

Open skyne98 opened 4 years ago

skyne98 commented 4 years ago

Hey there! Seems like you've been busy with other projects for a while, but I have a question.

Is it possible to somehow get sprite's (maybe average) light level to see how visible the sprite is? If not, is it possible to implement? I haven't yet looked in the code, but I would assume that if it is written using shaders, then, in theory, it should be possible to check the lighting texture for such values and sum an average somehow.

If you think it can be somewhat easy to implement, then I might help out when it comes to needing it in a project I am working on. However, just to mention, I don't have a lot of PIXI experience, which might complicate things!

Thanks for you time in advance!

TarVK commented 2 years ago

Apologies for the way late response. I only noticed this issue just now! I doubt you still want this answered, but I will answer it nevertheless in case somebody else has a similar situation.

There is a texture that combines all lights that are visible on the screen into a mask that's used to light areas of the scene: ShadowFilter.ts#L19 This mask could be queried using screen space coordinates to see whether something is visible. This however won't work for things that are off the screen. Additionally for both on screen and off-screen elements, you can check whether a sprite would be lit by individual light sources using this texture: Shadow.ts#L50

If it's a critical game element, I also would suggest to not rely on the graphics pipeline for this, but instead using some more proper algorithms.