Improving terrain lighting (pics!)

Started by
15 comments, last by OrangyTang 19 years, 7 months ago
You probably don't remember my earlier ponderings over terrain lighting, but I just recently tried an improvised form of horizon mapping and have very nice results for shadowing. :) Now I'm wondering what other factors people think is important for outdoor-style rendering. I know how people love pics to accompany peoples testing, so: Not very detailed as terrain goes I know, but this horizon mapping lets me move the light source along a pre-defined arc which is perfect for a sun. So far its just regular per-pixel diffuse * shadow intensity. Obviously the first improvement that springs to mind is some form of specular, but I think that might be unsuitable for 'soft' surfaces (grass, sand) that you typically find in such a scene. Having said that, perhaps rock or snow type surfaces would benifit from good specular, maybe some form of gloss map in my diffuse textures' (currently unused) alpha component. Suggestions muchly appreciated. :)
Advertisement
the shadows almost seem too dark to me. They almost look like cloud cover shadows. Unless the light is farily close the horizon ... they just seem darker then they should be.


The blending is nice though and the edges look smooth. How does it look as you move the light?

Yeah, I've added ambient light to the fragment shader now which stops it looking pitch black in the shadows. At the moment all my lighting is just a single (white) colour, I'm thinking that it should vary depending on the angle of the sun, such as shifting the ambient towards blue at nighttime.

Moving the light source is where it really starts to look good, you can watch the shadows from the hills slowly form and stretch as the sun gets lower. [grin]
So give us some details :p

Is it precomputed for each vertex, or is it done quickly when the sun moves?

Waramp.Before you insult a man, walk a mile in his shoes.That way, when you do insult him, you'll be a mile away, and you'll have his shoes.
Basically a big texture (same resolution as the vertex data) stored horizon angles at each terrain tile (in a texture's r channel, the rest are unused). Unlike regular horizon mapping I only store the horizon in one direction, which means theres not much memory cost.

A fragment shader looks up the (interpolated) horizon angle, then compares it with the global sun angle. If the sun is below the horizon then we're in shadow, else we're being lit. Chuck in a smoothstep useage for a little softness rather than a harsh on/off. By switching between an texture for east horizons and a texture for west horizons you can make the sun travel in a complete arc over the landscape. After the initial precalculating of the horizon values you can move the sun anywhere on this arc and you just let the fragment shader work out the light intensity.
now you make me think about wild methods like storing a texture with values like
r: time of begin shadowing
g: time of max shadowing
b: time of end shadowing
a: darkness of shadowing

where you just do shadowing depending on daytime and maybe abuse value clamping to further your goals and replace if instructions. hmmm.. nah, sounds like too much work just for shadows.
f@dzhttp://festini.device-zero.de
Quote:Original post by Trienco
now you make me think about wild methods like storing a texture with values like
r: time of begin shadowing
g: time of max shadowing
b: time of end shadowing
a: darkness of shadowing

where you just do shadowing depending on daytime and maybe abuse value clamping to further your goals and replace if instructions. hmmm.. nah, sounds like too much work just for shadows.
I think, ideally, you'd want any such technique to only use three values, instead of four - allowing you to pack into into an ARGB texture along with the heightmap value at that point.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

considering that there really is no limit to the amount of times a vertex can pop in and out of shadow, a more flexible datastructure might be more suitable. and probably a lot less efficient.
OrangyTang, can you try doing the terrain lighting using per-vertex lighting and using your form of horizon mapping and post the FPS results? I wonder - I use per-vertex lighting on my terrain. Because usally terrains are well-tesselated, it looks good as well. Your method looks better, true, however per-vertex lighting on the terrain also create soft shadows. I wonder if horizon mapping is a lot faster(or slower) than per-vertex lighting on the same terrain.

- Etus
In general pixel lighting is ofthen the best choice for terrains.

This does not mean that vertex lighting cant be used for anything, but with most LOD schemes it has the disadvantage that vertex lighting significantly increases the visibility of LOD changes. For instance approaching a mountainside with pixellighting you could maintaing a wery rought tesselation for a long time because the actual geometry is not visible, only the shadows, if it was vertex lit these would change a lot when the tesselation was changed.

The horizonmap lighting looks good, but to see it in full effect you would really need an animation ;)
There is a paper written on terrain lighting a while ago, which included some really cool effects including interreflections from surrounding terrain. That would be really cool.

In adition I think that outdoor scenes benefit enourmously from high dynamic range lighting and areal perspective.

This topic is closed to new replies.

Advertisement