The short answer is that true depth of field on translucency in real time computer graphics is an unsolved research problem.
The versions we have implemented in UE4 are screen space effects that rely on a single depth value per-pixel. That works great for opaque and masked materials but translucent materials do not write depth values.
Usually translucency is blended on to the scene before depth-of-field is computed resulting in the translucency being blurred as if it were at the same depth as the background opaque layer on to which it was blended. That’s the result you get in UE4 if you disable Separate Translucency on the material.
Separate Translucency is a feature that blends certain translucent objects on to the scene after depth-of-field has been calculated. That prevents the artifact but those translucent materials will not be affected whatsoever by depth-of-field.
So what will be your suggestion to make scene for 2D platform game that use textures with alpha? What material should I use to have proper alpha from textures and depth of field? One of the textures that I use is here:
I can pre-blur texture in Photoshop, but that will be tricky to get proper DoF on each scene where I need about 5 layers in parallax (as background). So is there a way, how add blur effect to specific translucent material and change amount of it in realtime?
I would use the DepthOfFieldFunction material expression in your material to approximate depth-of-field yourself. That node generates a value of 0 when the pixel should be completely in focus and a value of 1 when it should be out of focus.
The simplest thing you can do there is to mip bias your texture lookups making them blurrier. You would do that by setting the MipValueMode of the texture sample in the material editor to “MipBias” and then connecting the result of depth of field function to the MipValue input pin. You can multiply up the result of the DepthOfFieldFunction to control how blurry the texture is when out of focus.
You could also fade between an in-focus texture and out-of-focus texture that has been pre-blurred in an application like Photoshop. That will let you use a nicer filter for blurring the texture than the box filter used to generate mipmaps.
More info:
–
After writing this up I did a quick test and noticed that the DepthOfFieldFunction expression is not working correctly! I’ve filed bug UE-7950 to get that fixed up.
In the meantime, you can use the PixelDepth node to fade between in-focus and out-of-focus depths to blur your textures. If you set your in-focus and out-of-focus depths using a Material Parameter Collection you can access them easily from any material.
turning off separate translucency in the project settings will allow translucence to be blurred mathcing the corresponding dof settings, but unfortunately will not allow animated dof from - ie sequencer - to control it ie with dof keyframes
If anyone knows how to control dof on transparencies, possibly within sequencer; would be much appreciated…