# How do I go about lighting only polygons visible to the light?

This topic is 3045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

There is a maze game that I have been wanting to write for some time now. In it, the character walks around with a lantern. One of the enemies in the game can steal the lantern and run off with it. When this happens and the enemy turns a corner, I want the walls visible to the light (and only them) to be lit. How would I go about this? All geometric-based lighting schemes take the polygons that are visible to the viewer to calculate lighting. This, of course, will not work. Rather than doing complicated testing to see if the character has the lantern and then switching lighting modes if he does not, I would rather test the position of the light each frame and calculate lighting based on that. One method I thought of was to test the visible (to the viewer) polygon list to see which polys were also visible to the light, but that will not work since floor and ceiling polys are technically always visible to the light source. The levels will be generated dynamically (and potentially infinite), so I don't know if screen-space lighting techniques (i.e., light maps) will be viable. How would I go about this?

##### Share on other sites
I'm not sure what the difficulty here is. Standard diffuse lighting equations do not take the viewer's position into account, only the light's position. Combine it with any shadowing technique and a reasonable maximum radius of illumination and it'll look fine. You could improve performance with various culling techniques, but see if it's too slow without them first.

##### Share on other sites
Quote:
 Original post by SneftelI'm not sure what the difficulty here is. Standard diffuse lighting equations do not take the viewer's position into account, only the light's position.

I understand that, but they *do* take the position of the polygons visible to the viewer into account. As such, any and all polygons visible to the player will potentially be lit, even if the light source is no longer visible (due to occlusion by walls) to the viewer.

And to be clear, I haven't actually implemented anything as of yet. This is just a potential problem I see cropping up and one I want to address quickly. It doesn't help that my knowledge of lighting techniques is about 10 years out of date.

##### Share on other sites
You might check out something called portals to be able to keep track of what polygons your light can see.

What happens though when only part of a polygon is visible to your light?

Because of this i think what you really want is to check out one of these 2 things:

both of those guys are common techniques used to only light what should be lit from a light source.

HTH!

##### Share on other sites
Quote:
 Original post by Atrix256You might check out something called portals to be able to keep track of what polygons your light can see.What happens though when only part of a polygon is visible to your light?Because of this i think what you really want is to check out one of these 2 things:#1 - volumetric shadows#2 - shadow mapsboth of those guys are common techniques used to only light what should be lit from a light source.HTH!

Ah. Thanks for that. I'll look into those techniques. Actually, I've already decided on portals. Considering the dynamic nature of the levels, their potentially massive size and the regularity of a grid-based maze, they seem to be the only viable choice for visible surface detection and occlusion.

##### Share on other sites
If you go with portals what are you going to do about partial polygon visibility from a light source? Or is that not a problem for your situation?

(:

##### Share on other sites
Good question and I do not know...

##### Share on other sites
Do you think you could combine portals and volumetric shadows or light maps?

Maybe you could use portals to cull out un-necesary polygons (ones you know are not lit) to make the other algorithms more efficient?

##### Share on other sites
I'm really making this far harder than it needs to be.

The level(s) will be based on a standard grid-based maze algorithm. As such, there is occlusion information available at all times from the player and light position, assuming they are not the same. If the light is on the other side of a wall from the player, then it is in another cell. If this is the case, then the light simply cannot have an effect on the polygons in the cell containing the player. All that would be required is checking the type of cell that the light is in with the type of cells visible to the player. If there is a wall between the light source and a visible cell, then that entire cell is in shadow. In this case, lighting can simply be turned off while rendering that particular cell. Of course, there will always be a low level ambient lighting effect to prevent the level from going totally dark, but the light source can be safely ignored.

• 11
• 20
• 12
• 9
• 34
• ### Forum Statistics

• Total Topics
631399
• Total Posts
2999846
×