我正在尝试使用凹凸贴图创建着色器。
我有对象的真实法线,我有凹凸贴图采样法线。我想做的是旋转采样的法线,以便在采样的法线点上“向上”在真实法线的方向上。
我一直在做数学,但我似乎做错了...... Y 在这个世界上。
// 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);