MakeDot3

BlitzMax Forums/BlitzMax Programming/MakeDot3

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

ISq2 is inverse square root of 2. It is used to give the diagonal pixels slightly less influence over the averages than the pixels that are directly touching the pixel we are working on. Without this, bumpmaps come out looking very pixelated.


First it samples all pixels around the center; top-left, top-middle, top-right, etc. MM is the center pixel itself. It will wrap around from the other side of the texture if you are on an edge.

Then it computes an average for the four pixels directly around the center...average left, average right, avg. top, avg. bottom.

The horizontal normal of the pixel is determined by comparing the average left and right pixels. If left=right the X normal is 0.0. If left-right=255 the horizontal normal is 1.0.

The vertical component is calculated the same way.

After the X and Z component are calculated, that leaves the Z component, which is calculated like this:

1.0 = Sqr( x*x + y*y + z*z )
1.0 = x*x + y*y + z*z
1.0 - ( x*x +y*y ) = z*z
Sqr( 1.0 - ( x*x +y*y ) ) = z

The results seem to always come out with a magnitude of 1.0, which is good.

ATI's tool seems to do some scaling for low-contrast images, and this just performs the math on the true pixels. If it is correct, then I think this is better because it lets you work on low-bumpiness textures and you can keep things more uniform.