Note that there are some explanatory texts on larger screens.

plurals
  1. PODirect3D WVP Stretching issue
    text
    copied!<p>I've been working on my own 3D Engine using Direct3D. This went pretty good, until I ran into an issue with the World View and Projection Matrices. I'am using code from previous projects that I worked, but doesn't in the project. So I decided to use the Direct3D functions D3DXMatrixLookAtLH and D3DXMatrixPerspectiveFovLH.</p> <p>This gives a working matrices, but if by rotating or translating the camera I move geometry close to the edge of the screen, it stretches that entire object in the horizontal axis, now i'm not sure if this is correct or not.</p> <p>Cube in the middle of the screen looks normal: <img src="https://i.stack.imgur.com/38d4T.png" alt="Normal Cube"></p> <p>But if I move it to the side it starts to stretch: <img src="https://i.stack.imgur.com/7nfSN.png" alt="Stretched cube"></p> <p>This is the View matrix that I get in such a case:</p> <pre><code>-0.81964797 -0.017183444 -0.57260966 0.00000000 0.00000000 0.99954993 -0.029995499 0.00000000 0.57286739 -0.024585750 -0.81927919 0.00000000 -1.1457349 0.049171507 1.6385586 1.0000000 </code></pre> <p>I also noticed that between the WVP matrix in the application and the matrix the shader receives it gets transposed. ( I use memcpy to get it in the CBuffer, so that shouldn't be the problem) This is not a major issue, I just transpose it before it gets send, but I would like to know if this is common.</p> <p>this is my shader:</p> <pre><code>cbuffer WVP :cb0 { float4x4 WVP; }; struct VOut { float4 position : SV_POSITION; float4 color : COLOR; }; VOut VShader(float3 position : POSITION, float4 color : COLOR) { VOut output; output.position = mul( float4(position, 1.0f), WVP); output.color = color; return output; } float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET { return color; } </code></pre> <p>This is the code in that happens every frame to update the View matrix according to input:</p> <pre><code>// reset the vectors so the changes don't stack vcPos.Set(x, y, z); vcDir.Set(0.0f, 0.0f, -1.0f); // Rotate the dir vector Matrix3D m; m.Rota(Looky/100, 0.0f, Lookx/100); vcDir.RotateWith(m); // add the pos to the dir vector so it points to in a direction rather then a point in the world vcDir += vcPos; // Set and get the View matrix g_pDevice-&gt;SetViewMatrix(vcRight, vcUp, vcDir, vcPos ); g_pDevice-&gt;GetViewProjMatrix(&amp;g_mView, NULL); // Multiply them g_mWVP = g_mWorld * g_mView * g_mProj; // Transpose them so the shader tranposes them back. Transpose(&amp;g_mWVP); </code></pre> <p>And this is the behind the scenes part of it:</p> <p>View:</p> <pre><code>D3DXMatrixLookAtLH(&amp;m_mView, &amp;D3DXVECTOR3(vcPos.x, vcPos.y, vcPos.z), &amp;D3DXVECTOR3(vcDir.x, vcDir.y, vcDir.z), &amp;D3DXVECTOR3(vcUp.x, vcUp.y, vcUp.z)); // The .x/.y/.z has to do with some compatability stuff </code></pre> <p>Proj:</p> <pre><code>D3DXMatrixPerspectiveFovLH(&amp;m_mProj, FOV, Aspect, m_fNear, m_fFar); // Straight forward D3DXMatrixPerspectiveFovLH(&amp;m_mProj, 90.0, Aspect, 0.1f, 100.0f); // With values </code></pre> <p>Update2: Complete rewrite with new information</p> <p>Update3: I'm having problems with the View matrix and maybe the Projection. The World matrix works fine.</p> <p>Update4:</p> <p>After changing some more code, I now have something that seems to be working! The only Problem I have right now is the stretching to the side.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload