Skip to main content
GameDev.net gamedev.net
🔒 Locked

Shader matirx problems...

Started by Jorj Apr 25, 2006 at 11:54 AM 2 replies 450+ views
Original Post
Jorj
Jorj
ok, i have some VERY basic shader code ( as in i exported the default directx effect from RenderMonkey - so it should just dye the model red), but it requires a matrix is passed to it, its called: matViewProjection - and i can't find out what it should be... I have tried passing it my projection matrix, view matrix, view*proj and some other variations with the world matrix in there too ( which is 0,0,0 so shouldn't make a difference ), but each time it either leaves me with a background coloured scene, a completely red scene or lines of red on background. I have the camera set up so it points nicely at the scene showing some background and some scene - so whouldn't i be getting a different result???? As i said this is a simple shader and this is the only variable i am passing it, no textures or anything else are loaded - so i take it it must be this matrix i am passing it is wrong??? Can anyone tell me what this matrix should be??? thanks - Jorj
jollyjeffers
jollyjeffers
Two possible things:

1. What order are you multiplying the matrices? Usually its World * View * Projection. Matrix multiplication is not commutative, so you'll get different results with different orders. Also, you say your matrix is (0,0,0) - don't set it all to zero, set it to the identity with D3DXMatrixIdentity() if you're not using it...

2. You mention effects, but does that mean the standard FX via ID3DXEffect? Depending on the compiler flags it should sort out the row-major/col-major transposition, but "pure" shaders don't do this - you have to pass it in whatever form you compiled with. Even then, you might want to check you've got everything in the correct row-major/col-major format.

I always forget the details for #2, try changing the FX compile flags and then try calling D3DXMatrixTranspose() before passing in the matrix. Just work your way through the combinations and see if one of them gets it right [lol]

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
Jorj
Jorj
right, i changed the multiplication order (it was completely the wrong way round ( i knew the order mattered, but i had no idea which one way right, thanks for that)) and put a D3DXMatrixIdentity() in.

Now instead of a line of about 2px wide on the screen which changed angles when youe tried to move around i get 3 lines, coming to a central point, which change thickness when you try to move....

My current effect loading code is:

D3DXCreateEffectFromFile( device, "effect.fx", NULL, NULL, dwShaderFlags, NULL, &effect, NULL );

thats it, then when rendering:

mWorldViewProjection = matWorld * matView * matProj;
effect->SetMatrix( "matViewProjection", &mWorldViewProjection );
effect->SetTechnique( "myeffect" );
effect->Begin(&cPasses, 0);
for (UINT iPass = 0; iPass < cPasses; iPass++)
{
effect->BeginPass(iPass);
for(DWORD i = 0; i < m_dwNumMaterials; i++){=

m_pMesh->DrawSubset(i);
}
effect->EndPass();
}
effect->End();

oh wait, i just put the transpose function and it now *touch wood* looks right, i can make out shapes that look right, thanks a lot, you've been a great help.

- Jorj
noNchaoTic
noNchaoTic
as JollyJeffers says, check matrix order, shaders that work in render monkey need to have mul() calls reversed for matrix/vector multiplication (assuming your using standard D3DXMATRIX structures).
Steven ToveySPUify | Twitter

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.