Depth of Field with BokehShader2, preserve alpha

Hello everyone,

I am trying to implement depth of field with transparent background.
It is possible to achieve using BokehShader.js and commenting out one line described in this topic:https://discourse.threejs.org/t/is-there-a-way-to-set-clearpass-on-bokehpass/14615/3.

I would like to use BokehShader2,but i always get black background.
It there a way to use BokehShader2 and have transparent background?

Thanks for any help :wink:

Notice that this is conceptually problematic. Iโ€™ve explained the reasons for this here:

1 Like

Background color bleeding through is desired outcome so thatโ€™s not a problem for me :slight_smile:

I have not tested this but I assume you have to change this line in BokehShader2.

to

gl_FragColor.a = texture2D(tColor, vUv.xy).a;

Besides, the color render target must be in RGBA format.

Thanks for the reply!
Sorry for following up so late, i was swamped with other stuff.
With the change you proposed the background is transparent but i get this kind of result.
The blurring is exaggerated to make it super obvious.

Areas where spheres overlap are blurred as expected. However, edges of the spheres that are in front of background are not blurred at all. Do you have any tip how to fix this?