Sign in to follow this  
MZP

Parallax Mapping Error

Recommended Posts

MZP    124
Hello guys, I have some problems with implementing standard parallax mapping. The error is hard to explain, please take a look at this image: http://i36.tinypic.com/2u8aqv4.jpg Notice how the capped cone is facing away in the wrong direction. In the vertex shader I transform the toEye vector to tangent space...
float3 Pos = mul ( float4 ( input.Pos, 1 ), World );
float3 Nor = mul ( float4 ( input.Nor, 0 ), World );
float3 Tan = mul ( float4 ( input.Tan, 0 ), World );

float3 N = Nor;
float3 T = normalize ( Tan -N *dot ( Tan, N ) );
float3 B = cross ( N, T );
float3x3 TBN = float3x3 ( T, B, N );

output.toEye = mul ( TBN, CameraPosition -Pos );

... and in the pixel shader I use this vector to offset my texture coordinates.
const float BIAS  = +0.04f;
const float SCALE = +0.08f;

float height = texture2.Sample ( linearSampler, input.Tex ).r *SCALE -BIAS;
input.Tex += height *normalize ( input.toEye ).xy;

// use input.Tex to sample diffuse and normal map, etc etc...

Thanks in advance!

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