Add vertical shift to 3ds max exporter / babylon camera's

In regard to this post i made.

I would be nice if we can apply the vertical shift to a camera in babylon since we would like to use this feature to match the canvas with renders from 3ds max.

Thanks in advance!
Axel

Adding @drigax and @Guillaume_Pelletier

Interesting! I wasnā€™t aware of this camera setting. I donā€™t think our cameras currently support this without adding some extra math to our view projection calculation logic, do you know @sebavan or @Evgeni_Popov? Also is there a significant difference in 3dsMax between shifting the camera and translating it?

1 Like

Hi, so here is what happens in max when you turn on the vertical shift of a camera.

my scene looks like this when the vertical shift is turned off:


As you can see on the left the camera is at eye height and looking up at the ā€˜buildingsā€™, on the right is what the camera sees. There Iā€™ve drawn some lines on it to make it clear that the vertical lines are not going perfectly straight up.

Now here is the same view with the vertical shift turned on:


as you can see here the lines do go perfectly up which is not realistic to be clear, but it just looks better for architectural renders.

Iā€™m also not sure how it exactly works in 3ds max but i you can see the camera is looking straight ahead instead of at its target.
Schermafbeelding 2021-01-15 081138 This is what the camera now sees but it only shows the green as the camera viewport.

This is very different from just translating the camera as you would have to move the camera to the vertical center of the buildings which isnā€™t an option in our case.

Thanks for the quick replies, i hope this explanation helps! (also sorry for posting 3 answers but i can only put 1 image per post)

1 Like

I donā€™t think either, as it seems it is a tilting of the projection plane. Not sure how to do thatā€¦

Hi,

Is there any progress on the implementation or investigation into this feature?
Weā€™d really like this feature as itā€™s a common technique in architectural renderings.
Also itā€™s supported in all main 3D software packages, like max, maya, blender, etc.
Here is a short video on youtube which explains the technique used in blender.

Here is a preview of what this would look like in 3dsMax

Would be great to be able to use this feature in our future projects.
Please let me know if you need any other additional info on this topic.
Thank you
Pieter

Hi!

Has there been any consideration on implementing this feature?
We are very excited to start using babylon!

Kind regards

Thanks for the reminder. I created this issue to track this feature: Add camera lens shift Ā· Issue #10119 Ā· BabylonJS/Babylon.js Ā· GitHub

However I donā€™t believe that the team will be able to implement this quickly, if youā€™re waiting on this feature. Often with such specialized asks, it may be easier to implement this on our behalf, weā€™re always happy to accept a PR :slight_smile:

Iā€™m on it :+1:

2 Likes

you are the best

2 Likes

This PR implements what you need. It is still to be reviewed, but once it is merged, you will be able to use camera.applyVerticalCorrection() or camera.projectionPlaneTilt

Iā€™ll post the maths I used below as an FYI

2 Likes

Letā€™s just set ourselves in the camera view space. In BJS left-handed convention, Z is forward in the look direction, X is right and Y is up. (On the drawing, X is toward us)

Here on the drawing, projection plane untilted is AC. Projection plane tilted by angle alpha is EF. Camera is B on the left

By definition, a perspective projection projects every point P in the scene on the projection plane (here lying at Z), along the direction BP, thatā€™s the pinhole model. We get the projected point G by dividing Pā€™s coordinates by P.z, the z coordinate, with a projection matrix :

        (
            a, 0, 0, 0,
            0, b, 0, 0,
            0, 0, c, 1,
            0, 0, d, 0
        )

The 1 in the last column allows us to get this division when we normalize homogeneous coordinates with w.

But in our case, we want to project on the tilted plane directed by EF to get H, and still along the direction BP. For that, we want to find the z-coordinate of H, written as z on the image. For this we just need a bit of geometry :

As similar triangle, we have Y / Z = y / z, so y = Y * z / Z
With some trigonometry in the triangle HIO, we get : z = Z - y * tan(alpha)
We replace with above : z = Z - Y * z * tan(alpha) / Z.
Grouping z together : z = Z / (1 + Y * tan(alpha) / Z)

Now we are ready to use Pā€™s coordinates (Px, Py, Pz) :
As similar triangles, Py / Pz = Y / Z, so Y = Py * Z / Pz

We replace : z = Z / (1 + Py * tan(alpha) / Pz).

Now, perspective projection is about multiplying every coordinate of P by the same thing to get Pz => z, so here, we are going to multiply everything by z / Pz, hence :

Px
Py
Pz  
=> 
Px * Z / (Pz + Py * tan(alpha)), 
Py * Z / (Pz + Py * tan(alpha)), 
Pz * Z / (Pz + Py * tan(alpha))

In matrix form, this new transformation is :

        (
            a, 0, 0, 0,
            0, b, 0, tan(alpha),
            0, 0, c, 1,
            0, 0, d, 0
        )
3 Likes

Thanks for the update, and the progress on the implementation.
Canā€™t wait to try this out.

Is the new feature already implemented in the latest build?
Did you add a difference between vertical shift and vertical tilt?
Iā€™m no expert in Mathematics so I canā€™t really say if your math model will work in our case.
However a vertical tilt correction will skew the image back into a straight lined image.
While a vertical shift will pan the view UP/DN or left/right.

We would like to achieve this with the vertical shift option, as this gives us a cleaner result in our renderings.

Looking forward to test this feature asap.
Thanks for the work on this!

Pieter

@Pieter_van_Stee yes it looks like itā€™s been available since 5.0.0-alpha.29

And hereā€™s the example PG from that PR https://playground.babylonjs.com/#L20FJ4#15

2 Likes

Hi Inteja,

Indeed, I can find the ā€œprojectionPlaneTiltā€ option under the camera options.
However, we started our request for a vertical shift (just panning the world or the view behind the camera) as described above.

This gives a slightly different outcome, is this also possible to add to the camera properties?
If it already is possible please let me know how to do this.

Thanks
Pieter

Iā€™m not sure I understand what you mean sorry. Does the linked PG not do what you want?

Hereā€™s another one but this updates the camera continually https://playground.babylonjs.com/#L20FJ4#18

Iā€™m not sure if this is the best way to do it though.

Thank you for your reply.
I will make a screenrecording about this to make it easier to understand.
Can probably share this later this week.

Pieter