• Advertisement
Sign in to follow this  

View Transformation + Projection Transformation calculation method

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

If you intended to correct an error in the post then please contact us.

Recommended Posts


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 Edited by lucky6969b

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement