Hi all,
I've tried to search for my problem but couldn't find anything useful, so I turn directly to your wise counsel.
I have a node that is the player, in a room all by himself and dynamic light ( acting as an innocent torch). I would like to find out if the player is in shadow or light, like in the Thief games. I've tried to think about the problem but I couldn't come to anything conclusive, probably because I lack the required skill. I would appreciate if someone can point me to the right direction. I am not asking to solve the problem for me, just to point out some techniques commonly used to solve such a problem. Also, if Irrlicht is even capable of such a thing without serious changes.
Thank you in advance!
How to determine if node is illuminated
Re: How to determine if node is illuminated
Well, i don't know the mechanics of the game, but it seems it had a sort of lighting information associated to every area of the levels, so, perhaps building such a structure for your character to move could help. Pick your stage, pick your lights, divide the volume of the stage into manageable parts, calculate the amount of lighting that each light provides to each part of the volume of the stage, keeping in mind the projected shadows, and that could be one approach.
Other way. Use the geometry of the level. bake the lighting into the vertices of the stage, and insert the geometry of the level into an accelerator structure so you can find fast the triangle where you are placed, interpolate the lighting from the 3 vertices, and it is another way.
Other way more, insert your lights into a structure for fast access, based on the location of the player, and pick the lights that could afect it. Trace rays to your player from each light, and all of those which don't colide with any part of the level, affect your player, then, sum their contributions.
From all these approaches, the least time consuming is the first one but requires a preprocessing, and your level must be static. While the second depends too much on the geometry of the level, and should also be static, and the third one is better to be left for physics engines, but can change dinamically with ease.
What do you think?
Other way. Use the geometry of the level. bake the lighting into the vertices of the stage, and insert the geometry of the level into an accelerator structure so you can find fast the triangle where you are placed, interpolate the lighting from the 3 vertices, and it is another way.
Other way more, insert your lights into a structure for fast access, based on the location of the player, and pick the lights that could afect it. Trace rays to your player from each light, and all of those which don't colide with any part of the level, affect your player, then, sum their contributions.
From all these approaches, the least time consuming is the first one but requires a preprocessing, and your level must be static. While the second depends too much on the geometry of the level, and should also be static, and the third one is better to be left for physics engines, but can change dinamically with ease.
What do you think?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: How to determine if node is illuminated
Thanks for responding Mel
About the first two, as you have mentioned, they require a static level and I have a dynamic light that moves about so they won't suit me.
The third option suits me quite well, and I thought it would be something along these lines but I wasn't sure.
While implementing it doesn't sound complicated or hard, I'm not sure about the performance of such a solution.
Even for a small amount of dynamic lights, I would need to spread vectors that would cover 360 degrees. For the sake of simplicity, I would ignore less shaded or more shaded areas and would only
focus on "lighted" areas or full shadow. Calculating such a thing for each iteration of game loop wouldn't be heavy?
About the first two, as you have mentioned, they require a static level and I have a dynamic light that moves about so they won't suit me.
The third option suits me quite well, and I thought it would be something along these lines but I wasn't sure.
While implementing it doesn't sound complicated or hard, I'm not sure about the performance of such a solution.
Even for a small amount of dynamic lights, I would need to spread vectors that would cover 360 degrees. For the sake of simplicity, I would ignore less shaded or more shaded areas and would only
focus on "lighted" areas or full shadow. Calculating such a thing for each iteration of game loop wouldn't be heavy?
Re: How to determine if node is illuminated
Spread vectors? can't you just use a single vector? from the light to your object. That's enough, and you may calculate the atenuation, and the collision with the level, if it was occluded, and if the object was outside of the light radius you can avoid the collision calculation, which is quite fast.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: How to determine if node is illuminated
If you have small lights, you can just ignore raytracing and treat is as just a 3d sphere-point intersection.
Is this point inside this sphere (light position + radius).
Is this point inside this sphere (light position + radius).
Re: How to determine if node is illuminated
Thanks guys, I have a clear view now of what I have to do.