• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Calculating outward pointing normals

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Darkbouncer4689  Members

Posted 03 September 2011 - 02:37 AM

Just a quick question here.

If I calculate my normals with something like

Vector3 p1 = vertices[indices[i+0]];
Vector3 p2 = vertices[indices[i+1]];
Vector3 p3 = vertices[indices[i+2]];

Vector3 v1 = p2 - p1;
Vector3 v2 = p3 - p1;
Vector3 normal = v1.Cross( v2 );

Will the normal vector be guaranteed to be pointing outward and not inward?

I must admit I normally just plug and chug the normals from 3d files, but for terrain I need to calculate my own normals =)

Thanks for the help!

### #2japro  Members

Posted 03 September 2011 - 02:43 AM

Will the normal vector be guaranteed to be pointing outward and not inward?

I must admit I normally just plug and chug the normals from 3d files, but for terrain I need to calculate my own normals =)

There isn't really a "outward" direction for a single triangle... if you swap any two vertices the the direction of what is the cross product changes its sign. You have to ensure that all the triangles are "wound" the same way when you pass them to the normal calculation.

### #3Darkbouncer4689  Members

Posted 05 September 2011 - 12:50 AM

I think I understand how it's done now. If all of the triangles are CW or CCW the outward pointing normals can be calculated correctly.

My terrain is rendered using triangle_strips, which changes the ordering of the triangles for each row. So I think in order to calculate my normals I need to swap the way I calculate the normals each time I change rows (which changes CW/CCW ordering).

I intended to optimize my index buffer for gpu cache coherency in the future. I suppose I should look into that before I hard code how my normals are calculated. Any tips on that are appreciated =)

### #4ProfL  Members

Posted 05 September 2011 - 03:21 AM

I think I understand how it's done now. If all of the triangles are CW or CCW the outward pointing normals can be calculated correctly.

My terrain is rendered using triangle_strips, which changes the ordering of the triangles for each row. So I think in order to calculate my normals I need to swap the way I calculate the normals each time I change rows (which changes CW/CCW ordering).

I intended to optimize my index buffer for gpu cache coherency in the future. I suppose I should look into that before I hard code how my normals are calculated. Any tips on that are appreciated =)

keeping the order is especially important to have backface culling running, this saves you 50% of the rasterized pixel, low hanging fruit everyone should use (except on PS2 )

### #5Darkbouncer4689  Members

Posted 05 September 2011 - 02:30 PM

Thanks for the tip. I know about backface culling but I have never designed a mesh to take advantage of it. Should I not be using triangle_Strips for terrain?

### #6ProfL  Members

Posted 06 September 2011 - 08:08 AM

Thanks for the tip. I know about backface culling but I have never designed a mesh to take advantage of it. Should I not be using triangle_Strips for terrain?

backface culling works with triangle strips without a problem, for your normal calculation you just need to flip it every second triangles, if you use the raw strip indices.

enable backface culling, you'll see if something has a wrong orientation. if everything looks fine, then yournormal calculation code shall work.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.