Jump to content
  • Advertisement

Archived

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

knealeaj

Help with lighting on my terrain

This topic is 5240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have written a simple terrain engine using a bitmap for the heightfield terrain. The terrain is fine but when it comes to the lighting the hills look blocky ,I think the polygon normals i am giving to glNormal3fv(I am using OpenGL) are wrong but i cant see where I have gone wrong. can you have a look .Here is the relevant code. Sorry for the mess #define TERRAIN_MAP_X 64 #define TERRAIN_MAP_Z 64 #define MAP_SCALE 20.0f float diffuseLight1[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float specularLight1[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float lightPosition1[] = { -550.0f, -250.0f, -150.0f, 1.0f }; float ambientLight1[]={ 1.0f, 1.0f, 1.0f, 1.0f }; void InitScene4(); void Scene4(); void GetFaceNormal(float *norm,float pointa[3],float pointb[3],float pointc[3]); void CrossProduct(float *c,float a[3],float b[3]); void Normalise(float *vect); float normals[5000][3];//normals for the faces of the terrain void InitTerrain() { terrainTex = new Texture; imageData = terrainTex->LoadBitmapFile("Terrain2.bmp",&bitmapInfoHeader); for(int z= 0;zLink

Share this post


Link to post
Share on other sites
Advertisement
try to calculate the normals with more neighbors, and promediate them:

normal[x,z]: normal[x-1,z], normal[x+1,z],normal[x+1,z],normal[x,z+1]

Share this post


Link to post
Share on other sites
Normal of plane if you know two non-paralell vectors in the plane:

vector1 x vector2. That is IF they are positively oriented. (Otherwise you get the negative normal)

So, basically, here is a method:


void GetFaceNormal(float *norm,float pointa[3],float pointb[3],float pointc[3])
{
norm[0] = (pointb[0] - pointa[0]) * (pointc[0] - pointa[0]);
norm[1] = (pointb[1] - pointa[1]) * (pointc[1] - pointa[1]);
norm[2] = (pointb[2] - pointa[2]) * (pointc[2] - pointa[2]);
}


That above can be done with a loop, but is quite unneccecary (and inefficent if this method is called 1000 times per frame).

That should calculate the plane's true normal.

Also, what jaba meant by promediating is this:


float norm[3][3]; // three different normals

float truenorm[3]; // True normal


for(int i = 0; i < 3; i++)
truenorm[i] = norm[0][i] + norm[1][i] + norm[2][i];


Or at least I THINK he meant that.

[edited by - biovenger on April 12, 2004 6:54:24 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by biovenger
Normal of plane if you know two non-paralell vectors in the plane:

vector1 x vector2. That is IF they are positively oriented. (Otherwise you get the negative normal)

So, basically, here is a method:


void GetFaceNormal(float *norm,float pointa[3],float pointb[3],float pointc[3])
{
norm[0] = (pointb[0] - pointa[0]) * (pointc[0] - pointa[0]);
norm[1] = (pointb[1] - pointa[1]) * (pointc[1] - pointa[1]);
norm[2] = (pointb[2] - pointa[2]) * (pointc[2] - pointa[2]);
}



Umm, but which point is pointa, which is pointb and which is pointc? Surely if you use the wrong ones then you'll get a funny normal vector?

a b
+-------+
|
|
|
+ c

would surely be different to

b c
+-------+
|
|
|
+ a

(I'm having problems doing this too...)

--
Never
My game

[edited by - Never on April 12, 2004 7:09:24 AM]

Share this post


Link to post
Share on other sites
That''s what I said, you must know if the points form two positively oriented vectors or not. You can only get two versions of the normal vector with respect to 3 points in a plane:
Either the normal, or the negative normal (-n).

Choose points wisely in the plane, such as the lower left, upper right and lower right would be good as a, b, c for a quad.

Also, in the examples you drew for me, you would get exactly the same normal in both. Except in the first example you would get the negative normal.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!