Vertex Normals [Somewhat SOLVED]

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Vertex Normals [Somewhat SOLVED]

Post by Benjamin100 »

What is the best way to calculate vertex normals?
I need them to pass to the vertex shader for lighting calculation. I have an idea of what to do, but it seems extremely long; taking 3 points at a time for the array of coordinates (9 values total), breaking them into vertices, calculating the face normals, and then averaging for the vertex normals. Is there an simpler way to find vertex normals?

Thanks
Last edited by Benjamin100 on Fri Jan 03, 2014 4:09 pm, edited 2 times in total.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: Vertex Normals

Post by qpHalcy0n »

No, there isn't really an easier way. You have to sum the connected face normals up for every face the vertex shares. That said, you should only have to do this one time.
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Vertex Normals

Post by K-Bal »

I don't know what your situation is so this might not help you, but if you're creating models with 3D modelling software you can usually export the model file with vertex normals included.
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Vertex Normals

Post by Benjamin100 »

Thanks guys.

Still not sure how 3d files are set up.
Apparently I can write a script that saves the information however I want to. I'm just not sure how that works.
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Vertex Normals

Post by Benjamin100 »

I'm trying to read these Wavefront 3d files. I'm not sure how to find the vertex Normals. I think I see the vertices, and I see some other file that appears to be related. Are those the normals? It looks like a completely different file. Not sure if you use these file types.
EDIT: Just found out I was missing a little box in Blender for "Include Normals."
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Vertex Normals [Somewhat SOLVED]

Post by Benjamin100 »

OK, just one more thing...
Do most of you use a particular library for reading the Wavefront files? I'm having trouble figuring out how to parse this file. Perhaps it would be easier if I knew how to create my own type of file where I would have it split up by lines. It just gets messy trying to create a function to read the vertices. First I have to find out where the vertices start, then I have to separate them by the Vs, then I have to separate them which differs in size according to whether there is a negative sign or not. It is really a pain. Should I just stick with it? I'd rather focus on the lighting and other issues than parsing these frustrating files/ I'd like it if there was a library available to take a file and return the vertices or vertex normals. Maybe this is something I should do myself just for the experience.

What do you recommend?
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Vertex Normals [Somewhat SOLVED]

Post by Benjamin100 »

It appears this wasn't as difficult as a I thought. I was unaware of these scanning format functions.
But I don't understand the format strings. What do the strange characters in the format strings represent?
Post Reply