DevMaster.net Forums
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

Go Back   DevMaster.net Forums > Site Discussions > Code & Snapshot Discussion
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Closed Thread
 
Thread Tools Search this Thread Display Modes
Old 07-28-2003, 03:15 PM   #1
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

Code:
// just reset the normals to an initial value of 0 for every vertex v in mesh { * *v.normal = 0,0,0 } // calculate each face normal and add it to the 3 edge-vertices for every face f in mesh { * *vertex& a = mesh.vertex_array[f.a] // refer to the 3 vertices of this face * *vertex& b = mesh.vertex_array[f.b] * *vertex& c = mesh.vertex_array[f.c] * *vector3 normal = calc_triangle_normal(a,b,c) * *a.normal += normal * *b.normal += normal * *c.normal += normal } // normalize the vertices to average for every vertex v in mesh { * *v.normal.normalize() }

By the way, as we don't normalize the normals on the summing part, bigger faces turn normals on their vertices more towards them.. this is accurate if you do it on paper (in 2d as best)..

there are suggestions to divide them by the squared length before summing to smoothen more towards the round parts.. while looking nice, too, and being based on some good idea actually, it is just slower.. thats why i never use anything else but that..


be warned that, if you have different vertices with same position, you get a hard edge there..
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline  
Old 07-29-2003, 11:55 PM   #2
DrunkenCoder
Member
 
Join Date: Jul 2003
Posts: 97
Talking

This is the method I use to took me some time to figoure it out (mostly because my teacher said it wouldn't work ).


Just make sure that calc_triangle_normal returns a unit normal (is that the correct terminology?) i.e. a normal with length 1.0
DrunkenCoder is offline  
Old 07-30-2003, 12:26 AM   #3
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

as i said above, that is NOT needed. and gives mathematically more correct result (good if you animate the mesh..)..

well.. i just thought about it again.. i'm not sure now anymore.. i'll paper it out today, i have time..
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline  
Old 07-30-2003, 12:58 AM   #4
DrunkenCoder
Member
 
Join Date: Jul 2003
Posts: 97
Talking

Quote:
Originally Posted by davepermen
as i said above, that is NOT needed. and gives mathematically more correct result (good if you animate the mesh..)..

well.. i just thought about it again.. i'm not sure now anymore.. i'll paper it out today, i have time..
Actually Im not quite sure that just being large should give you an added bonus at least for me I get the feel that the look is more correct when rescaling all normals to unit normals before summation.

The other method most people use is to first calculate normalized plane normals then add these and divide by the number of normals, normalizing the plane normals before summation here yields the exact same result with less book-keeping so I would call it more accurate.

But that's just my oppinion, could be wron... it's known to happen...
DrunkenCoder is offline  
Old 07-30-2003, 02:27 AM   #5
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

as i said, i'll go over the normalizing per face again to see how it affects visual impression..
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline  
Old 09-07-2004, 04:39 AM   #6
Mihail121
Senior Member
 
Mihail121's Avatar
 
Join Date: Jan 2003
Posts: 868
Default

You're right dave. One shoudn't!!! normalize triangle normals when calculating vertex ones. The results are really more correct that way.
Mihail121 is offline  
Old 09-07-2004, 07:35 AM   #7
z80
Member
 
Join Date: Sep 2004
Location: Copenhagen, Denmark
Posts: 99
Default

Does calc_triangle_normal() return a unit vector?

If it does, I fail to see how bigger faces turn normals on their vertices more towards them.

If not, then how is it implemented (probably (b-a)x(c-a) right)?
z80 is offline  
Old 09-07-2004, 08:14 AM   #8
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

no normalization, nope. just b-a x c-a, yes. (or the other way around? no this way around, what ever way around )
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline  
Old 09-07-2004, 08:34 AM   #9
Mihail121
Senior Member
 
Mihail121's Avatar
 
Join Date: Jan 2003
Posts: 868
Default

Actually when you calculating cross product the order does matter...
Mihail121 is offline  
Old 09-07-2004, 08:48 AM   #10
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

yeah, but in the end, we can just flip all the normals if they are to the wrong side. the rest doesn't mather, it doesn't change anything else of the calculation. thats what i ment.
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline  
Old 09-07-2004, 08:49 AM   #11
z80
Member
 
Join Date: Sep 2004
Location: Copenhagen, Denmark
Posts: 99
Default

So really the bending-towards-large-faces-feature is controlled by the two edges (randomly) selected for the normal calculation (b-a and c-a or whatever).

This could give some random results if for example a triangle face has two very long edges and one very short edge.
z80 is offline  
Old 09-08-2004, 08:01 AM   #12
z80
Member
 
Join Date: Sep 2004
Location: Copenhagen, Denmark
Posts: 99
Default

Quote:
Originally Posted by davepermen
to z80, nope, the cross product normal length is always related to the area of the triangle you calculate it on, it doesn't mather, on wich edges you evaluate it. works always.

but yes, the ones with bigger area result in longer normals => they affect a vertex normal more => they drift towards the long faces.. making them more flat, while small faces get more round shading (wich often makes sence).
[snapback]10883[/snapback]

Yeah ok, you're right of course! I've been unaware of that vector cross product property until now.
z80 is offline  
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump


All times are GMT -7. The time now is 01:35 AM.


Powered by vBulletin
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.