Jump to content
  • Advertisement
Sign in to follow this  
jamesleighe

Lighting for Dynamic Terrain

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have terrain that can change allot during gameplay and I was wondering how I could go about sun-lighting it? Normaly I could pre-bake in a lightmap but I don't know any fast way of simulating that realtime.

I mean, direct illumination with ambient light is fine, but I don't know how to quickly do 'terrain shadows'.

Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
You could use shadow mapping, which fits well in using the same shadow method for terrain and other models, but it depends on how much blurring you need. As for lightmaps, usually the whole terrain isn't dynamic at the same time, so recalculating a small part of the lightmap at a time when something changes might be OK.

Share this post


Link to post
Share on other sites
Cascaded ShadowMaps is probably what you want (I believe Crysis and GTA IV are using that too). Basic (variance) shadowMapping is not sufficient for long-range lighting, palmtrees for example will cast blocky shadows, or none at all. Unless you have low-end hardware, that should be very well possible, although it's quite difficult to get it working right.

ShadowMapping does not handle ambient light though. However, you can fake that pretty well with terrains. What you could do:
- use a small blurred cubemap texture (or just 6 colors) that represent incoming light from the horizon. Depending on the terrain-triangle normal, you sample from that texture (or mix the colors).
- Try to indicate how much surrounding triangles there are. The more, the less ambient light (sort of Ambient Occlusion). When deforming the terrain, you can calculate the surrounding obstacles within a (small circle). A local crater for example would have pretty much occlusion around it, resulting in less ambient light. You can store the occlusion factor as a simple value within the vertex data.

Rick

Share this post


Link to post
Share on other sites
You could try implementing this technique. It can be made to work on sub-regions of a heightmap, so that only the parts that change need be relit (although you do need to calculate a good "margin" to take into account the areas that might not change in height, but which will still change in lighting depending on the casting of shadows).

Share this post


Link to post
Share on other sites
I'm gona look into lightmapping, but I have a few questions.

* Since you have to render from the perspective of the light, won't that mean that each pixel will be ridiculously huge for large terrain?

I guess you could get around this by moving the light's effective rendering area to encompass only for the portion you can see but (other issues excluded) won't that mean the shadow edges will 'flicker' with the changing resolution of the shadow texture? Like if your just looking at a small patch of terrain the detail will be high, but if your looking over the edge of a mountain you will have super large pixels?

Thanks guys!

Share this post


Link to post
Share on other sites

* Since you have to render from the perspective of the light, won't that mean that each pixel will be ridiculously huge for large terrain?
Yeah, it's not necessarily a problem though, unless you want very sharp shadow borders.
I guess you could get around this by moving the light's effective rendering area to encompass only for the portion you can see but (other issues excluded) won't that mean the shadow edges will 'flicker' with
the changing resolution of the shadow texture? Like if your just looking at a small patch of terrain the detail will be high, but if your looking over the edge of a mountain you will have super large pixels?[/quote]Yep, resizing the area covered by the "light-camera" is a common way to get better use out of your shadow-map resolution.
Yes, this does cause jittering along shadow edges, which I personally find a very annoying artifact. However, you can completely avoid jittering with some care - you've got to make sure that when you move the light-frustum, you only move it by pixel-sized (shadow-map pixel) increments. i.e. you snap it to a grid, so it can only shift by the size of a whole pixel. This stops the jittering problem, as the projected shadow-map pixels always cover the same areas.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!