OpenGL calculating normals for my terrain

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

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 on other sites
You need one normal per vertex.

Share on other sites
calculating a normal involves 3 vertices i thought...how do I end up with one normal per vertex?

thanks

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.

try this then

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 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 on other sites
The key to normals per triangle versus normals per vertex is this function call:

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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631774
• Total Posts
3002290
×