Dynamic Camera Projection Matrix

Hello, I am brand new to the forum (and Babylon) so there is a lot I still have to learn.
Bear with me if this is an easy implementation; I read through all of the Camera docs and didn’t find the answer.

How can I apply my own projection matrix to a camera? I need to seamlessly blend between orthographic and perspective, as seen in this image from this wikipedia page:

Dynamic Projection

I will need to update the projection per frame when transitioning between ortho and perspective, in case that impacts the answer.

I made rather hacky and poorly optimized proof of concept in this playground:

Dynamic Projection Matrix

Any improvements are welcome, I’m just glad that it “works”.


This is great :slight_smile:

The other possibility is to create you own camera inheriting from the choosen camera type and override the getProjectionMatrix function

The “official” way to change the projection matrix is to call:


Looks similar to Camera.fov, but that does it in both horizontal & vertical, I think. That is good for fish eye in one direction & 120mm (0.265103 radians) zoom for close up without distortion.

Note to future, forget trying to do any projection matrix manipulation for a WebXR camera. Every frame, the device is responsible for providing the matrix for each screen.

Edit: I actually have a scene which does fov animation, here. Zoom out is not the only scene transition, I have. The transition is chosen by random, so just reload a couple of times till you get the zoom out.

this was fun to learn how matrix works:

an ortho and a perspectiveFov…

…scale on the cosine!


Then, manually sets matrix values BABYLON.Matrix.FromArray([])… Like! : )

Which applies to… camera.getProjectionMatrix().setRow(!?!) :wink:

and helps to understand camera.freezeProjectionMatrix(newMatrix?)

I did not know any of that was possible. : ) Will look next time, stepping into, a freezing matrix… thanks!

Also… the easter-egg-babylon-icons (somewhere) (one of those playgrounds), was fun to find. : )

Thanks everyone, I will definitely polish this up and implement those more efficient / official methods.

This is not just a zoom in/out that I’m striving for, but a very specific need to move from “Flat” to “3D” in a seamless and smooth way. The transition must be animated per frame to achieve the blending.

I am very interested in ways that this could be achieved as shown here, but with WebXR compatibility.

I’m guessing that some can already guess why the blend from flat to 3D would be desirable.