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

View Transformation + Projection Transformation calculation method

Started by lucky6969b Aug 7, 2012 at 5:49 AM 1 replies 1.2k views
Original Post
lucky6969b
lucky6969b

virtual void Render()
{
CObjects::Render();
g_pEffect->SetTechnique(g_pEffect->GetTechniqueByName("basic_with_shader"));
D3DXMATRIXA16 compMat, invMat;
g_pEffect->SetMatrixTranspose("matView", &g_Cam[iCurCam].GetViewMatrix());
D3DXMatrixMultiply(&compMat, &m_matWorld, &g_Cam[iCurCam].GetViewMatrix());
g_pEffect->SetMatrixTranspose("matWorldView", &compMat);
D3DXMatrixInverse(&invMat, NULL, &compMat);
D3DXMatrixTranspose(&invMat, &invMat);
g_pEffect->SetMatrixTranspose("matWorldViewIT", &invMat);
D3DXMatrixInverse(&invMat, NULL, &g_Cam[iCurCam].GetViewMatrix());
D3DXMatrixTranspose(&invMat, &invMat);
g_pEffect->SetMatrixTranspose("matViewIT", &invMat);
D3DXMatrixMultiply(&compMat, &compMat, &g_Cam[iCurCam].GetProjMatrix());
g_pEffect->SetMatrixTranspose("matWorldViewProj", &compMat);
g_pEffect->SetMatrixTranspose("matProj", &g_Cam[iCurCam].GetProjMatrix());
m_Mesh->UpdateFrame(NULL, &m_matWorld);
m_Mesh->RenderTransparent();
}



VS

vNormal = normalize(vNormal);
Out.Pos = mul(matWorldViewProj, vPosition);
float3 P = mul(matWorldView, vPosition); //position in view space
float3 N = mul((float3x3)matWorldViewIT, vNormal); //normal in view space
float3 V = -normalize(P); //viewer






*********** I strongly believe there is a problem with matViewProj Transform combining with world transform to get the positions.
What is the correct way of calculating the world transform but taking care of view and projection?

In Summary, I don't know how to define the view transformation.....



Thanks
Jack
lucky6969b
lucky6969b
http://msdn.microsoft.com/en-us/library/windows/desktop/ee418867%28v=vs.85%29.aspx

I think the AMD shader is combining the view and projection transform into one, and directly transforming world to clip space.
Adaline
Adaline
Hello



D3DXMATRIXA16 compMat, invMat;
g_pEffect->SetMatrixTranspose("matView", &g_Cam[iCurCam].GetViewMatrix());
D3DXMatrixMultiply(&compMat, &m_matWorld, &g_Cam[iCurCam].GetViewMatrix());
g_pEffect->SetMatrixTranspose("matWorldView", &compMat);
D3DXMatrixInverse(&invMat, NULL, &compMat);
D3DXMatrixTranspose(&invMat, &invMat);
g_pEffect->SetMatrixTranspose("matWorldViewIT", &invMat);
D3DXMatrixInverse(&invMat, NULL, &g_Cam[iCurCam].GetViewMatrix());
D3DXMatrixTranspose(&invMat, &invMat);
g_pEffect->SetMatrixTranspose("matViewIT", &invMat);


VS

float3 N = mul((float3x3)matWorldViewIT, vNormal); //normal in view space



I'm not sure about how matWorldViewIT is defined and used :
From the main code one can see : matWorldViewIT=(World*View)^-1 (I don't take into account transpositions)
This matrix transforms something in view space into object (local) space but the normal (at least at the end of the rendering pipeline) is expressed in world space.
It should be something like that :

float3 N = mul((float3x3)matWorld, vNormal); //normal in world space


If you really want to express your normal in view space (this is totally possible, for example when one wants to pack normals as 2-components vector in a G Buffer) :

float3 N = mul((float3x3)matWorldView, vNormal); //normal in view space


Another little thing :

D3DXMatrixTranspose(&invMat, &invMat);
g_pEffect->SetMatrixTranspose("matWorldViewIT", &invMat);

is similar to :

g_pEffect->SetMatrix("matWorldViewIT", &invMat);


Hoping that might help a little wink.png

Topic Locked

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

Sign in to reply to this topic.