Caculating Normals For Smooth Shading
Hi
Can someone please tell me how to calculate the normal for a point on a triangle from the three vertex normals to create a smooth shaded object(not flat shaded)?
I have the three vertex normals , the point on the triangle , the vertex coordinates and the plane normal.
Please help me.
Add all the normals for a particular vertex together (all the different normals that it has as a result of being part of more than 1 triangle), normalize and voila! You have the vertex''s normal.
- Weasalmongler
- Weasalmongler
I would assume you interpolate down the edges, and then interpolate between those values to the point between the edges. When I wrote my software engine that was the way I did it - each scanline of the rectangle has a start and finish normal, and each pixel in between has a value between those two.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
That''s what Phong shading does. I wonder how correct it is, though. If we had ''vertical'' scan lines, would it yield the same result? I doubt it...
Cédric
Cédric
cedricl, no matter if you use vertical or horizontal scan lines for filling if you interpolate the normals across the face to calculate the light you should get the same results. scanlines are the result of the 2d rasterization process. if you rotate the object by 90 degrees then its just like you were using vertical scanlines.
though the most correct way would be to interpolate the normal using a trilinear filter (or tricubic). you use the distance from the vertices as the weights just like with traditional bilinear filter, except now you have three values instead of 2. going down the edges then across is a nice optimization since you reduce the calculations since you have a LUT for the values and just do the interpolate across the face as a simple linear (or cubic) filter. same goes for the edge interpolations. so you are doing more interpolations instead of recalulating the weights by distance and then weighing the normals. you see, the scaline system is correct, heh.
in any case, the most correct answer is to just add the normals and normalize. since triangles that share vertices will contribute to the vertex color of all triangles attached it makes sense to use the normals of all trinagles that the vertex is attached to. remember vertices dont have normals, they are just there so that lighting can be calulated on a few points and then interpolated across the face. its also helpful that you can smooth the interpolation of the color by using the normals of all triangles being affected by the single vertex light calculation. since i doubt mavric is writing a software engine Kylotan''s info is a little more low level then needed.
though the most correct way would be to interpolate the normal using a trilinear filter (or tricubic). you use the distance from the vertices as the weights just like with traditional bilinear filter, except now you have three values instead of 2. going down the edges then across is a nice optimization since you reduce the calculations since you have a LUT for the values and just do the interpolate across the face as a simple linear (or cubic) filter. same goes for the edge interpolations. so you are doing more interpolations instead of recalulating the weights by distance and then weighing the normals. you see, the scaline system is correct, heh.
in any case, the most correct answer is to just add the normals and normalize. since triangles that share vertices will contribute to the vertex color of all triangles attached it makes sense to use the normals of all trinagles that the vertex is attached to. remember vertices dont have normals, they are just there so that lighting can be calulated on a few points and then interpolated across the face. its also helpful that you can smooth the interpolation of the color by using the normals of all triangles being affected by the single vertex light calculation. since i doubt mavric is writing a software engine Kylotan''s info is a little more low level then needed.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement