Understanding the focus parameter for BokehPass

Hello! I’m trying to apply a BokehPass to create a depth of field effect. I have the focus set on 5 for example. If I understand correctly, from what I see, everything from a distance of 5 is focused. Anything further and closer are blurred.

However, what I’m trying to achieve is that everything is focused within a range. I have set focus to 5, but I don’t want my object to be blurred when it’s closer than 5 blocks in range, the blur should be applied on a distance of 5 and further, anything with a distance between 0 and 5 should be focused.

Is this achievable? Or perhaps I need something different than BokehPass, but I haven’t found anything as of yet, so any help is welcome!

You can’t use the Bokeh shaders of three.js for you intended visual result, sorry. Simply because a proper depth of field effect does not work the way you have mentioned.

However, you should be able to achieve your result if you change this line in BokehShader:

to:

vec2 dofblur = vec2 ( clamp( factor * aperture, -maxblur, 0.0 ) );",
1 Like