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.
Can anyone help me to fix this issue?
↧