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.
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.
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.
//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 */
oldCamera.detachControl(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) {
defaultPipeline.addCamera(scene.activeCamera);
defaultPipeline.removeCamera(oldCamera);
}
besides,what to do when creating additional post-processing
PostProcessē±»å
//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;
camera.attachPostProcess(horizontalBlur);
oldCamera.detachPostProcess(horizontalBlur);
}
SSAO2
// when created SSAO2
ssao2 = new SSAO2RenderingPipeline("SSAO2RenderingPipeline", scene, 1);
// Attach camera to the SSAO render pipeline
scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(
"SSAO2RenderingPipeline",
scene.activeCamera
);
//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
scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(
"SSAO2RenderingPipeline",
oldCamera
);
}