Switching cameras using SAO pass

I have a scene using EffectComposer and an SAO pass, and UI to allow the user to switch between orthographic and perspective cameras. What is the recommended way of changing the camera that SAO uses?

If I just set SAO’s camera property to the new camera, there are a number of fields that are left with values referencing the old camera, for example:

saoMaterial.defines[ 'PERSPECTIVE_CAMERA' ]
and
saoMaterial.uniforms[ 'cameraProjectionMatrix' ].

Running the setSize method appears to fix things, but there are a number of fields that remain incorrect. For example, it resets the second property above, but not the first. Not sure if that matters. setSize also, well, sets the size, of all of the render targets, so it seems like it’s a little more (and less?) than needed. I have created my own method on a custom version of the pass that resets all of the camera related properties, but I’m wondering if I’m missing something. Thanks!

When switching the camera, you have to manually update the uniforms cameraProjectionMatrix and cameraInverseProjectionMatrix. As you have mentioned correctly, both uniforms are automatically set when SAOPass.setSize() is called.

And yes, it’s necessary to update the define PERSPECTIVE_CAMERA which is essentially a boolean. 1 is it’s default value which means you want to render with a perspective camera. For orthographic cameras, you have to set 0. Unlike the uniform values, you then have to set the needsUpdate flag of saoMaterial to true since a change of defines requires a new shader compilation.

1 Like

OK, thanks for confirming I wasn’t missing something! Would it be worth adding a method to wrap up what needs to happen when switching or updating the projection matrix of a camera? I realize there’s a reason the effects are in the examples folder, but it does seem generally useful.

Well, no post-processing passes provide an API to support camera switching so far. Probably because it’s not that common. Hence, it would leave it as it is until more user run into this issue.

Yep, ok. Thanks!