How to determine if node is illuminated

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

How to determine if node is illuminated

Post by Cleves »

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! :D
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: How to determine if node is illuminated

Post by Mel »

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?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Re: How to determine if node is illuminated

Post by Cleves »

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?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: How to determine if node is illuminated

Post by Mel »

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
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: How to determine if node is illuminated

Post by hendu »

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).
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Re: How to determine if node is illuminated

Post by Cleves »

Thanks guys, I have a clear view now of what I have to do.
Post Reply