Re: HeightMap to NormalMap

Maybe you can quickly find-out if simply sampling more and doing some filtering would be nicer:

GIMP:

http://nifelheim.dyndns.org/~cocidius/normalmap/

Photoshop:

http://developer.nvidia.com/object/p...s_plugins.html

Re: HeightMap to NormalMap

Some nice sync here! I am trying to solve the same (or a very similar) issue.

In my experience, running a 3x3 sobel filter yields better results:

Code :

Vector3 CalculateNormal(int u, int v)
{
// Value from trial & error.
// Seems to work fine for the scales we are dealing with.
float strength = scale.Y / 16;
float tl = Math.Abs(this[u - 1, v - 1]);
float l = Math.Abs(this[u - 1, v]);
float bl = Math.Abs(this[u - 1, v + 1]);
float b = Math.Abs(this[u, v + 1]);
float br = Math.Abs(this[u + 1, v + 1]);
float r = Math.Abs(this[u + 1, v]);
float tr = Math.Abs(this[u + 1, v - 1]);
float t = Math.Abs(this[u, v - 1]);
// Compute dx using Sobel:
// -1 0 1
// -2 0 2
// -1 0 1
float dX = tr + 2 * r + br - tl - 2 * l - bl;
// Compute dy using Sobel:
// -1 -2 -1
// 0 0 0
// 1 2 1
float dY = bl + 2 * b + br - tl - 2 * t - tr;
Vector3 N = new Vector3(dX, dY, 1.0f / strength);
N.Normalize();
//convert (-1.0 , 1.0) to (0.0 , 1.0), if necessary
//Vector3 scale = new Vector3(0.5f, 0.5f, 0.5f);
//Vector3.Multiply(ref N, ref scale, out N);
//Vector3.Add(ref N, ref scale, out N);
return N;
}

For best results, your normalmap should be at least 4x bigger than the heightmap (i.e. generate the heightmap at a higher resolution and downsample when you construct the vertex buffer). 16x bigger is even better.

Re: HeightMap to NormalMap

Code :

for(int Y=1;Y<image->sizeX-1;Y++)
for(int X=1;X<image->sizeY-1;X++)

that's a little bit incorrect :)

However, I don't see any other major mistakes...

Maybe the problem lies aside the code you provided.