calculating normals for my terrain

Started by
7 comments, last by Squirm 19 years, 4 months ago
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.
"We are what we repeatedly do. Excellence, therefore, is not an act, but a habit."-Aristotle
Advertisement
You need one normal per vertex.
This should help you.
You should never let your fears become the boundaries of your dreams.
calculating a normal involves 3 vertices i thought...how do I end up with one normal per vertex?


thanks
"We are what we repeatedly do. Excellence, therefore, is not an act, but a habit."-Aristotle
Did you even read the link I posted?
You should never let your fears become the boundaries of your dreams.
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.
"We are what we repeatedly do. Excellence, therefore, is not an act, but a habit."-Aristotle
try this then
[size="1"]
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!
"We are what we repeatedly do. Excellence, therefore, is not an act, but a habit."-Aristotle
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.
You should never let your fears become the boundaries of your dreams.
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.

This topic is closed to new replies.

Advertisement