Jump to content

Image of the Day

Everything is fine. 

#screenshotsaturday #indiedev #gamedev https://t.co/98BAKUInyo
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

Calculating outward pointing normals

4: Adsense

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.


  • You cannot reply to this topic
5 replies to this topic

#1 Darkbouncer4689   Members   

110
Like
0Likes
Like

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!

#2 japro   Members   

887
Like
1Likes
Like

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.

#3 Darkbouncer4689   Members   

110
Like
0Likes
Like

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

#4 ProfL   Members   

677
Like
2Likes
Like

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

#5 Darkbouncer4689   Members   

110
Like
0Likes
Like

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?

#6 ProfL   Members   

677
Like
0Likes
Like

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.