Apply post processing effects to a subset of objects

Hello everyone, I would like to apply an unreal bloom effect to a subset of elements of my scene.
Reading around it seems it could be possible to render different scenes with different post processing effects using masking provided by the MaskPass.js.

I’ve followed this example https://threejs.org/examples/#webgl_postprocessing_masking and created a plunk with two scenes, one with a cube and one with a sphere.
I would like to apply the bloom effect only to scene1, leaving scene2 uneffected (but still rendered).

This is the plunk: https://plnkr.co/edit/Y1IbNIkgHV8buph6TkBB?p=preview

At the bottom of the code there are two functions:

  • addPasses: renders both scene1 and scene2 with the bloom effect
  • addPassesWithMasking: should render scene1 with bloom effect and scene2 without effects, but it is not working

Can someone share some light on what I am doing wrong? The example uses TexturePass to render textures, here I am using RenderPass, could be the problem?

I’m don’t think the usage of masking makes sense here. You could create a pass chain like presented in the following code snippet but that produces only a acceptable result with wireframes. If the sphere is rendered in normal mode, you will see that the bloom effects gets lost when the cube is in front of the sphere.

composer.addPass(clearPass);
composer.addPass(renderPass1);
composer.addPass(bloomPass);
composer.addPass(renderPass2);
composer.addPass(outputPass);

Update Plunker: https://plnkr.co/edit/mKyWyMIwgjj89GuSdPgF?p=preview

A more promising approach is maybe to blend the bloom pass on top of the normal beauty pass (the objects without bloom). But I’m not sure if you can use UnrealBloomPass in this context or if you have to adjust the code.

1 Like

Thank you @Mugen87! What do you mean by “sphere is rendered in normal mode”?
It seems your code is working fine:
48 51

Also I am not sure what is the use of the MaskPass, I though it can be used to apply effects only for objects included in the mask, is this incorrect?

I mean the following. Notice, how the bloom is missing where the lines cross the sphere geometry.

The problem is that a mask produces a hard border which does not allow the bloom effect to fade out or glow.

1 Like

Oh I see!
Generally speaking, is this the correct approach to mix different shader effects (for different objects) in the same scene? Apologies, I am not very much in 3d graphics, trying to learn

No. Like I said before, blending different rendering results together might be a more promising approach. But the “correct” solution is always use case specific.

Ok, is there any example around where this kind of renders blending is used?

You might want to study how the new SSAOPass works (available with R99). It blends the calculated ambient occlusion on top of the rendered scene.

Ok I will check it, thank you very much!