Jump to content
  • Advertisement
  • entries
    422
  • comments
    1540
  • views
    490082

3D Pipes in Direct3D 10 - another one bites the du

Sign in to follow this  
jollyjeffers

108 views

I've mentioned it a couple of times recently, but I sat my 70-536 MCTS .NET exam on Tuesday afternoon. Scored 859 which is a pass (>700). Yay.


Right, finally twigged what was causing the messed up normals. I apologise for the repeated THUD noise you're hearing but I felt I needed to simultaneously kick myself and hit my head against the desk.

The follow-on investigation to the previous journal entry yielded unsurprisingly that the matrix transformations were a big part in it. Changing the rotations about gave some better and some worse results. Despite working through all the theory on paper and trying combinations in code I couldn't settle on any changes that fixed all cases. I panicked briefly thinking that my architecture was at fault and that I couldn't express the matrix transformations in the way that I'd need to.

I had assumed it was entirely the applications fault that the image was wrong. Then, by simple static code analysis I spotted this in my shader:
float3 p = lerp( pA, pB, v.blend_weight );

// Transform the world-space position to final projection-space coords
o.position = mul( float4( p, 1.0f ), mViewProj );

// Transform the normal vector
float3 nA = mul( v.normal, (float3x3)v.blend_from );
float3 nB = mul( v.normal, (float3x3)v.blend_to );
o.normal = normalize( nA + nB );

Why was I using a weighted blend to determine the position and a simple average for the normal...??

hmm... so let me see:
float3 p = lerp( pA, pB, v.blend_weight );

// Transform the world-space position to final projection-space coords
o.position = mul( float4( p, 1.0f ), mViewProj );

// Transform the normal vector
float3 nA = mul( v.normal, (float3x3)v.blend_from );
float3 nB = mul( v.normal, (float3x3)v.blend_to );
o.normal = normalize( lerp( nA, nB, v.blend_weight ) );

Let's give that a shot...



* slaps forehead *

By comparison, we now have:


Working


Broken


You may notice that a few of the joints are still showing artifacts. I'm pretty sure I know what that's about (that is app-side matrix manipulation) and I'll get on the case ASAP.

For now, I'm just happy to have gotten it mostly working [grin]

If you want, you can grab the relevant code as ChangeSet #14522.
Sign in to follow this  


2 Comments


Recommended Comments

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
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!