Set custom project matrix in Camera

Discussion of proposed new features.

Set custom project matrix in Camera

PostPosted by godan » 20 Aug 2016, 18:20

Small request: implement a SetCustomProjectMatrix(Matrix4 mat) function in the Camera class. From what I can see, only various SetFOV and SetNearClip methods are exposed.

For my recent investigations in VR, this is would be a pretty handy function to have.
User avatar
godan
Active user
Active user
 
Posts: 122
Joined: 23 Sep 2014, 20:28

Re: Set custom project matrix in Camera

PostPosted by godan » 20 Aug 2016, 18:22

To clarify, the use case here is for reading the left and right eye projection matrices from the device and forcing them on to the cameras. So this function would be called during Update.
User avatar
godan
Active user
Active user
 
Posts: 122
Joined: 23 Sep 2014, 20:28

Re: Set custom project matrix in Camera

PostPosted by Egorbo » 20 Aug 2016, 18:53

You can extract FOV, FarClip, NearClip, aspectRatio from your custom projection matrix and feed them to Camera without that additional method.
User avatar
Egorbo
Have some posts
Have some posts
 
Posts: 23
Joined: 21 Sep 2015, 22:24

Re: Set custom project matrix in Camera

PostPosted by godan » 20 Aug 2016, 19:23

Yep, but it's a hassle :)

Since in my case, I'm getting a Matrix4 directly from the device, it seems much easier to simply set the private variable "projectionMatrix_" via a SetProjectMatrix method. No math needed.... Don't get me wrong, I can certainly find a work around for now. However, I think it's simple enough fix that would make this sort of application a lot easier.
User avatar
godan
Active user
Active user
 
Posts: 122
Joined: 23 Sep 2014, 20:28

Re: Set custom project matrix in Camera

PostPosted by Egorbo » 20 Aug 2016, 19:25

Make sure your matrix is left-handed ;-)
PS: you will have to extract those values anyway in that SetProjectMatrix method, otherwise other components/code with some logic based on camera->GetFOV\camera->GetFarClip etc will get wrong values (default).
User avatar
Egorbo
Have some posts
Have some posts
 
Posts: 23
Joined: 21 Sep 2015, 22:24

Re: Set custom project matrix in Camera

PostPosted by cadaver » 20 Aug 2016, 20:24

This can be done, but IMO it should be done in a raw way, no new state or "useCustomProjection" flag but you simply set it, and if you change any of the standard parameters like FOV or near clip, your custom matrix is lost. Also you must take care yourself of D3D / OpenGL differences, since the final matrix would be different for both of them due to different depth range.
User avatar
cadaver
Urho3D author
Urho3D author
 
Posts: 1802
Joined: 16 Jan 2014, 14:52
Location: Finland

Re: Set custom project matrix in Camera

PostPosted by cadaver » 20 Aug 2016, 21:22

Hm, now that I think of this more, it has potential to make some things not work so well, so I lean on not adding it after all. I also remember that I've possibly thought of it before. :) For example OpenGL texture rendering needs to flip the projection vertically, which would under the simple scheme I outlined in the last post, just overwrite the custom set matrix. Also screen ray calculation and occlusion software rendering need the projection matrix too, but it's always for the D3D-like depth (from 0 to 1) so an OpenGL matrix would produce incorrect results there, and then you might wonder why screen picking or occlusion doesn't work as you expect.

In short I don't plan to spend energy on this now. A cleanly implemented PR that avoids these shortcomings would be welcome though, as usual.
User avatar
cadaver
Urho3D author
Urho3D author
 
Posts: 1802
Joined: 16 Jan 2014, 14:52
Location: Finland

Re: Set custom project matrix in Camera

PostPosted by Egorbo » 20 Aug 2016, 21:44

I guess we can add a method smth like this:

Code: Select all
void Camera::SetProjection(const Matrix4& projection)
{
  //TODO: calculate values
  //calculation depends on DX\GL and LH\RH coordinate systems

  //for example, this is how fovY is calculated:
  float fovY = 360 * atanf(1 / projection.m11_) / M_PI;

  SetAspectRatio(apect);
  SetFov(fovY);
  SetNearClip(nearClip);
  SetFarClip(farClip);
}
Last edited by Egorbo on 20 Aug 2016, 23:25, edited 1 time in total.
User avatar
Egorbo
Have some posts
Have some posts
 
Posts: 23
Joined: 21 Sep 2015, 22:24

Re: Set custom project matrix in Camera

PostPosted by cadaver » 20 Aug 2016, 21:57

Doing it that way would also ensure the frustum is kept correct.
User avatar
cadaver
Urho3D author
Urho3D author
 
Posts: 1802
Joined: 16 Jan 2014, 14:52
Location: Finland

Re: Set custom project matrix in Camera

PostPosted by Egorbo » 21 Aug 2016, 12:42

BTW, in my case a device returns me a projection matrix with some fields that Urho3D Camera doesn't use. For example - skew (m01).
User avatar
Egorbo
Have some posts
Have some posts
 
Posts: 23
Joined: 21 Sep 2015, 22:24

Next

Return to Feature Request

Who is online

Users browsing this forum: No registered users and 1 guest

cron