Original Post
My game engine is going to precompute lighting on a terrain, but I don't know a good algorithm to use. Right now I'm just making the sun a directional light and doing: I get some _really_ dark (ie black) areas of the terrain though, and it doesn't look very realistic. Is there a better lighting model I can use? Thanks!
for(int x=0; x < h->m_mapWidth; ++x)
{
for(int z=0; z < h->m_mapLength; ++z)
{
float innerProduct=lightpos.dot(h->m_normals[x+z*h->m_mapWidth]);
if(innerProduct < MIN_LIGHT_PERCENTAGE)
innerProduct=MIN_LIGHT_PERCENTAGE;
for(int pixelX=0; pixelX < pixelsPerVert; ++pixelX)
{
for(int pixelZ=0; pixelZ < pixelsPerVert; ++pixelZ)
{
tex[3*(x*pixelsPerVert+pixelX+((z*pixelsPerVert+pixelZ)*sizeX))]*=lightR*innerProduct;
tex[3*(x*pixelsPerVert+pixelX+((z*pixelsPerVert+pixelZ)*sizeX))+1]*=lightG*innerProduct;
tex[3*(x*pixelsPerVert+pixelX+((z*pixelsPerVert+pixelZ)*sizeX))+2]*=lightB*innerProduct;
}
}
}
}