Hey guys.
I sort of have a problem when trying to do this...
First of all my engine uses deferred lighting(still it shouldn't make any difference).
So I made a really nice terrain but give the way it works I have to use a normal map for it. I only have a height map so I have to convert the heightmap into a normalmap.
Currently I have this code for converting:
Code :
for(int Y=1;Y<image->sizeX-1;Y++)
		for(int X=1;X<image->sizeY-1;X++)
			float v1 = image->GetImageHeight(X,Y-1)*scale;
			float v2 = image->GetImageHeight(X-1,Y)*scale;
			float v3 = image->GetImageHeight(X+1,Y+1)*scale;
			CVector3 n1 = (CVector3(1,v3,1)-CVector3(0,v1,-1)).cross(CVector3(1,v3,1)-CVector3(-1,v2,0));
			CVector3 normal = n1;
			unsigned char r, g, b;
			r = (BYTE)(255.0 * (normal.x * 0.5 + 0.5));
			g = (BYTE)(255.0 * (normal.y * 0.5 + 0.5));
			b = (BYTE)(255.0 * (normal.z * 0.5 + 0.5));
			norm->data[Y*image->sizeX*3+X*3] = r;
			norm->data[Y*image->sizeX*3+X*3+1] = g;
			norm->data[Y*image->sizeX*3+X*3+2] = b;
It basically takes 3 near adjacent pixels transforms them into 3 3d points with the height(y value) being the height from the heightmap as a float multiplied by the maximum height in the terrain so that all the vertexes will be just like in the terrain.
Interesting problem is that when I run it my normal map looks chunky.

I really can't figure this out.
I guess it's something from my function but I can't understand what.
Could anyone be so nice to help me please?
Thank you very much.