Archived

This topic is now archived and is closed to further replies.

TriloByte

Terrain Lightning

Recommended Posts

I hate to break it to you but it is nothing but math!

here is a function that will create a color value based on height...

 
//this funtion was quite FUN!!!...it takes the min and max z's of any map

//and displays the color values red(max) to purple(min)...It was quite difficult

//to figure out the math to make sure any map's (with any z range) RGB values

//are assigned 255 for max z's and 0 for min z's...but it works...check the math!

void SetVetexColor3ub(float max_z, float min_z)
{
//interval: the difference between 255 and 204 is 51 intervals

//over that 51 intervals we would like to go from 0 to 128, or

//128 to 255, etc...so 128/51 is 2.51 changes to the color value

//to each of the 51 intervals

//float interval = 128.0/51.0;

if(max_z>255) max_z=255; //get rid of

int span = (max_z-min_z)/5.0; //this is the span between each "if statement"

float interval = 128.0/span; //this is the amount of the color to change for

//each interval within a span

int pad_max = 255-max_z; //this makes up for low max...for example if max is

//224...we need this value (31) to bring it up to 255


float z;

//changed as a prerendering calculation function

for(int i = 0; i < num_squares; i++)
{
for(int j = 0; j<4; j++)
{
z = -(poly[i].vertex[j].z);
if(z>255) z=255; //make sure z is not larger than 255

if(z<=max_z)
{
poly[i].vertex[j].color.red = (max_z-((max_z-z)*interval))+pad_max; //OK

poly[i].vertex[j].color.green = (max_z-z)*interval; //OK

poly[i].vertex[j].color.blue = 0;
if(z<=(max_z-(span*1)))
{
poly[i].vertex[j].color.red = (max_z-((max_z-z)*interval))+pad_max; //OK

poly[i].vertex[j].color.green = (max_z-z)*interval; //OK

poly[i].vertex[j].color.blue = 0;
if(z<=(max_z-(span*2)))
{
poly[i].vertex[j].color.red = 0;
poly[i].vertex[j].color.green = (((max_z+pad_max)*2)-((max_z-z)*interval)); //OK

poly[i].vertex[j].color.blue = ((max_z-(span*2))-z)*interval; //OK

if(z<=(max_z-(span*3)))
{
poly[i].vertex[j].color.red = 0;
poly[i].vertex[j].color.green = ((max_z+pad_max)*2)-((max_z-z)*interval); //OK

poly[i].vertex[j].color.blue = ((max_z-(span*2))-z)*interval; //OK

if(z<=(max_z-(span*4)))
{
poly[i].vertex[j].color.red = ((max_z-(span*4))-z)*interval; //OK

poly[i].vertex[j].color.green = 0;
poly[i].vertex[j].color.blue = ((max_z+pad_max)*2)-(((max_z-(span*2))-z)*interval);
}
}
}
}
}
}
}
}


of course this is not optimized and it is only a quick and dirty way to do it!


www.lanceusa.com

[edited by - dnagcat on July 6, 2003 1:58:26 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by dnagcat
I hate to break it to you but it is nothing but math!



Whats your point? Are you telling me that you somehow are able to implement an algorithm you know nothing about ( without simply cut and pasting code, something which I disagree with )? Graphics programming is maths, get used to it.

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
Guys I know the math else this post wouldn't be in the openGL section. The only thing I want to know: is it fast? and does it look good? btw I'm using geo-mipmapping.


[edited by - trilobyte on July 6, 2003 4:29:42 PM]

Share this post


Link to post
Share on other sites
Lmao, I think i''m the only one that gets what you''re saying. You can calculate lighting.. but you''re just wondering the best way to apply it to the terrain, right? I''ve used vertex lighting in my engine.. but it looks like crap, hehe. With the amount of subdivisions i have in my terrain, the smoothness just isn''t there. I haven''t implemented lightmapping yet, but it i know it''d be just as easy to do, and i''d have the ability to add so much more shadow detail. The one effect i love is calculating lighting values based on a higher resolution version of the terrain than the one that is being displayed (I noticed it in ace combat 4). This would be impossible with vertex lighting. Plus, you can scale the quality of the lightmaps for computers that don''t have the capability for the high resolution (and memory requirements) texture.



Disclaimer: "I am in no way qualified to present advice on any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)"

Share this post


Link to post
Share on other sites
Ah yes, sorry about that Mr. Cat, I was at work so never spent much time reading over your post.

Mr. Byte : Your post asked for better methods, there are far better methods on vterrain.

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
quote:
Original post by TriloByte
I was thinking about using different color values, I can compute them in build time, and then but them in a Color array.

Is this a good method or are there better methods?


there are definitely better methods. if you use lod it will produce horrible results, because changing the lod will not just result in the geometry "popping", but if you do anything on a per vertex base the left out vertices will completely change the appearance. colors will look different, lighting changes and if you use vertex colors as texture blending weights the resulting texture will look completely different.

id definitely go with lightmaps or normalmaps and perpixel lighting.

Share this post


Link to post
Share on other sites