I'm trying to create a shader with bump-mapping.
I have the real normal of the object, and I have the bump-map sampled normal. What I would like to do is rotate the sampled normal, so that "up" on the sampled normal points in the direction of the real normal.
I've been working at the math and I can't seem to get it right... Y is up in this world.
// Vertex shader sends this matrix to the pixel shader
OUT.normal[0] = mul((float3x3)world, normal);
float3 temptan = cross(normal, float3(0, 0, 1));
temptan = normalize(temptan);
OUT.normal[2] = mul((float3x3)world, temptan);
OUT.normal[1] = cross(OUT.normal[0], OUT.normal[2]); calculating binormal (in world space)
// Pixel Shader:
// Get normal from bump texture
float3 normal = tex2D(normalmap, texCoord);
normal = normal * 2 - 1;
// Swap Z and Y, since Z is up on the texture, but Y is up in this world.
float temp = normal[1];
normal[1] = -normal[2];
normal[2] = temp;
// Multiply the sampled normal and the normal-basis matrix together.
normal = mul(normalMat, normal);