how best to recalc surface normals

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
damoos
Posts: 14
Joined: September 21st, 2019, 6:35 pm

how best to recalc surface normals

Post by damoos » November 27th, 2019, 10:36 pm

Is it common to apply the same rotations and translations to you surface normals as the vertices, or is it better to calculate new ones AFTER said transformations?

I currently do the latter, because I'm concerned that floating point rounding errors will, over time, cause the normals to no longer be perfectly perpendicular to the surface. I figure computing fresh normals from the transformed vertices is safer.

But maybe I'm imagining a problem that doesn't actually exist? I know it would be faster just to include the normals in the vertice transforms.

What say you?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: how best to recalc surface normals

Post by albinopapa » November 28th, 2019, 3:26 am

First off, you shouldn't be translating your normals, normals are just directions or vectors that are perpendicular to the surface plane. When you do the transformations, rotations, on your normals or even the complete transformation on the vertices themselves, you are starting from a fixed point and just transforming them to a new location/orientation.

In simplest terms, it's like:

Code: Select all

float f = 10.f;
for(int i = 0; i < 10; ++i)
{
     float result = f * float( i );
}
whereas something like:

Code: Select all

for(float f = 0.f; f < 100.f; f += 10.f )
{
     // use f
}
The first version, you are using the same starting point, so no accumulated errors occur. The second version, you move the starting point so accumulation errors occur. Normally, in transforming your vertices, you have the same starting point and the results of the transformations are stored in a separate buffer, so accumulation errors shouldn't occur.

Now, because of linear interpolation from one vertex to another, the normals may not be unit vectors, but that's caused from something other than rounding or accumulation errors.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

damoos
Posts: 14
Joined: September 21st, 2019, 6:35 pm

Re: how best to recalc surface normals

Post by damoos » November 28th, 2019, 4:46 am

Ok, actually I am already using your first example's method in my code (all transformations are done to the same start point), so yeah, it was silly to imagine accumulated error.

As for translation, don't I avoid that by having the normal's w component be zero?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: how best to recalc surface normals

Post by albinopapa » November 29th, 2019, 7:14 am

As for translation, don't I avoid that by having the normal's w component be zero?
You're correct, my mistake.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply