Skip to main content
GameDev.net gamedev.net
🔒 Locked

Normals...

Started by RegularKid Apr 8, 2002 at 5:40 PM 5 replies 700+ views
Original Post
RegularKid
RegularKid
Can anyone tell me how to calculate vertex normals or maybe give me a link to a tutorial that does. I know how to do polygon normals, but am kind of confused on how to calculate the normals for each vertex. Thanks.
IndirectX
IndirectX
You can calculate the normals for all polygons containing this vertex and average them.
---visit #directxdev on afternet <- not just for directx, despite the name
Vlion
Vlion
Coolness.
I have always kinda wondered about that.
~V'lionBugle4d
Cedric
Cedric
Well, a vertex does not have a mathematically defined normal, as far as I know. OpenGL and DirectX might use vertex normals to achieve lighting, but the vertex normal is often "tweaked" to achieve the desired effect. The method IndirectX described doesn''t find _the_ vertex normal; it''s just a way of finding a decent one. I guess the main drawback to this approach is that triangles aren''t weighted in his approach, but I don''t know how to weight them either.

Cédric
Matt Calabrese
Matt Calabrese
Yeah, mathematically, most of the vertices in 3D design on computers don't have normals because they are not differentiable at that point -- There is no tangent plane to the point because the plane of tangency would be different depending on which adjacent polygon you approach it from (unless they form a straight angle). Since there isn't such a plane in many of these cases (unless you had infinite vertices), there can't be a normal to the vertex. Standard is to average (weighted) the normals of adjacent planes, but an alternate method would be to come up with a formula which pseudo-defines your 3D figure. For instance -- say you have a sphere-like model: rather than averaging adjacent planes, it's actually easier to just calculate the normal on a mathematically exact sphere at that vertex. For a sphere this is simple because the normal is just the radius that extends to that point. All you have to do is choose the vertex you want to find a normal to, and the normal is just that point *minus a vector which defines the x,y, and z shift of the sphere.
Obviously, for most objects, it's not that easy to use a mathematic model for tangency, but in some cases, like the one above, it can be a lot faster because you can calculate the normal easily and not have to average all of the normals of the adjacent polygons, so complexity of the sphere makes absolutely no impact on the vertex's normal calculation. Analyze the situation and figure out which works best.

*EDIT: I accidentally wrote plus instead of minus

--------------------
Matthew Calabrese
Realtime 3D Orchestra:
Programmer, Composer,
and 3D Artist/Animator
"I can see the music..."

[edited by - Matt Calabrese on April 9, 2002 4:20:16 PM]
RegularKid
RegularKid
Great advice. Thanks.
Cone83
Cone83
Here is the source I use to calculate the normals. You need 3 points of you polygon (if your polygon lies on one plane which it has to be rendered correctly by OpenGL or Direct3D).

The points have to be in counter clockwise order.

HTH, Cone

void makeNormal(float *dst,float *a, float *b, float *c)
{
float ab[3], ac[3], len ;

ab[0] = b[0] - a[0] ; ab[1] = b[1] - a[1] ; ab[2] = b[2] - a[2] ;
ac[0] = c[0] - a[0] ; ac[1] = c[1] - a[1] ; ac[2] = c[2] - a[2] ;

dst[0] = ab[1] * ac[2] - ab[2] * ac[1] ;
dst[1] = ab[2] * ac[0] - ab[0] * ac[2] ;
dst[2] = ab[0] * ac[1] - ab[1] * ac[0] ;

len = (float) sqrt ( (double)( dst[0]*dst[0] +
dst[1]*dst[1] +
dst[2]*dst[2] ) ) ;

dst[0] /= len ;
dst[1] /= len ;
dst[2] /= len ;
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.