Original Post
Hi guys, I'm trying to use ComputeNormalMap (D3DXComputeNormalMap function in the C++ library) to generate a normal map from my height map. My height map is a greyscale 8-bit bitmap. I load it into a Texture with 1 mipmap level, with an 8-bit luminance channel format:
heightMap = TextureLoader.FromFile(Graphics.Device,
heightMapPath,
x, y, 1,
0,
Format.L8,
Pool.Managed,
Filter.Box,
Filter.Box,
0);
byte[,] heights = (byte[,])heightMap.LockRectangle(typeof(byte), 0, LockFlags.ReadOnly, x, y);
heightsNormalized = new float[heights.GetLength(0), heights.GetLength(1)];
for(int i = 0; i < heights.GetLength(0); i++)
{
for(int j = 0; j < heights.GetLength(1); j++)
{
heightsNormalized[j,i] = ((float)heights[j,i])/byte.MaxValue;
}
}
normalMap = new Texture(Graphics.Device, x, y, 1, 0, Format.A8R8G8B8, Pool.Managed);
TextureLoader.ComputeNormalMap(
normalMap,
heightMap,
0,
Channel.Luminance, 1);
The heightmap works just fine, I'm rendering with it and everything - but when I go to computer the normal map at the end I get D3D_INVALID_CALL. Any ideas anyone?