Effects of post-processing on the camera

  1. The default camera of the scene is a, and the post-processing effect is turned on. Add a new camera b, switch the camera to b, and the post-processing effect disappears.
  2. There are currently two cameras a and b in the scene. The default camera is a. After enabling the post-processing, switch the camera to b. If you delete the camera a scene, an error will be reported.

This is a problem related to post-processing that I am currently encountering. The steps to reproduce it are as above. Please help me to solve it.

1-1.when using DefaultRenderingPipeline


1-2. Declare camera in advance

new BABYLON.DefaultRenderingPipeline(“default”, true, scene, [camera1, camera2]);

  1. This is also the same problem as 1’s mechanism

Which PostProcessing is using?


If you cannot set up multiple cameras Try changing to the following form

scene.activeCamera = newCamera;
createYourPostPrecess() //using newCamera

1 Like

Why would you dispose of the camera? Are you creating multiple cams on the fly?
Else I believe the solution shared by @11128 (solution 1.2) is likely the best way to go.
That’s what I’m using in my scene and it works like a charm.

1 Like

@lxq100 any repro you could share in the playground ???

The solution is as follows:

//when created
defaultPipeline = new DefaultRenderingPipeline("DefaultRenderingPipeline",true,  scene,[scene.activeCamera]);

//When switching the camera, you need to switch the camera first and then change the post-processing camera binding

/**1.  detach camera to canvas */

/**2.   attach camera to canvas */
b.scene.activeCamera = camera;
camera.attachControl(canvas, false);

/** 3.  change the post-processing camera binding */
let defaultPipeline = scene.postProcessRenderPipelineManager._renderPipelines["DefaultRenderingPipeline"];
if (defaultPipeline) {

besides,what to do when creating additional post-processing


//when created
horizontalBlur = new BlurPostProcess(scene.id+"-HorizontalBlur",
    new Vector2(1.0, 0), filter.blurKernel, 1.0, scene.activeCamera);

verticalBlur = new BlurPostProcess(scene.id+"-VerticalBlur",
    new Vector2(0, 1.0), filter.blurKernel, 1.0, scene.activeCamera);
//when switching cameras
let horizontalBlur = scene.getPostProcessByName(scene.id+"-HorizontalBlur"),
    verticalBlur = scene.getPostProcessByName(scene.id+"-VerticalBlur");
let horizontalBlur = scene.getPostProcessByName(scene.id+"-HorizontalBlur"),
    verticalBlur = scene.getPostProcessByName(scene.id+"-VerticalBlur");
if (horizontalBlur) {
    horizontalBlur._camera = scene.activeCamera;


// when created SSAO2
ssao2 = new SSAO2RenderingPipeline("SSAO2RenderingPipeline", scene, 1);
// Attach camera to the SSAO render pipeline
//when switching cameras
let ssao2 = scene.postProcessRenderPipelineManager._renderPipelines["SSAO2RenderingPipeline"];
if (ssao2) {
    // Attach camera to the SSAO render pipeline
    scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline("SSAO2RenderingPipeline", scene.activeCamera);
    //detach camera to the SSAO render pipeline
1 Like