Hello Demus79, thanks for replying.
Quote:- your worldviewproj matrix should be fine since the balls are actually on the screen.
That's what I think.
Quote:- world matrix might not be alright, though there is no evidence that it isn't correct.
...or, it's not being used at all? I've tried commenting out the lines of code that use the HLSL global variable "world" and I get the same results, as if it doesn't matter that it's there!
Quote:- position of the light, is it in world space or do you accidentally transform it by the inverse world matrix ?
That is a fine queation! the light position is hardcoded into the shader:
float3 lightPos = float3(1.0, 150.0, 1.0);
And I'm sending the matrix to the shader untransposed, and without inversion. AS far as I've tried, if I transpose, inverse, inverse-transpose, or whatever other method you can think of, I always get the same results. As a matter of fact, if I comment out the SetVertexShaderConstantF statement that sets the world matrix I still get the same results, as if the shader is not getting the matrix at all! Or perhaps the matrix is being set to sero or null? I've tried changing the constant registers, and using SetMatrix instead, but still the same. If I change the constant registers to something I know is wrong (say c10 instead of c4) then there is no lighting, so I know that something is being passed. Here is how I'm currently setting the shader:
D3DXMatrixTranspose( &theWorld->matWorldViewProj , &(theWorld->matWorld * theWorld->matView * theWorld->matProj) ); theWorld->g_pd3dDevice->SetVertexShaderConstantF(0, theWorld->matWorldViewProj, 4); //D3DXMatrixInverse(&theWorld->matWorldI, NULL, &thePhysics->dxTrans); //D3DXMatrixTranspose(&theWorld->matWorldIT, &theWorld->matWorldI); theWorld->g_pd3dDevice->SetVertexShaderConstantF(4, theWorld->matWorld, 4); theWorld->g_pd3dDevice->SetVertexShader( retrieve(2) );// D3DXHANDLE handle;// if(handle = pConstTable->GetConstantByName(NULL,"WORLDVIEWPROJECTION")) {// MessageBox(NULL, "got handle for WVP!", "Error!",// MB_ICONEXCLAMATION | MB_OK); //tempConstTable->SetMatrix(theWorld->g_pd3dDevice,"WORLDVIEWPROJECTION",(D3DXMATRIX*)&theWorld->matWorldViewProj);// }// if(handle = pConstTable->GetConstantByName(NULL,"WORLD")) {// MessageBox(NULL, "got handle for W!", "Error!", // MB_ICONEXCLAMATION | MB_OK); //tempConstTable->SetMatrix(theWorld->g_pd3dDevice,"WORLD",(D3DXMATRIX*)&thePhysics->dxTrans);// }
AS you can see from all of the commented code, I've tried many different methods.
Quote:The order matters in the mul instruction. mul(Vector,Matrix) isn't same as
mul(Matrix,Vector) and that might produce problems as described. The other operation actually results a vector as if the matrix was transposed.
Thanks, but I already tried that. It did have an effect on how the shading appeared (the shade rotated the opposite direction of the rotation of the sphere instead of rotating with it), but it didn't fix the problem.