Jump to content
  • Advertisement
BlackJoker

DX11 How to render with Matrix.PerspectiveOffCenterLH

This topic is 450 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

Hi,

I am trying to render my 3d object in exact screen space coordinates with correct shading.

I tried for this orthoOffCenterLH matrix, but it produces strange render results (object in front part in disappearing and appearing during rotation). I think it because of nature of ortho projection (but maybe I am wrong).

I want to correctly display my 3d object like when I render with perspective projection. 

To achieve this I tried to use PerspectiveOffCenterLH matrix, but when I apply it, I can see nothing.

Here is parameters I pass to the method:

PerspectiveOffScreenProjection = Matrix4x4F.PerspectiveOffCenterLH(0, Width, Height, 0, 100, 1);

ZFar and ZNear are flipped because I am using reversed depth buffer.

And here is how I build matrix itself

public static void PerspectiveOffCenterLH(float left, float right, float bottom, float top, float znear, float zfar, out Matrix4x4F result)
      {
         float zRange = zfar / (zfar - znear);

         result = new Matrix4x4F();
         result.M11 = 2.0f * znear / (right - left);
         result.M22 = 2.0f * znear / (top - bottom);
         result.M31 = (left + right) / (left - right);
         result.M32 = (top + bottom) / (bottom - top);
         result.M33 = zRange;
         result.M34 = 1.0f;
         result.M43 = -znear * zRange;
      }

Also I render it without View matrix to fix object position and dont let it move somewhere.

 

Also if I flip Znear and ZFar back on their places, it will resnder distored like on first screenshot, but it should render like on the second screenshot

 

Can anyone help me to fix this issue?

distorsion.png

correct.png

Edited by BlackJoker

Share this post


Link to post
Share on other sites
Advertisement

Ok, seams ortho projection was enough and I just passed incorrect znear/zfar. I thought that max zfar could be 1, but obviously I was mistaken. 

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!