Jump to content
  • Advertisement
Sign in to follow this  
51mon

Problems with Bump Mapping

This topic is 3987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I got problems with bump mapping and would be very pleased if someone could help me. Here is a screenshot from what my rendering looks like. As you can see the normals is opposite in left and right side and washed out in the middle. My shader looks like this.
struct TEST_VS_OUT
{
	float4 Position : SV_Position;
	float3 WorldNormal : NORMAL;
	float3 LightVector : TEXCOORD4;
	float2 TextureUV : TEXCOORD5;
};

TEST_VS_OUT RenderTestVS( float4 vPos : POSITION, float3 vNormal : NORMAL, float2 vTexCoord0 : TEXCOORD0)
{
	TEST_VS_OUT Output;
	
	Output.Position = mul( vPos, g_MatWorldViewProj_C);
	Output.WorldNormal = vNormal;
	
	Output.LightVector = g_vLightPosition - vPos.xyz;
	
	Output.TextureUV = vTexCoord0;
    
	return Output;    
}

float4 RenderTestPS( TEST_VS_OUT Input) : SV_Target0
{
	float4 vBump = g_BumpTexture.Sample( MeshTextureSampler, Input.TextureUV);
	vBump *= 2.0f;
	vBump -= float4( 1.0f, 1.0f, 1.0f, 0.0f);

	float3 Normal = normalize(Input.WorldNormal);
	float3 vUp = float3( 0.0f, 1.0f, 0.0f);
	if( abs(Normal.x) < abs(Normal.y))
		vUp = float3( 1.0f, 0.0f, 0.0f);
	float3 Tangent = cross( vUp, Normal);
	float3 Binormal = cross( Normal, Tangent);
	
	float3x3 BTNMatrix = float3x3( Binormal, Tangent, Normal);
	float3 TransBump = mul( vBump.xyz, BTNMatrix);
	float Shading = dot( TransBump, normalize(Input.LightVector));
	return Shading * g_MeshTexture.Sample( MeshTextureSampler, Input.TextureUV);
}


g_vLightPosition is given by g_Camera2.GetEyePt(). Does anybody have a clue of what’s wrong? I suspect that something has to be done with the light vector? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Many examples I see make a 3x3 matrix out with float3x3(tangent, binormal, normal).
In your shader you have the tangent and binormal backwards relative to them, but I'm not sure if that would make a difference. Try reversing them and see what happens.

Share this post


Link to post
Share on other sites
Quote:
Original post by blakedev
Many examples I see make a 3x3 matrix out with float3x3(tangent, binormal, normal).
In your shader you have the tangent and binormal backwards relative to them, but I'm not sure if that would make a difference. Try reversing them and see what happens.


No that didn't work, the error just appeared in another form :(

Share this post


Link to post
Share on other sites
I'm no math wiz, but I'm not sure you can just calculate your tangent and binormal that way. It might work for a number of cases, but it doesn't look like a valid approach for all tangent space calculations. In you screenshot it looks like you're kinda rendering a pretransformed quad, which is one case where your tangents & binormals would be off, since vUp points along the z-axis in this case.

I might be way off, but I don't see anything wrong with the other lighting calculations at first glance. You could always try and move the light around a bit in your scene, that might give you a better idea of how the lighting is working out. But I'd try and calculate a valid tangent frame using the D3D utility functions and using that in the shader first.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!