Sign in to follow this  
mind in a box

[DirectX10] Parallax mapping looks wrong

Recommended Posts

mind in a box    887
Hi there! I wont to put some parallax mapping into my engine, but something seems to be wrong: Image and video hosting by TinyPic The pixel shader is here:
float4 wtPixelShader(PixelShaderInput Input) : SV_Target
{
	
	float3 tCam = WorldToTangent_Inv(normalize(CamLoc-Input.VertexPos),Input.Norm,Input.Tangent,Input.Binormal);
	float Height = TexUV(Tex2,UV*5).r * 0.03;
	Height/=tCam.z;

	float2 ParallaxUV = (UV) + tCam.xy * Height;

	float4 Color = TexUV(Tex1,ParallaxUV);

	return Color;
	//return float4(ParallaxUV,0,1);
}

//... Include:

shared float3 WorldToTangent_Inv(float3 In,float3 Nrm,float3 Tan, float3 Bin)
{
    float3x3 mTangentFrame = {Tan, Bin, Nrm };
  
    return normalize(mul((float3x3)mTangentFrame, In));
    
}

Can you maybe give me some pseudo code? I ahve looked at the SDK sample already, but everything seems to be just like there...

Share this post


Link to post
Share on other sites
SIIYA    477
I had similar problem. The cause of my problem was wrong computation of mesh tangents. I used D3DXComputeTangentFrameEx() for tangent and binormal computation, and passing anything other than NULL for CONST DWORD * pdwAdjacency parameter caused this behavior in shader.

Share this post


Link to post
Share on other sites
JohnnyCode    1046


it seems that it shifts correctly by y axis but opposite at x axis.
Try this then

Height/=tCam.z;

tCam.x=-tCam.x;

float2 ParallaxUV = (UV) + tCam.xy * Height;

float4 Color = TexUV(Tex1,ParallaxUV);

Share this post


Link to post
Share on other sites
mind in a box    887
Sorry, my internet was down for a while. But I found out that the Vertex-Position I used was in Object space. So it works now, but it looks strange. Also, if I rotate the model, the parallax mapping stays the same, just like I never rotated it. :(

Share this post


Link to post
Share on other sites
rubicondev    296
There are few things that are almost always responsible for various bump mapping problems. I suggest you try em all ad hoc and see if any work:

1) Swap the tangent and binormal params around
2) Tranpose the matrix before you multiply with it
3) When rotating normals, remember to cast a full matrix to a float3x3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this