Sign in to follow this  

Parallax Mapping problem

This topic is 4336 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

I've been trying to get Parallax Mapping working for a few days now, but for some reason its just not coming out right. I understand the concept and all, but it seems I'm doing something stupid in my shader code. I'm testing this in fxComposer. Basically it only seems to work from certain angles. Objects in this code are assumed not to have world transformations. Heres the code: float4x4 s_matWorldViewProj : WorldViewProjection; float4x4 s_matWorld : World; float4x4 s_matWorldView : WorldView; float3 s_cameraPos : CameraPosition; float3 lightDir : Direction < string Object = "DirectionalLight"; string Space = "World"; > = {1.0f, 0.0f, .5f}; texture dT : Diffuse < string ResourceName = "rockwall1.tga"; >; texture normMap : Diffuse < string ResourceName = "rockwallNormal.tga"; >; texture heightMap : Diffuse < string ResourceName = "rockwallHeight.tga"; >; sampler diffuseSampler = sampler_state { Texture = <dT>; MinFilter = Linear; MagFilter = Linear; MipFilter = None; AddressU = WRAP; AddressV = WRAP; }; sampler normalSampler = sampler_state { Texture = <normMap>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = WRAP; AddressV = WRAP; }; sampler heightSampler = sampler_state { Texture = <heightMap>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = WRAP; AddressV = WRAP; }; struct VS_IN { float4 pos : POSITION; float3 norm : NORMAL; float2 tex : TEXCOORD0; float3 tang : TANGENT; float3 bino : BINORMAL; }; struct VS_OUT { float4 pos : POSITION; float2 tex : TEXCOORD0; float3 toEye : TEXCOORD1; float3 norm : TEXCOORD2; }; VS_OUT PVertexShader(VS_IN inVertex) { VS_OUT outVertex; //basic stuff outVertex.pos = mul(inVertex.pos, s_matWorldViewProj); outVertex.tex = inVertex.tex; outVertex.norm = inVertex.norm; //get eye vector float3 eye = mul(inVertex.pos, s_matWorldView); //get tangent matrix float3x3 matTangent; matTangent[0] = mul(inVertex.tang, s_matWorldView); matTangent[1] = mul(inVertex.bino, s_matWorldView); matTangent[2] = mul(inVertex.norm, s_matWorldView); //bring eye into tangent space outVertex.toEye = mul(eye, matTangent); //NOTE: Objects are assumed not to have world transforms. return outVertex; } struct IN_PIXEL { float2 tex : TEXCOORD0; float3 toEye : TEXCOORD1; float3 norm : TEXCOORD2; }; float4 PPixelShader(IN_PIXEL inPixel) : COLOR { //get height value float2 height = tex2D(heightSampler, inPixel.tex).xy; //get look vector float2 look = normalize(inPixel.toEye).xy; //offset texture coord float2 newTC = inPixel.tex + (look*(height*0.04 - 0.02f)); return tex2D(diffuseSampler, newTC); } technique DiffuseTechnique { pass P0 { VertexShader = compile vs_1_1 PVertexShader(); PixelShader = compile ps_2_0 PPixelShader(); } };

Share this post


Link to post
Share on other sites
Instead of :

//get eye vector
float3 eye = mul(inVertex.pos, s_matWorldView);

You might do :

float3 eye = mul(inVertex.pos-s_CameraPos, s_matWorldView);
? :)

EDIT: In fact, you might not multiply by matWorldView all your data concerning offset mapping. This is incorrect I think.

then

float3 eye = inVertex.pos-s_CameraPos;

float3x3 matTangent;
matTangent[0] = inVertex.tang;
matTangent[1] = inVertex.bino;
//matTangent[2] = inVertex.norm; ===> is unuse for offset mapping

then dont use a mtrix, do

OutVertex.ToEye.x = dot(inVertex.tang, eye);
OutVertex.ToEye.y = dot(inVertex.binorm, eye);

ToEye => vector2;

Share this post


Link to post
Share on other sites
I think the idea behind parallax mapping was never that it looked like the object was parallaxed from all angles as you seem to be requesting. It's meant to "look 3-d" from a certain set of angles, but once you've overstepped that angle set, it just looks like an ordinary texture again, with silly-looking bump mapping applied to it. Have to look into this one tho...

Share this post


Link to post
Share on other sites

This topic is 4336 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.

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