Normal maps and Y or Z as height value

Started by
4 comments, last by Dragon_Strike 16 years, 11 months ago
Hi I’m using the following pixel shader to implement per pixel lightning with normal maps. I've taken this code from the XNA game Programming Book (witch by the way is an excellent book). The author uses compressed normal textures with DXT5 so that's why we uses .agb when he accesses the normal map. In my terrain engine the Y is up not Z as the author assumes in his book. My question is : I should change agb to abg right ? I'm saying this because the normal maps are calculated with xyz being z the up direction not Y as in my engine. I've tried this but I’ve not seen a major difference between the two. By the way that's now my main problem, it's terribly hard to understand if I’m getting the proper image or not... :-( float4 PsDiffusePerPixel(VsOutputDiffusePerPixel In) : COLOR { float4 diffuseTexture = tex2D(Texture0Sampler, In.TexCoord); float3 normalTexture = tex2D(NormalTextureSampler, In.TexCoord).agb; float3 normalVector = normalize((2.0f * normalTexture) - 1.0f); float3 lightVector = (2.0 * In.LightVector) - 1.0; float diffuse = saturate(dot(normalVector, lightVector)); return diffuseTexture * (ambientColor + diffuse * diffuseColor); } [Edited by - Ivo Leitao on May 21, 2007 9:24:44 AM]
Advertisement
im no expert but...

i think the normalmaps are in tangentspace.. which means u should simply multiply your lightvector by your TBN matrix before lighting calculations...

like this...

	vec3 Normal = normalize(gl_Normal.xyz);	vec3 Tangent = normalize(gl_Color.xyz);	vec3 BiNormal = cross(Tangent,Normal);				mat3 TBN = mat3(Tangent, BiNormal, Normal); 	 	LightDir = (LightPos - VertPos)*TBN;


Quote:Original post by Dragon_Strike
im no expert but...

i think the normalmaps are in tangentspace.. which means u should simply multiply your lightvector by your TBN matrix before lighting calculations...

like this...

*** Source Snippet Removed ***


I've done that but in the vertex shader like this

float3x3 ComputeTangentMatrix(float3 tangent, float3 normal)
{
float3x3 worldToTangentSpace;

worldToTangentSpace[0] = mul(cross(normal, tangent), world);
worldToTangentSpace[1] = mul(tangent, world);
worldToTangentSpace[2] = mul(normal, world);

return worldToTangentSpace;
}

VsOutputDiffusePerPixel VsDiffusePerPixel(VsInput In)
{
...
Out.LightVector = 0.5 + 0.5 * normalize(mul(ComputeTangentMatrix(In.Tangent, In.Normal), lightDirection));

return Out;
}

ehm..yea... well that doesnt rly look very correct to me... but im sure there is something behind it...

but anyways.. if thats correct and ur getting it in tangentspace then there shouldnt be any problems.. since y before becomes z after when u multiply by the tangent matrix...

whats the problem?
Quote:Original post by Dragon_Strike
ehm..yea... well that doesnt rly look very correct to me... but im sure there is something behind it...

but anyways.. if thats correct and ur getting it in tangentspace then there shouldnt be any problems.. since y before becomes z after when u multiply by the tangent matrix...

whats the problem?


Well probably this is a math problem, and I’m not especially proud of my knowledge in that area :-(. So you are saying that I can still use agb an not abg because of the space transform ? Or the tangent space transform is wrong ?
Quote:Original post by Ivo Leitao
Quote:Original post by Dragon_Strike
ehm..yea... well that doesnt rly look very correct to me... but im sure there is something behind it...

but anyways.. if thats correct and ur getting it in tangentspace then there shouldnt be any problems.. since y before becomes z after when u multiply by the tangent matrix...

whats the problem?


Well probably this is a math problem, and I’m not especially proud of my knowledge in that area :-(. So you are saying that I can still use agb an not abg because of the space transform ? Or the tangent space transform is wrong ?


if your space transform is correct then u dont have to modify the normalmap...

This topic is closed to new replies.

Advertisement