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));
}
[DirectX10] Parallax mapping looks wrong
Hi there!
I wont to put some parallax mapping into my engine, but something seems to be wrong:
The pixel shader is here:
Can you maybe give me some pseudo code? I ahve looked at the SDK sample already, but everything seems to be just like there...
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...
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.
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.
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);
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. :(
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement