Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Is there a way to detect which hulls are affected by light? #25

Open
scott-lin opened this issue Jun 15, 2019 · 3 comments
Open

Comments

@scott-lin
Copy link

First of all, great library! It's light years ahead of other attempts on the internet.

I have successfully added a light into my top-down prototype, which is casting shadows beautifully on my hulls. Now I'd like to understand if there is a way to figure out which hulls are casting shadows (in other words, which hulls the light is reaching)?

I didn't see any hooks for this in the Hull class, so I'll keep looking throughout the code base, but thought I'd ask too. If I find something, I'll post it for others too. Thanks.

@discosultan
Copy link
Owner

Hi and thanks!

I understand you envision a property on Light class that would provide information which hulls it intersects with on that particular frame.

The checks for light / hull intersections are currently performed here:

penumbra/Source/Hull.cs

Lines 301 to 302 in 4b85d25

light.Bounds.Intersects(ref hull.Bounds) &&
hull.WorldPoints.Contains(ref light._position))
. Note that even if I attached those results to a light, it might not be accurate enough for your particular use-case, since it is only checking for the rectangle (AABB) intersection around light and doesn't take the exact shape of a light nor hull into account.

Let me know what would be best fit for your scenario. Perhaps I can pull the aforementioned method apart and attach that information to a light on a frame-by-frame basis.

@scott-lin
Copy link
Author

Thanks for the quick response and details. You're right, that check isn't quite enough for my particular case.

To explain my scenario in more detail, I'd like to take action on the entities in my game that are not lit up (on a particular frame). To do this, I am hopeful to get to know which hull are lit up via penumbra; if I know this much, I can map them to game entities on my side.

Unfortunately, the AABB intersection isn't enough since, as you know, this might identify hulls eclipsed by other hulls. I'm guessing the checks you mentioned above are for narrowing down and identifying possible candidates to shade (for performance), but the final determination of light drawing is done in the Penumbra*.fx code? Hopefully there would be a way to return what hulls are actually shined on from the fx calculations.

@scott-lin
Copy link
Author

scott-lin commented Jun 15, 2019

It looks like ShadowRenderer identifies the relevant shadow/hull vertices to pass along to PenumbraShadow effect to cast shadows / illuminate hulls. Hopefully this summary is accurate.

Unfortunately, I'm not a graphics programmer, so this is as far as I can get without help / doing some deeper learning of what VAOs are, what role the hull indices play versus the hull vertices, how these integrate with the graphic effects, etc.

That said, I would defer to your opinion on whether it is possible to identify the hulls hit by light and the right approach. However, I'm happy to get my hands dirty if you do not have the time; I completely understand. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants