Jump to content

  • Log In with Google      Sign In   
  • Create Account


Inverted Projection / Rendertarget Problems


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
5 replies to this topic

#1 Carandiru   Members   -  Reputation: 212

Like
0Likes
Like

Posted 04 January 2007 - 01:29 PM

Ouch this problem is absolutely confusing, and I'm hoping either someone has run into the same problem or can atleast help me out a little bit. Basically we have a render target setup with orthographic projection. D3DXMatrixOrthoLH( &const_cast<D3DXMATRIXA16&>(m_matProjOrthoRTx512), 512, 512, -5000.0f, 5000.0f ); Next Step is Rendering a Terrain Patch Mesh to the The RenderTarget that is of 512x512, the Terrain Patch is 64x64 Vertices, and is scaled to the rendertarget resolution. 64 'x' vertices by 64 'z' vertices where height is represented by 'y'. So the default view of the orthographic projection is looking to into Z, not down onto y like we would typically use for viewing the terrain patch TOP DOWN. D3DXMatrixTranslation(&matModel, 0.0f, 0.0f, 0.0f); D3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(90.0f), D3DXToRadian(0.0f), D3DXToRadian(90.0f)); D3DXMatrixRotationQuaternion(&matRot, &qR); D3DXMatrixScaling(&matScale, RT512/RT64, RT512/RT64, RT512/RT64); D3DXMatrixMultiply(&matModel, &matRot, &matModel); D3DXMatrixMultiply(&matModel, &matScale, &matModel); // Final Model View Projection Matrix // D3DXMatrixMultiply(&matModelViewProj, &matModel, &m_matProjOrthoRTx512); So I made these key points to show that I have to orient the model to compensate for this. The Problem: Its Inverted!!!!! How on earth it is inverted, I'm trying to figure out. It seams like a mirror image of the same terrain patch rendered normally on the main screen. If I orient the "pitch" +-90 degrees, it fixes X from being inverted but Z is still inverted, and vice versa it fixes z from being inverted, but x is still inverted (mirrorred). So this is rather confusing. I've tried D3DXMatrixOrthoLH( &const_cast<D3DXMATRIXA16&>(m_matProjOrthoRTx512), -512, -512, -5000.0f, 5000.0f ); D3DXMatrixOrthoLH( &const_cast<D3DXMATRIXA16&>(m_matProjOrthoRTx512), -512, 512, -5000.0f, 5000.0f ); D3DXMatrixOrthoLH( &const_cast<D3DXMATRIXA16&>(m_matProjOrthoRTx512), 512, -512, -5000.0f, 5000.0f ); No avail, still run into the same roadblock of being able to fix one corner of the patch, but either x xor z is still mirrored. And with several different combinations of 3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(-90.0f), D3DXToRadian(0.0f), D3DXToRadian(90.0f)); 3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(90.0f), D3DXToRadian(0.0f), D3DXToRadian(-90.0f)); 3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(-90.0f), D3DXToRadian(0.0f), D3DXToRadian(-90.0f)); 3DXQuaternionRotationYawPitchRoll(&qR, D3DXToRadian(90.0f), D3DXToRadianD3DXToRadian(-90.0f), D3DXToRadian(90.0f)); Where some of them don't draw the mesh due to the fact that its is looking "under that patch". Help me out, cause I've stared at this problem for far to long.

Sponsor:

#2 Carandiru   Members   -  Reputation: 212

Like
0Likes
Like

Posted 05 January 2007 - 12:17 AM

Geez could someone say something?

#3 Schrompf   Prime Members   -  Reputation: 950

Like
0Likes
Like

Posted 05 January 2007 - 12:30 AM

Have a closer look at the coordinate space section of the D3D documentation. As far as I know, the post-projected Y coordinate is growing down to up, being inverted in respect to the normal texture coord projection you might use. There's no way to achieve a inversion with rotations only. Maybe insert a D3DXMatrixScaling() into the beginning of your projection matrix.

Just guessing, sorry. I remember having that problem one time or the other, too, but I can't dig up the places in my source where I solved it. So it's only a vague hint.

Bye, Thomas

#4 Carandiru   Members   -  Reputation: 212

Like
0Likes
Like

Posted 05 January 2007 - 05:22 PM

Well I'm assuming this, but these seems to more of proper way of doing it, and makes more sense.

Rather than rotating the model, I'm just setting a look at matrix to do basically the same thing, but more "naturally".

D3DXMATRIXA16 matView, matProj;

D3DXMatrixOrthoOffCenterLH(&matProj, -RT256, RT256, -RT256, RT256, 0.0f, 5000.0f);
D3DXMatrixLookAtLH( &matView,
&D3DXVECTOR3(0.0f, 5000.0f, 0.0f),
&D3DXVECTOR3(0.0f, 0.0f, 0.0f),
&D3DXVECTOR3(0.0f, 0.0f, 1.0f) );

D3DXMatrixMultiply(&const_cast<D3DXMATRIXA16&>(m_matViewProjOrthoRTx512),
&matView, &matProj);

D3DXMatrixTranslation(&matModel, 0.0f, 0.0f, 0.0f);
D3DXMatrixScaling(&matScale, RT512/RT64, RT512/RT64, RT512/RT64);
D3DXMatrixMultiply(&matModel, &matScale, &matModel);

// Final Model View Projection Matrix //
D3DXMatrixMultiply(&matModelViewProj, &matModel, &m_matViewProjOrthoRTx512);

So I'm assuming this a more proper way of doing this. But really man, it still is inverted, changing the parameters to D3DXMatrixOrthoOffCenterLH be reversed, and negating the up vector in D3DXMatrixLookAtLH still gives me the same confusing problem.

Messing with these parameters gives me different mirrored combinations.

Mirrored X, Mirrored Z
Mirrored X, Correct Z
Correct X, Mirrored Z

But never:
Correct X, Correct Z

Mind bogling confusing. It is probably REALLY simple too I bet. If anyone can lend a helping hand I might just have to honor you as the bestest online buddy I've ever had!

:P

Thanks again,

#5 Carandiru   Members   -  Reputation: 212

Like
0Likes
Like

Posted 06 January 2007 - 05:35 AM

bump

#6 TheAdmiral   Members   -  Reputation: 1118

Like
0Likes
Like

Posted 06 January 2007 - 06:58 AM

Are you sure you're actually using a left-handed coordinate system? It sounds like you'd be better off using D3DXMatrixOrthoRH. This will flip the direction of your z axis, so you should be able to attain your 'Correct X, Correct Z'.

Admiral




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