Blur Shader for Universal Render Pipeline's 2D Renderer

Ok, got it working:

  1. Upgrade to Unity 2019.3.3f1
  2. Use the package manager to upgrade “Universal RP” to 7.2.1 (or 7.3.1 now)
  3. To avoid the “the renderer used by this camera doesn’t support camera stacking”, in the project, open Universal RP/Runtime/ScriptableRenderer.cs and change ~line 36 to public bool cameraStacking { get; set; } = true; /* false originally! */ (see Camera stacking for URP page-2, post by “NotEvenTrying”).
  4. Change your main camera (rendering the foreground) to rendertype “overlay” (it’ll be rendered on top of the background).
  5. Add a layer “BackgroundLayer” and assign everything in your scene which is in the background to be in this layer.
  6. Let the main camera render everything, except the “BackgroundLayer” using the “culling mask”
  7. Make sure this one is not rendering post-effects (in my case resulted in broken graphics)
  8. Add another camera “Background camera” to your scenegraph as a child of the main camera) with rendertype “Base”, set position and rotation to 0,0,0, match size/clipping planes values with those of the main camera.
  9. Let the "Background camera render only objects in the “BackgroundLayer” using the “culling mask”
  10. For the “Background camera” click the + for “Stack” and add the “Main camera” (so it’s rendered first).
  11. Enable post-processing for the “Background Camera”, e.g. use a Depth-of-Field/Bokeh and play around with “Focus Distance” and “Focal Length” to create the blur you want.

There you go, blurry background and sharp foreground.
Probably not the most efficient way, but at least finally a way to do it.

Update: In the meanwhile URP 7.4.1 has been released, definitely upgrade to that one as you don’t need the manual fix from step 3 anymore and it fixes an issue with “smearing” when using the postprocessing-blur which happened in some situations.

3 Likes