Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

View Transformation + Projection Transformation calculation method


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 lucky6969b   Members   -  Reputation: 359

Like
0Likes
Like

Posted 06 August 2012 - 11:49 PM

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, 07 August 2012 - 01:06 AM.


Sponsor:

#2 lucky6969b   Members   -  Reputation: 359

Like
0Likes
Like

Posted 07 August 2012 - 12:28 AM

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.

#3 Tournicoti   Members   -  Reputation: 491

Like
0Likes
Like

Posted 07 August 2012 - 04:20 AM

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 Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS