three-vr-postfx icon indicating copy to clipboard operation
three-vr-postfx copied to clipboard

conditional bloom

Open coderofsalvation opened this issue 10 months ago • 1 comments

Hi, Leon here from https://xrfragment.org. Thanks, and kudos for the bloom demo (the scifi room with the reactor failure). TBH I got a bit frightened when I realized the machine was about to explode lol...I was like: ohno which button should I press to stop it :)

I'm interested in having the bloom activate based on certain material-settings inside a glb (like emissive-values above 1.0 e.g.). It seemed like something like that was going on in the reactor scene. Could you be so kind to elaborate/advice on that?

coderofsalvation avatar Feb 26 '25 08:02 coderofsalvation

Thanks :-)

The UnrealBloomEffect is modelled after the UnrealBloomPass of three.js. It performs a luminance threshold to determine which pixels contribute to the bloom. This is done on an HDR buffer, so it can distinguish between brighter than normal pixels. Setting the threshold to 1.0 should leave only the emissive pixels.

const threshold = 1.0;
const effect = new UnrealBloomEffect(size, strength, radius, threshold);

There is one caveat, though. Lighting calculations can also cause pixels to exceed this threshold. So specular highlights will also cause bloom. Often times this is desired, but if you want full control and perform "selective bloom" that isn't currently implemented.

Technically there's nothing preventing this from working. In fact, I do plan on implementing it at some point. It's just difficult to come up with a convenient interface. Hard to beat just replacing a renderer.render(scene, camera) with effect.render(renderer, scene, camera).

mrxz avatar Feb 26 '25 09:02 mrxz