# What normal to use when triangles are in smoothing groups?

This topic is 2523 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,
I am currently in the process of building a 3D graphics engine in C#. My aim is to not use any 3D libraries that would provide support. For that reason I am using the standard GDI available through the .NET framework. Its come on a lot further than I imagined. I have done all triangle plotting by hand and it fully supports texturing and .OBJ wave front file import (bar the smoothing groups)

As you can see from the cylinder above there is some shading from a fixed point light source. I use the normal of each face with the vector of the light to the triangle to calculate the triangle intensity. I am using the Lambertian Reflectance model to calculate the correct light intensity of each face.

My draw triangle function works by specifying 3 things:

• 3 * 2D-screen coordinates
• 3 * texture UV coordinates
• 3 * intensity of a vertex of the triangle (in the above screenshot each vertex on any given triangle will have the same intensity)

My question is this: If a group of triangles are in a smoothing group how would I calculate the light intensity at each triangle vertex?
I think I may be missing something...

Thank you in advance for any help. Hope this is the correct place and what not

##### Share on other sites
You need to duplicate any vertices that are shared between smoothing groups; they will have different normals. So, for example, if 2 smoothing groups meet at a single edge, the vertices on that edge will need to be duplicated.

##### Share on other sites
I sort of see where you are coming from. I still don't understand how I could make the calculation. So if I had 2 triangles at right-angles joined along one edge (and part of the same smoothing group). what vector would I use for the intensity calculation at the joining vertex? Do I calculate some average of the 2 face normal vectors?

Thank you for the speedy reply

##### Share on other sites
Sorry; I think I misread your question. Within a smoothing group triangles can share vertices; the normal at each vertex is some function of the normal(s) of the face(s) to which that vertex belongs - averaging the face normals will work perfectly for this.

##### Share on other sites
I will have a go at implementing that and post my result back. This sounds like it could work. I will now have to cycle through each triangle in a given smoothing group to work out the averaged vertex normals. Thank you once again.

##### Share on other sites
For shared vertices, typically you calculate the triangle normals normal and weight them based on the angle of the wedge at the shared vertex, then normalize.

a 90 degree corner contributes twice as much of its triangle normal to the vertex than a 45 degree corner

This weighting breaks down if _edges_ can be used by more than two triangles (i.e. polygon fins sticking out of your mesh)

##### Share on other sites
Thanks for the reply
I have a rough idea of how all this works now. I was listening to something my lecturer said today about shading. For a standard sphere/cube(smoothed), you can take the vector from the mesh origin to the vertex (& normalize it). Could I use this on other shapes as a 'quicker' procedure for getting the vertex's. This would be really quick as all it is

(vertex - meshOrigin).normalise();

Or would this produce some weird results. The solution that I have at the moment takes way too long. I will give this a try

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 9
• 11
• 15
• 11
• 11
• ### Forum Statistics

• Total Topics
634149
• Total Posts
3015830
×