Advertisement

terrain lighmapping

Started by January 17, 2003 06:32 AM
3 comments, last by penetrator 22 years, 1 month ago
Suppose i have an array whick keeps the height elevation of a terrain. Starting from this, how can i create a lightmap to apply on the terrain ?
www.web-discovery.net

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]
Advertisement
Thanks RipTorn, gonna try it ! I want to thank you also for your hints about multidimensional arrays, they worked very well !



www.web-discovery.net

RipTorn, can you give me more details about

normal[y][x].DOT(sunDirection);

do you mean glNormal3f perhaps ?



www.web-discovery.net

the terrains normal dot producted with the direction to the sun.

This topic is closed to new replies.

Advertisement