Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Here is a picture of a lovely polygon:

Box of awesome

Circled is a vertex, and numbered are its adjacent faces. I have calculated the normals of those faces as such (not yet normalized, 0-indexed):

Vertex 1 normal 0:   0.000000   0.000000    -0.250000
Vertex 1 normal 1:   0.000000   0.000000    -0.250000
Vertex 1 normal 2:  -0.250000   0.000000     0.000000
Vertex 1 normal 3:  -0.250000   0.000000     0.000000
Vertex 1 normal 4:   0.250000   0.000000     0.000000

What I'm wondering is, how can I determine, taken as given that I want this vertex to represent a hard edge, whether its normal should be the normal of 1/2 or 3/4? My plan after I glanced at the sketch I used to put this together was "Ha! I'll just use whichever two faces have the same normal!" and now I see that there are two sets of two faces for which this is true.

Is there a rule I can apply based on the face winding, angle of the adjacent edges, moon phase, coin flip, to consistently choose a normal direction for this box?

For the record, all of the other polygons I plan to use will have their normals dictated in Maya, but after encountering this problem, it made me really curious.

share|improve this question

1 Answer 1

up vote 10 down vote accepted

You'll need to duplicate the normal for the corner N times (where N is the number of "sides" it is shared amongst). If you try to use one value for all "sides," you'll end up averaging it, and your lighting will not appear to have that hard edge that you're looking for.

share|improve this answer
    
So presuming I was using OpenGL indexed vertices, because I am, you're saying I couldn't use this vertex for all five of these triangles, I'd have to duplicate it for 1/2, 3/4, and 5? –  K.G. Mar 23 '12 at 3:11
    
You can use the same vertex for all 5 triangles it touches; you'll just use the same index to point to it where appropriate. Since the 5 triangles in question need 3 different normals, you'll have to have 3 different normals and use the correct indices for them. However, the vertices involved with triangles 1 and 2 all share the same normal. In fact, for your rectangular prism, you'll only need 6 different normals. –  stephelton Mar 23 '12 at 3:15
    
Woah! I don't know why, but having multiple normals per vertex hadn't even occurred to me. Thanks! –  K.G. Mar 23 '12 at 3:24
    
Glad to help! Hint: you probably need 8 vertices and 6 normals. And probably 4, 8, or 24 tex coords... –  stephelton Mar 23 '12 at 3:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.