Advertisement Jump to content
  • Advertisement
  • entries
  • comments
  • views

Generating Model Normals

Sign in to follow this  
Jason Z


The set of data that is available in my bunny.ply data is essentially just a list of vertices followed by a list of faces that index into the list of vertices. So, the first thing I needed to do to develop some of the effects that I want is to generate a set of per vertex normals for the model.

Although I have known how this is accomplished for a while, this was the first time that I have explicitly used the normal generation. The idea is to:

1) Find the two vectors that are formed between the first vertex and pointing to the other two vertices of each face.

2) Take the cross product of these two vectors after normalizing them.

3) This produces the FACE normal. I add this value to the vertex normal for each of the three vertices of this face.

4) Since most (if not all) vertices are shared by more than one face, adding multiple vectors results in a greater than unit length normal vector. But, the vector addition of all of the face normals produces a vector pointing in the average direction of the normals - so all I have to do is normalize the new vector.

And that's it, now I have a per vertex normal that is nice and smooth around the model. There are actually a couple of small gotchas when doing something like this though. You have to make sure that the winding of the polygons is correct with the way that you are viewing your models, other wise you will end up with a set of normals pointing to the inside of the model!!! It is surprisingly difficult to look at the results and just see that the normals are inside-out. The best way that I can think of is to generate a list of lines that start at each vertex's position and end at each vertex's position + the normal vector. Then render the model and line list. If you see the lines, they are pointing the right way, if you don't see the lines, the winding is probably different.

So, to show the results that I got for the bunny I wrote a quick effect file which simply outputs the world space normals as an RGB color. Here is how it turned out:

I am pretty happy with the results, it seems to show the subtle variations in the model surface. So now I can move on and start working on a couple more interesting rendering techniques...
Sign in to follow this  

1 Comment

Recommended Comments

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

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!