Sign in to follow this  
lucky6969b

View Transformation + Projection Transformation calculation method

Recommended Posts

[code]
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();
}

[/code]

VS
[code]
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
[/code]





*********** 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
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

[quote name='lucky6969b' timestamp='1344318546' post='4966912']
[code]
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);
[/code]

VS
[code]
float3 N = mul((float3x3)matWorldViewIT, vNormal); //normal in view space
[/code]
[/quote]

I'm not sure about how [b][i]matWorldViewIT [/i][/b]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 :
[code]
float3 N = mul((float3x3)matWorld, vNormal); //normal in world space
[/code]

If you [i]really[/i] 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) :
[code]
float3 N = mul((float3x3)matWorldView, vNormal); //normal in view space
[/code]

Another little thing :
[code]
D3DXMatrixTranspose(&invMat, &invMat);
g_pEffect->SetMatrixTranspose("matWorldViewIT", &invMat);
[/code]
is similar to :
[code]
g_pEffect->SetMatrix("matWorldViewIT", &invMat);
[/code]

Hoping that might help a little [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this