# [DirectX10] Parallax mapping looks wrong

## Recommended Posts

Hi there! I wont to put some parallax mapping into my engine, but something seems to be wrong: 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 on other sites
Hodgman    51328
Have you tried tweaking that 0.03 value?

##### Share on other sites
Yes, but the height is not the problem. When you take a closer look to the picture, you will notice that they bumps get shifted into the wrong direction...

##### 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 on other sites
I use a .x loader from the NVIDIA SDK10 for loading my meshes. So, I think they know what they are doing. Also normal mapping works just fine for me.

##### 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 on other sites
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 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

## 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