# Normal and height maps

First: a good year to you all!!!

I have a normal map, and I want to add more detail (normals) to it. The detail is stored in a height map. The way I’m doing this is to transform the height map to a normal map add then add the two of them. Is this correct?! Is there a better way?

At a minimum, you need to re-normalize after adding. That will make it “work” although the result is probably not exactly what you want.

What you REALLY want is probably to start with two height maps, where the second height map is applied to the first height map using some scaling, and in the tangent space of that first height map. You can do this the expensive way by calculating a tangent base per pixel, and using that base to apply the second height map’s normal output.

You can also treat the normals as rotations, and apply the rotation of the second normal to the existing first normal. That’s also very close to what I think you really want.

If you do this real time, then neither of these mechanisms work all that quickly.

I want to do this at startup… I’ll try converting the normal do height, add the two and then create the final normal map.

Thankx

adding two normal maps together isn’t the solution. if you want to add the detail normal map correctly, you have create Normal,Tangent and Binormal for every pixel of the first texture, and then multiply the vector(pixel) from the 2nd texture with it.
here is my code for it:

unsigned char *mix(TGABUFF *tb,unsigned char *a,unsigned char b)
{ int num = tb->w
tb->h;
unsigned char *d=(unsigned char )malloc(num4);
float A,B,C,M,xn,yn;

for(int t=0;t<num;t++)
{ expand(B,&a[t4]); // convert pixel to float, normalized vector
expand(A,&b[t
4]);
// create norm,bin,tan
set(C,0,1,0);
cross(xn,C,A);
cross(yn,A,xn);
norm(xn);
norm(yn);
// setup 3x3 matrix
M = xn; M = yn; M = A;
M = xn; M = yn; M = A;
M = xn; M = yn; M = A;

``````// 3.roatate normal
C = B*M + B*M + B*M;
C = B*M + B*M + B*M;
C = B*M + B*M + B*M;
// convertback to pixel
compact(&d[t*4],C,shd*1.25f);
``````

}
return d;
}

(this code is tested with textures generated with the normtool plugin for photoshop from nvidia)