normals

Started by
1 comment, last by Wilhelm van Huyssteen 15 years, 4 months ago
hey. ive been working on my 3d engine for a while now and it has all the basics (scene graphing, billboarding, its own internal file formats, and a fixed timestep with the display and the game logick runing on separate threads) and ive created some test applications with it including a 3d chess game. Now i want to move on to implementing shaders but before that i guess i have to get lighting to work.. now ive googled up on normals a bit but im strugling to get ahold of something that can realy tell me what i need to do, i understand that i need to load the normals into my VBO's along with my texture coords, vertexes, colours and whatever else but how do actualy calculate the normals? and also whats the difference between vertex normals and surface normals?
Advertisement
Each vertex is going to have a normal.
A "surface normal" means that all 3 verts on a triangle have the same normal, the normal of the surface.
A "vertex normal" means that the normal on a vertex is the average of the normals of all triangles that that vertex is part of.

Imagine a pyramid. Surface normals point out from each flat surface on the pyramid. Vertex normals point straight out of each point on pyramid in the direction of that point.

Calculating a surface normal is as easy as taking the cross product of any two edges on that triangle, BUT order maters, so take a stance that counter-clockwise is "out" and clockwise is "in", and calculate all your triangles the same. (but be careful if you are drawing triangle strips, as the winding order changes every-other triangle.

B-D
|\|
A-C

(A-B)cross(C-B) and (B-C)cross(D-C) are your two surface normals.
Also remember to "normalize" your normals.
thnx that clears is out for me. fortenetley for me my engine is simple and just duplicates vertexes instead of using the same vertex for 2 triangles so i dont have to worry about different vertex normals on the same surface and also i dont use triangle strips i just draw my triangles with glDrawArray

thnx for the help

This topic is closed to new replies.

Advertisement