Calculating outward pointing normals

Started by
4 comments, last by ProfL 12 years, 7 months ago
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!
Advertisement

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.
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 =)

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 :D)
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?

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.


This topic is closed to new replies.

Advertisement