-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unreal Bloom and Renderer Transparency issue #14104
Comments
In gl_FragColor = vec4( diffuseSum / weightSum, 0.1 );\n\ Remember, it is an example, so you are free to modify it. |
Thanks for the answer @WestLangley ! Any solution would help me a lot :) |
/ping @spidersharma03 |
I achieved to find a solution for this but I would like to know your opinion @spidersharma03 and @WestLangley.
|
Sorry, I have no opinion on this. |
Sorry @fire67 , was away for a few days. Yeah, what you have done seems correct. I didn't handle the transparency. |
No problem, thank you for the answer @spidersharma03 ! Do you have any idea where does this comes from ? |
@fire67 , Not sure actually. Do you have the changed code in some branch? I will try to take a look. |
@spidersharma03 No, unfortunately the code is not available on a branch. Do you want me to do it ? |
@fire67 @spidersharma03 hi, I tried to use your
please help, thanks. |
ok so the problem is caused by my setting: the changed shader works well actually, thank you very much @fire67 |
This comment has been minimized.
This comment has been minimized.
@fire67 Did you manage to get this working with the bloom keeping the colour of the object? As soon as I try to use the changed shader the bloom just goes pure white, rather than taking the object colour as before. I also tried disabling Any ideas?
|
I've been mulling this over for the past few days and decided to attempt a slightly different approach that takes the original (non-transparent) colour calculations, leaves them unmodified and then adds on top the new alpha calculations from @fire67 with a couple of minor tweaks to utilise the same weights as the colour calculations. I don't know if this is the right way to do it, and the calculations could probably be tidied up, but it works.
Previous approach (posted earlier in this issue): New approach combining original logic with updated logic posted earlier in the issue: |
Tidy things up a bit and it seems to work just as well:
I've noticed some little (single pixel) artefacts that appear once in a while but seem to be random or based on something that only occurs on some frames as they disappear on the next frame. Not sure if it's caused by the changes I made or something unrelated to this issue. |
I've done some more testing and can confirm that the artefacts that I was seeing are unrelated to Three.js and the changes that I made to the bloom shader, so that's good. |
/ping @spidersharma03 |
I will see the results with a colored scene and come back. |
@robhawkes , I see that you initialize the alphaSum to 0. Did you simply try making something like this::
|
@robhawkes , basically something like this::
I need to test it though |
Any idea if this exists for r3f or is there another way to achieve transparent background and bloom effect in r3f nowadays? |
Solution provided by @mbalex99 worked for me with r136 |
Typescript 🤢 |
Lovely! Could you share the JS version? 🤓 |
I'm sort of new here in the Three.js scene. How would you suggest might be the best way to share? As in, what's the preference? |
@mrdoob; I uploaded my reimplementation (JS version) in this gist: UnrealBloomPass.js. Should these changes be integrated into the original UnrealBloomPass and do a #14104 branch PR? |
Okay, i´ve found what happens -> the bloom alpha was finally fixed on 137.5 I´ve tested in 137.2 and 136.0 it worked (pasting the file on node_modules) it´s funny when something breaks an old thing fix just before the fix release :D Also, i wonder what setClearColor does? when i got it working with i described above or not, setClearColor does nothing always. |
I've decided to having a look at this issue since the PR #23356 does not work for me. Here is my branch with the suggested change from above: Mugen87@551e7b5
You can easily verify this by opening the following URL and set the bloom strength and radius to maximum. https://raw.githack.com/Mugen87/three.js/dev60/examples/webgl_postprocessing_unreal_bloom.html Looking at the suggested fix, a simple enhancement in the fragment shader is not sufficient. |
Hi, I've been using this tweak with const BLOOM_PARAMS = {
resolution: new THREE.Vector2(1024, 1024),
strength: 2,
radius: .65,
threshold: .85
}
const CAMERA_PARAMS = {
fov: 50,
pixelRatio: window.devicePixelRatio,
nearClippingPlane: .1,
farClippingPlane: 10000
}
this.#scene = new THREE.Scene();
this.#renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
format: THREE.RGBAFormat,
logarithmicDepthBuffer: true
});
this.#renderer.shadowMap.type = THREE.PCFSoftShadowMap;
this.#renderer.outputEncoding = THREE.sRGBEncoding;
this.#renderer.setPixelRatio(window.devicePixelRatio);
this.#renderer.setClearColor(0x000000, 0.0);
this.#shadowRoot.appendChild(this.#renderer.domElement);
this.#camera = new THREE.PerspectiveCamera(...Object.values(CAMERA_PARAMS));
this.#passes = {
render: new RenderPass(this.#scene, this.#camera),
bloom: new UnrealBloomPass(...Object.values(BLOOM_PARAMS))
}
this.#effectComposer = new EffectComposer(this.#renderer);
Object.values(this.#passes).forEach(pass => this.#effectComposer.addPass(pass)); Where I do wrong? Thanks! |
The issue is actually not fixed. Sorry for the confusion in this thread. Besides, I don't think the issue can be properly fixed since there is no way to correctly additively blend the bloom with a HTML background. I think we should close the issue and state that |
Thanks for the feedback! With |
Ok, the mix doesn't work. I'll stick to 128 + frag shader for now |
Ah i was so hopeful when i saw that this was fixed but maybe we are back at square one. I don't know much about modifying this library and the underlying WebGL tech but i've spent 10 hours trying to get background transparency working as it is essential to my use case. What changed from the previous versions that now break background transparency? What is it about RenderPass that handles background transparency with ease that breaks in UnrealBloom? I don't have the background to fully understand how to implement this, but the solution here seems simple as this allows bloom to work with WebGL, I just need to understand how to implement it with threejs.UnrealBloom https://stackoverflow.com/questions/53422916/how-to-draw-transparent-background-in-webgl-on-canvas |
+1 Why haven't we fixed this? What is the final solution? @mrdoob let's get something merged we have plenty of PRs and Gists in this thread but nothing someone can just import and use right now. |
Also what is up with the breaking changes from 127 to 128? Codepen: https://codepen.io/johnnyshankman/pen/MWGMqYZ I can't seem to figure out how to upgrade to 128 successfully. |
This remains open because no working, stable fix has been found. You might try https://github.com/pmndrs/postprocessing/, it may support bloom + canvas transparency. I'd recommend using the forums (https://discourse.threejs.org/) for help with the upgrade to r128. |
Voting again for closing this issue since I don't think it can be fixed, see #14104 (comment). |
The three version is 0.146.0 |
@Mugen87 Recently I tried to implement UnrealBloom in my app but encountered the same transparency problem. I came across this thread, seeing all attempts to modify the blur pass in the middle but none seemed to yield favorable results. After trying some experiments by myself, I suggest a new approach which basically doesn't need to modify UnrealBloom.js. I use the selective bloom example as a base. In the fragment shader of the final pass where the bloom texture and the screen texture is merged,
which is practically a simple additive operation, I replace it with the following.
The concept is fairly simple. I generate an alpha value for the final bloom texture by using its luminosity as a base (it can be something else other than luminosity, which is open for discussion). The final result is the original The actual result is fairly decent, at least according to my testings. Below are some screenshots using the same bloom parameters. As you can see, the default one with no transparency (i.e. black background) looks almost identical with the new approach using a HTML black background. The new approach also looks fairly decent on a pure white background, as well as a complex background. Of course, this is not a perfect solution. There is no perfect solution when there is no way to actually mix WebGL with HTML background with additive blending. At least, this is a fairly reasonable solution for those who really needs a transparent background. |
Wow, the result is amazing, congratz! |
Description of the problem
I am currently using the Unreal Bloom post with a transparent renderer.
Unfortunately, the Unreal Bloom pass doesn't seem to take in account the alpha channel of the coming texture when doing the blur and it apparently comes from
getSeperableBlurMaterial
in js\postprocessing\UnrealBloomPass.js.The fragment's alpha channel is always set to 1.0 which results in a complete removal of the previous alpha values when doing the additive blending at the end.
This is happening in the latest version of Three.js r92 and you can experiment about this issue using the Unreal Bloom example
The text was updated successfully, but these errors were encountered: