How can I blend between perspective and orthographic projections

In Unity I could blend between projection and orthographic matrices by just setting up the two and blending between them. Just add a script to the camera, create both matrices and:

	for (int i = 0; i < 16; i++)
	{
		camera.projectionMatrix[i] = Mathf.Lerp(perspective[i], ortho[i], time);
	}

Works great.

How would I go about doing this in unreal? I tried doing the same thing in LocalPlayer.cpp but had no luck. The output just looked like perspective and would shake the closer I get to full ortho.

Is there a way to do this in the editor?

Any help would be appreciated.

Hi ahozaru,

I apologize for the delay in getting a response for you. Unreal Engine 4 does not have a built-in ability to smoothly transition between perspective and orthographic views. Both perspective and orthographic views in Unreal Engine 4 contain properties related to how they are treated by the camera and the viewport, and some of these properties are unique to their respective projection mode. In order to do this successfully, you would have to replace the perspective view with an orthographic view, but that would be an abrupt change instead of a smooth transition.

Hi, is this still the case? If it is, are there any plans to allow this kind of smooth transition?

Thanks

Hi Catweazle,

Unfortunately this is still not possible in UE4, and to my knowledge it is not something that we intend to support by default. As I mentioned previously, some of the properties for each of these projection modes are completely different, and the Engine is not able to blend between them because of this. It is theoretically possible to do a blend between views, but you would have to write the code for that yourself.

Hey,
Just chiming in to show interest in this being added in some way. Came here looking for the exact same thing. If anyone does happen to code this in the next day or 2 and wouldn’t mind sharing then that would be awesome. Or any ideas of how to fake the blend between the 2 projection modes, or mask it so it isn’t so adrupt. Not having this has really put a dampner on what I was hoping to achieve,

cheers

Hi Beddall,

We still do not have any plans to provide this functionality in the Engine. However, I have entered a request that we investigate a way to make this possible (UE-20394).

Hi ,

I’m not necessarily interested to have direct support from the engine to do a blend like the one in the question, but I’m looking for a solution just now and I can’t figure out how to fix it without modify the engine or at least use really in-depth and scarcely documented classes and functions.

Projection matrices are really different between orthogonal and perspective matrices and you can’t simply change the values exposed from the camera component to blend between the two of them.
The only way I can think is to change the projection matrix manually, but that’s not exposed in any way from the engine, as far as I know, so you should change the engine itself to do so, and it doesn’t seems trivial at all.

And even if you’d made this, there is the culling problem, you have to specify how to cull geometries in scene if you blend between two projection matrices, even just telling to the engine to not cull some geometry seen from a list of cameras (in this case the two you are using in blending), or at least disable it (that’s already possible obviously, but really that’s not what I want, it’s too inefficient).

So, I’m missing something when you say it’s theoretically possible to do that? Because almost everything is possible having the engine code, but it seems really infeasible…
And if that is really the only way to do this blend, can please give me some advice to understand how to achieve this? I’m really new to UE4 and I don’t really know it so well to know even where I can start.

Thanks!

Hi Totoro83,

As you mentioned, this is a non-trivial task to try to accomplish. You cannot simply lerp property values from one matrix to the other since, as you mentioned, the matrices are quite different. It would indeed require a lot of manual work to set up. It may be possible to do this in a custom class in a project, but I think if you really wanted to do this it would be best to add it into the Engine source code. It might even be possible to do it as a plugin that you could then make available on the Marketplace.

When I mentioned that it was theoretically possible to do this, that was really just a comment meant to indicate that it should be possible to accomplish this, but that it would require a great deal of effort to get it working. Unfortunately I do not have any information that I could provide to get you started.

I see, maybe I’m on another simpler solution in my specific case, but if I’ll continue in that direction I’ll evaluate the to publish a plugin in the Marketplace.

Thanks!

The way I achieved this was faking orthographic view in perspective mode, by using the “Calculating distance” formula on [this wikipedia article about Dolly Zoom][1]. Basically, pull away your camera a whole lot and then zoom in tight.

I was using a CineCamera object on a Camera Boom.

For perspective, I manually set a good boom length and focal length (which controls the FOV).

331881-1.png

Noted these values down and plugged into the formula to get the initial “width” (which may be different from your screen width).

Now for orthographic, I set a big value for boom length (eg. 80000) and plugged the above calculated width to get the FOV value, and set it into the camera.

(In this example, for perspective, I pass Boom Len as 1500, and for orthographic, I pass the earlier mentioned 80000)

For a smooth transition, you can hook Set Camera Projection Params up into a timeline.

(Adding more images here cause upload limit hit in main answer)

Here’s the effect:

331886-orthopersp-proto-trim-crop.gif

1 Like

I’ve added an answer for a hack of sorts to achieve this effect.

That look great! Convincing. Also a nice, clean implementation.

Thats a shame to hear, I would hope UE would do everything to compete with Unity’s capabilities.