# Who wants to be a millionnaire (DirectX Matrixes edition)

This topic is 4966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i'm your host for tonight. This will be a special edition, so no choice of answers. (heartbeating music starts..) So let's start with the 100$question : What is the "practical" purpose of this function :D3DXMatrixTranspose ? By practical I mean show an example and explain why that function must be used. Don't answer me it switches columns to rows I know, because knowing that does not tell me when to use this function. Now the 200$ question : From DirectX SDK : [­...]You can minimize the number of required calculations by concatenating your world and view matrices into a world-view matrix that you set as the world matrix, and then setting the view matrix to the identity. [...] For clarity, in this documentation Direct3D samples rarely employ this optimization. For clarity, could you show an example (a simple one thanks) of concatenating a world and view matrix? Right now i'm using them separately. This is it for the first part of the show.. Come back next week!

##### Share on other sites
Can we use a life line? LOL!!! I knew of the transpose thing for many years and I've never seen it used nor do I know even to this day of where it is used. Does anyone know?

##### Share on other sites
$100: D3DXMatrixTranspose(&mat, &mat); pDev->SetVertexShaderConstant(&mat, 20, 4); Why? Because then a matrix multiply becomes dp4 r0.x, v0, c20 dp4 r0.y, v0, c21 dp4 r0.z, v0, c22 dp4 r0.w, v0, c23 Also, technically, if you want to accurately transform normals in software (or in a shader), you should use the transpose of the inverse of the world transform. D3DXMatrixInverse(&iworld, 0, &world); D3DXMatrixTranspose(&itworld, &iworld); D3DXVec3TransformNormal(&normworld, &norm, &itworld);$200:
concat = world * view;
or
D3DXMatrixMultiply(&concat, &world, &view);
D3DXMatrixIdentity(&ident);
pDev->SetTransform(D3DTS_WORLD, &concat);
pDev->SetTransform(D3DTS_VIEW, &ident);

--

##### Share on other sites
We've got a winner!

So far you've won $300 dollars, Namethatnobodyelsetook, but you know how it's working, nobody's get off that seat until maybe passed the 64,000$ mark.

I'm sure you can't wait for the 400\$ question.

Next one will be soon. Final answer.

##### Share on other sites
If you set one of the view/proj matricies to ident, will it not multiply throught it? or will it multiply through it anyways?

##### Share on other sites
Quote:
 Original post by AxiverseIf you set one of the view/proj matricies to ident, will it not multiply throught it? or will it multiply through it anyways?

Personally, I'd expect DX to multiply the matrices together itself. It's slightly more work than testing for identity, and can save lots of work per vertex. If you're doing a shader, you can multiply them if you want, or leave them seperate.

We use coords in worldspace for height fog and lightmap UV generation (world x and z * scale factor), allowing the lightmap to affect moving objects. If we didn't do height fog, we could do lightmap UVs as a texture transform with the inverse of view and then scaled and do that on cameraspaceposition, but really, it all works out to the same number of matrix multiplies, so why bother making the CPU calculate the inverse of the view transform.

If you use the fixed pipeline, I'm sure it multiplies world and view, and if you're using shaders, it's up to you. If you don't need data in worldspace, go for it... mix those matrices. If you do need worldspace data, it's not a big deal. It's only 3 shader instructions.

##### Share on other sites
What are those three simple instructions?

##### Share on other sites
Normally you'd have

// transform to worldview, or worldviewproj
dp4 r1.x, v0, c20
dp4 r1.y, v0, c21
dp4 r1.z, v0, c22
dp4 r1.w, v0, c23
// now r1 = viewpos or viewprojpos

// transform to world
dp4 r0.x, v0, c17
dp4 r0.y, v0, c18
dp4 r0.z, v0, c19
mov r0.w, v0.w
// transform to view or viewproj
dp4 r1.x, r0, c20
dp4 r1.y, r0, c21
dp4 r1.z, r0, c22
dp4 r1.w, r0, c23
// now r0 = worldpos
// now r1 = viewpos or viewprojpos

Ok, so it MAY be 4 instructions to have an extra matrix mutliply (because you need to copy over the W... or use a 4X4 matrix, wasting a constant register).

• 35
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631358
• Total Posts
2999531
×