the easiest way, imo, is to have the light comming from either north, south, east or west. but never an angle in between,
then, you can loop through each row or column of vertices and track the height, each step lowering this.. if the vertex encounterd is higher than the tracking value, it's lit, and the tracking value gets set to that vertices height.
eg,
for (int y=0; y<terrain_height; y++){ float height=heightmap[y][0]; for (int x=0; x<terrain_width; x++) { if (height>=heightmap[y][x]) { height=heightmap[y][x]; lightmap[y][x]=normal[y][x].DOT(sunDirection); if (lightmap[y][x]<0) lightmap[y][x]=0; lightmap[y][x]+=ambient; if (lightmap[y][x]>1) lightmap[y][x]=1; } else lightmap[y][x]=ambient; }}
and bang, you have lit, shadowing terrain. (you may want to look into smoothing the transition from shadow to lit areas depending on the sky type your using (eg, cloud, harsh sun). And this will also help cut back on jaggy looking shadows.
This also assumes your using a lightmap of the same resolution as the heightmap. But if your not it's pretty trivial to fix.
this is especially nice since it's order n.
| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - | [edited by - RipTorn on January 17, 2003 7:44:32 AM]