Switching postprocessing on and off dynamically

Hi there, I wondering if anyone has any guidance on the best way to handle switching post-processing effects on and off using the PMNDRS library

Currently, I am adding the following passes independently to the same effect composer.

RenderPass
Outline
N8AO
SMAA
Depth of field
Tone mapping

For visual/performance reasons I want to be able to toggle the N8AO, SMAA and depth of field on and off independently, I thought I could just set the relevant pass to enabled = true/false, but doing so seems to end up with an empty screen under certain combinations.

What is the preferred method to disable/enable multiple effects? If you disable say the 3rd one, does that break it because there is a “gap” in the array of effects?

Hello, have you been able to figure out how its done? I would be interested to see how you’re managing all these effects. I am still learning how to use the pmndrs postprocessing library and i am struggling to understand how to implement smaa alone

The recommended way to enable or disable effects on the fly is to prepare multiple EffectPass instances with the desired Effect combinations ahead of time and to enable or disable these passes as needed using Pass.setEnabled().

No idea why, but that is not in the documentation but rather the wiki area, which is why I didnt originally find it.

I don’t think I got very far with it as I got pulled off on to real work. I will revisit at somepoint, so I would be interested to hear how you get on.

Thanks for the reply! At the moment im struggling to implement SMAA on its own, so my current struggle is unrelated to this topic. But later on id like to be able to switch these effects on and off so i will have to come back to this.

Concerning the implementation of smaa, theres so much that i dont understand in the demo. Would you be able to help me in that regard ? heres a simple three js case that im using to learn how to use this library. Currently I have added selective bloom, but the next step is smaa CodeSandbox

Ey y’all… Post processing has been a bit finicky for me in the past…

Just wanted to contribute some of my understanding of how it works…

Each pass has to feed into the next pass, and this is done by having 2 buffers that ping pong… a post effect usually reads from one texture, then writes to the other, and then the buffers are swapped, and the output of the first pass, gets fed into the next pass…
And the last pass, either has a special flag that tells it to output to the screen, or, its fed into a “CopyPass” that copies the last buffer to the screen…

So if you just disable one pass, or remove/disable a pass on the end of the stack, sometimes that can mess up the order that the buffers are getting handed off, or sometimes one pass will render to an the wrong output and its contribution will get skipped.

I think the latest versions of postprocessing improve/automate this process a bit better, but it’s something to keep in mind if you see things like… a pass not appearing to contribute to the output, or the output not appearing, and similar…

If in doubt, you might want to set a breakpoint on the render method of EffectComposer and step through it to diagnose why your pass might be not getting rendered or whatnot…

I’ve encountered the same situation.The WebGLRenderer object init options can be vary between typical-render and postprocessing, like preserveDrawingBuffer, premultipliedAlpha, and so on.Those params , as i know, cannot change dymaniclly. Does that means to achieve ‘switch dynamiclly’, one have to create two renderers,append the two domElements into container, and switching between them(both render function and dom node visibility)?