Vertex Normals

Started by
12 comments, last by AbeE 22 years, 9 months ago
I was wondering how I should approach this. I know what they are but not how to implement them. I have an array with all the vertices of my triangle strips, and have calculated the normals for each face (well, I made a normal for each set of 2 triangle strips, treating them more like a quad). Should I just run through this array checking for vertices that are equal for what. I just can''t think of specific code to accomplish this.
Advertisement
Hey there, to get a vertex normal, you add the normals of all the faces that use that vertex, then normalize the result. I think you''ll find each vertex has 3 different faces whose normals need to be added and then normalised.

I may post some code later,

FatalXC
I dunno if this works or not, because the 'land' in my game so far is flat, maybe some1 could tell me if this makes sense:

All my vertices are stored like this (bad I know but I'm a beginner)

numstrips_x[polynum][3];
numstrips_y[polynum][3];
numstrips_z[polynum][3];

Where polynum is the polygon number and the '3' represents 3 x,y,z coordinates for each polygon. I have already generated the face normals and transfered these face normals to each vertex on that face and stored this normal in
Norm_Vertex[Polynum][3]; '3' representing this time the normal at each of the 3 points on the polygon.

The following code I ain't sure about, basically what its MEANT to do is search for any points that are the same (therefore the normals at that point should added - normalised later)

for(int u=0; u < TotalPolygonNumber ; u++) //Loop through all polygons
{
for(int y=0; y < TotalPolygonNumber ; y++)
{
if( (((numstrips_x[0] == numstrips_x[y][0]) && (numstrips_y[0] == numstrips_y[y][0])) && (numstrips_z[0] == numstrips_z[y][0])) )<br> {<br> Norm_Vertex[0] += Norm_Vertex[y][0];<br> }<br><br> if( (((numstrips_x[1] == numstrips_x[y][1]) && (numstrips_y[1] == numstrips_y[y][1])) && (numstrips_z[1] == numstrips_z[y][1])) )<br> {<br> Norm_Vertex[1] += Norm_Vertex[y][1];<br> }<br><br> if( (((numstrips_x[2] == numstrips_x[y][2]) && (numstrips_y[2] == numstrips_y[y][2])) && (numstrips_z[2] == numstrips_z[y][2])) )<br> {<br> Norm_Vertex[2] += Norm_Vertex[y][2];<br> }<br><br> }<br> }<br><br>After this I just normalize the normals and assign them to their vertex? Sorry for being long winded' and complex.<br><br>Edited by - AbeE on June 26, 2001 10:55:48 AM
How are you calculating your vertices from the faces? Are you using 3-plane intersection? If you are then vertex normals are easy. Just add the normals of the faces that intersect at the vertex then normalise the result.

You really should change your data formats to something nicer. Have a cVector class with all your vector operations, and a cFace class and a cPlane class etc... It will make everything so much easier. You could have my base classes if you want, they are a good starting platform.

If you need more explanation or if I''ve screwed something up, its no problem.

FatalXC
Thanks, that''d be a great help, but I''ve got one minor problem left. I have gotten some type of lighting going, I think its per Vertex, it looks decent enough anyways I think for a first attempt. In fact I''ve gotten the whole terrain done and I''d love you to try it on your system some-time and tell me what kinda frame-rate you get. But before I show anyone I have 1 more question:
At certain areas on my terrain the frame-rate is alot higher than on others, and because of this the movement of the ''camera'' occurs quicker in some areas than others (it all depends on where you look!). Is there anyway I can fix this using the timer of something???
That''d be a great help
Thanks again.
OK, frame rate fluctuations are normally due to overdraw. Doing frustrum culling will help, definitely have back face culling on (especially for a terrain engine!!) and implement a QuadTree for relatively flat terrain, else use an Octree. I''m not sure but maybe using an SBuffer would be good, there are some articles on www.flipcode.com. Alpha blending can also slow rendering down a lot, so don''t complain if thats whats causing it!! I hope I haven''t confused you more!!

I''ll send you my cVector, cVertex, cPlane, cCamera, cTiming, cPolygon classes and anything else i think might be useful!! They work pretty well and are not frame rate linked. What address should I use?

I''d love to see what you''ve made, my address is standingintheshadows@hotmail.com. I have an Athlon 800 and a GeForce 256 DDR.

Cheers,

FatalXC
Sure, I''ll send it to you hopefully tomorrow, I just have a couple of things to do to it first.
See ya
Hey FatalXC:
Could I give u the address of my website to download it off? It would save me emailing it on my crappy modem.
Yeah sure, no problem

FatalXC
But wouldn''t you still have to upload it....?

This topic is closed to new replies.

Advertisement