Sign in to follow this  

Normals Calculations [Pics]

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to code a filter into my Mesh Loading functions, that detects when a resource was loaded, but has no Normals. If such a case occurs, this filter is responsable for generating those normals. Here is an example, with a teapot, the original: The Original Teapot Normals And this is my version, with an algorithm to calculate the normals: The Calculated Teapot Normals Something is obviously happening in the calculations that is skewing the normal vectors onto the Y Axis, for some reason... This is how I calculate the cross product, im afraid something may be wrong with it: res.x = (v1.y * v2.z) - (v1.z * v2.y); res.y = (v1.z * v2.x) - (v1.z * v2.z); res.z = (v1.x * v2.y) - (v1.y * v2.z); The pseudo-algorithm i use to calculate the normals is: + Calculate face normals for all faces + Create (Vn) vector, that will hold current vertice's normal + For all (V) Vertices, for all (F) Faces, if F uses V, then add F's normal to Vn + Normalize Vn. It now holds the normal for that vertice. So... what could I be doing wrong here?

Share this post


Link to post
Share on other sites
res.x = (v1.y * v2.z) - (v1.z * v2.y);
res.y = (v1.z * v2.x) - (v1.z * v2.z);
res.z = (v1.x * v2.y) - (v1.y * v2.z);

should be:

res.x = (v1.y * v2.z) - (v1.z * v2.y);
res.y = (v1.z * v2.x) - (v1.x * v2.z); <-- changed
res.z = (v1.x * v2.y) - (v1.y * v2.x); <-- changed

Share this post


Link to post
Share on other sites
Thank you for the quick reply rick_appleton.

I've changed the code, after reading your post, and doing some deep digging on some math books.

None the less the visual result remais the same, the vertex normals still point upwards...

Share this post


Link to post
Share on other sites
Could you post the code where you loop through everything and calculate the normals?

It looks like the algorithm starts at the top, where the normals are calculated correctly, and then goes down to the bottom withouth clearing the results for each vertex. Therefore the previous normal (point up) keeps on getting used along with the correct normals.

Share this post


Link to post
Share on other sites
Thank you rick_appleton. I was able to track down the bug in my algorithm.


In the above image you can see a teapot exported from 3D Studio Max.

It is being rendered with a shader that visually shows us the normals on the model. A visible "seam" runs across the handle area.

On the lower area of the image you have the same model, but with normals generated by the algorithm. No seams are visible [wink]

Rate+ Rick_appleton

Share this post


Link to post
Share on other sites
Nothing big... in fact it was so small it was well hidden.
I was just making a mistake when normalising the normal, which gave the "y" axis more "weight" than it should have...

Traced the error using a plane mesh, hahaha.

The normals calculations takes a good deal of time, but its all dumped to file afterwards anyways, so...

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this