Jump to content
  • Advertisement
Sign in to follow this  
lazE

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.

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

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
Advertisement
calculating a normal involves 3 vertices i thought...how do I end up with one normal per vertex?


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
Sign in to follow this  

  • 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!