Sign in to follow this  
lazE

OpenGL calculating normals for my terrain

Recommended Posts

hey, i have a few questions about calculating normals for my terrain... the terrain is a heightmap of equal width and height (512x512 in this case). that gives give me 512 ^ 2 vertices and times 6 as many indices. im rendering it using vertex buffers. i do one strip at a time going down the whole terrain. i want to give opengl a pointer to the normal array. the first question is, how many normals will i have? it should be equal to the number of triangles so that should be the number of indices - 2 for a strip, right? also, assuming thats right, do i just make an array with the normals in sequential order and opengl will be able to internally figure out which one to use? thanks.

Share this post


Link to post
Share on other sites
I did, actually.

It looked like a lot of code which is great but I am still having trouble with the basics. I'm still at the point where I'm not sure how many normals I need so looking at a post that talks about how to optimize the number of mults and adds isn't as useful as someone telling me if I am right or wrong about what what I said.


Thanks.

Share this post


Link to post
Share on other sites
Thanks.

One point of clarification about the article (not sure if this is what it said) if you don't mind -- for vertices that are shared between faces (pretty much all of them in a terrain) I should sum up the normals calculated for that vertex and then make it unit length to achieve the best effect?


Thanks again!

Share this post


Link to post
Share on other sites
Quote:
Original post by lazE
for vertices that are shared between faces (pretty much all of them in a terrain) I should sum up the normals calculated for that vertex and then make it unit length to achieve the best effect?

Yes. Thats the idea. It's the same for all normals. When it comes to rendering you can forget about face normals in most cases. It's only about vertex normals.
The link I posted uses different, terrain specific, way for computing normals. It dosen't use triangles or anything. I find it simpler to understand... And sorry if I was being rude before.

Share this post


Link to post
Share on other sites
The key to normals per triangle versus normals per vertex is this function call:

glShadeModel(GL_SMOOTH);

With GL_SMOOTH you get lighting calculated at each vertex with the vertex normal and the colour evenly shaded accross the triangle. With GL_FLAT it will ignore your normals completely and shade according to the normal to the triangle.

GL_FLAT is the default, and results in a crystaline appearance, with sharp angles and facets.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this