Search code examples
3dvisibilityshadowogre3dlight

Calculating how visible an object is in a 3D-scene for use in game logic/AI


I am starting a game project which will allow characters to hide in dark areas. Hiding in a dark corner should make it harder for other characters to see you.

What I need is a way to calculate how the lighting conditions are where the character is located.

The ideal would be to have a

double getLightFactor(GameCharacter observer, GameCharacter target)

since I suppose there could be lighting conditions where light falls so that different sides of the target is hit by different amounts of lights. But I would gladly settle for

double getLightFactor(GameCharacter target)

to get the light for a specific character regardless of where you are watching from or even

double getLightFactor(int x, int z)

to just get the light at a specific map point in the terrain.

The method need to take into account that lighting conditions may change during gameplay, but since it is turn based some heavy calculations could be allowed. I intend to make it possible to use flashlights so they need to be taken into account as well (but they could be modeled and handled separately).

I will be using Ogre3d to handle my scene, but I will happily accept generic solutions or even solutions for other engines (my choice of engine is not carved in stone).

Ideas, papers or really anything relevant is very welcome!


Solution

  • You could just render the scene from the viewpoint of the observer to an offscreen buffer (even in a rather low resolution) taking into account the current light settings. Then you could calculate a mean luminosity value around the middle of the target character.

    I do not know about the Ogre3d engine, but this should be a rather generic way to handle your problem (it's just rendering the scene from a different viewpoint after all...)