Jump to content
  • Advertisement
Sign in to follow this  
Laccolith

Normal Mapping in View Space

This topic is 2533 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'm changing my deferred shader to work in view space from world space but I'm having trouble getting the correct results from my normal mapping. I'm pretty sure I have got the rest of the pipeline working as if I manually calculate the face normal in the pixel shader I get the correct results.

What I have at the moment is in the vertex shader I'm creating a matrix to transform from tangent space to view space using the normal, binormal and tangent:
float4x4 gWorldView;
float3x3 mTangentToView;

Output.mTangentToView[0] = mul(float4(Input.mTangent, 0.0f), gWorldView).xyz;
Output.mTangentToView[1] = mul(float4(Input.mBinormal, 0.0f), gWorldView).xyz;
Output.mTangentToView[2] = mul(float4(Input.mNormal, 0.0f), gWorldView).xyz;


Then in the pixel shader I sample the normal map and transform it to view space using the mTangentToView matrix:
float3 normal = gNormal.Sample(gSampler, Input.mTexCoord).rgb;
normal = (2.0f * normal) - 1.0f;
normal = mul(normal, Input.mTangentToView);
Output.mNormal = normalize(normal);


And for reference, this is what I was doing to calculate the face normal, where mPositionView is the view space position:
Output.mNormal = normalize(cross(ddx_coarse(Input.mPositionView), ddy_coarse(Input.mPositionView)));

Here are screen caps showing the result of the normal mapping and just using face normals:
Normal Mapping
Face Normals

[edit] Turns out it was a problem with the model not the code, edited post to save bumping

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!