Computing Lighting Normals per vertex.

Started by
15 comments, last by Grain 18 years, 11 months ago
How do I compute lighting normals at the vertex level so my procedurally generated objects look smooth? Currently I am computing them at the triangle level by using the three verts of the triangle and the cross product but this which makes the surface geometry very noticeable.
Advertisement
you have face(triangles) normals right? all you have to do is to cycle for every vertex, find the faces that share the current vertex and sum their normals.. something like this (pseudocode):

for(every vertex)
for(every face)
if(current_vertex is in current_face)
normal_array[current_vertex] += current_face->normal

and then normalize the result :)
If it is procedurally generated, why don't u generate the normals as well?
Quote:Original post by b3rs3rk
you have face(triangles) normals right? all you have to do is to cycle for every vertex, find the faces that share the current vertex and sum their normals.. something like this (pseudocode):

for(every vertex)
for(every face)
if(current_vertex is in current_face)
normal_array[current_vertex] += current_face->normal

and then normalize the result :)

Do the face normals have to be normalized first? If so that would be unacceptably slow. And does this method take into account the size of the face? Or should that not matter?

Quote:Original post by Cifko
If it is procedurally generated, why don't u generate the normals as well?


Well that's what I'm asking how to do.

Quote:Original post by Grain
Do the face normals have to be normalized first? If so that would be unacceptably slow. And does this method take into account the size of the face? Or should that not matter?


1)Yes, normalize face normals first.
2)Slow? do you need to compute normals during rendering !!??!? You have to compute the normals BEFORE you start to render anything.
3)The size of the face doesn't matter.

i just have a small interjection here. what about smoothing groups? if you wanted to add those how would you go about processing those?
Quote:Original post by b3rs3rk
2)Slow? do you need to compute normals during rendering !!??!? You have to compute the normals BEFORE you start to render anything.



My geometry isn’t static. It changes shape continuously. So it has to be done every frame.
Quote:Original post by b3rs3rk
Quote:Original post by Grain
Do the face normals have to be normalized first? If so that would be unacceptably slow. And does this method take into account the size of the face? Or should that not matter?


1)Yes, normalize face normals first.
2)Slow? do you need to compute normals during rendering !!??!? You have to compute the normals BEFORE you start to render anything.
3)The size of the face doesn't matter.


I had done this in my FEM application (Deformation Simulation) where vertex normal calculating in real-time was needed when my model deformed. It didn't show bad performance.

One thing you need to notice, averaging the facet normals of all the polygons that the vertex is in dose not work when there are edges that are to be preserved in your model, see this: http://www.xmission.com/~nate/smooth.html for help! But this time there's indeed a trade-off between performance and image quality :)

[Edited by - aKeye on May 18, 2005 7:35:16 AM]
You can find out moved faces of your model and just calculate normals for vertices in those faces. If at least one of three vertices of a face(triangle) moved, the face is moved.
How are you generating your vertices?

You said "procedurally", does that mean you have some geometric object you are tesselating, or do you have a base mesh and you simply morph the position of the vertices over time?

In the first case, when you sample the verticies of your geometry, you can sample the normal as well (just the derivative of whatever function defines your geometry).

If you're just starting with a base mesh and moving around the verticies, then recalcuating the normals is indeed a pain, but you could do it inside a vertex shader program. Simply pass in all of the neighboring connected verticies and do the normal computation. I'm not saying it would be trivial to write, but you'd deffinately see a performance boost!

This topic is closed to new replies.

Advertisement