So what I’m looking for is something I can just slap onto a quad or sprite that I can just place in the scene, and everything behind it will get blurred. Does anyone happen to have a shader like that, or resources on how to make one that would be compatible with the 2D Renderer (URP) that Unity recently released?
Looking for the exact same thing, would like to render several sprites in the background, blur the entire screen (heavily) and then render sprites in the foreground.
Doesn’t seem possible with a custom renderpass (sth like this LWRP FullScreenQuad feature example. This can be used to extend LWRP render to render a full screen quad. · GitHub) because you can’t add “renderer features” to a 2d renderdata ( can only add with to forward renderer ).
Doesn’t seem possible with *post-*processing ( emphasis is on post, so no way for ‘early blur’… ).
Doesn’t seem possible with camera stacking in urp/2d renderer (from what I understand that would have been the legacy way to do it), using urp 7.2.1 (feb 2020) gives “the renderer used by this camera doesn’t support camera stacking. Only base camera will render.”
I found some notes on a “GrabPass and blur” but didn’t look too deeply. Probably won’t work since it seems custom renderpasses (which are not supported with urp/2d) are supposed to be the replacement for the grab-pass.
The choice seems to be between 2d-sprite-lights and camera-stacking + custom-renderpasses…
Rant: From one side Unity is extremely cool and powerful, from the other side it’s a mess. Lots of documentation and samples only work with ‘classic unity’. The way forward is LWRP, which was renamed to URP (adding to the confusion). URP supports multiple renderers which don’t seem to be on par feature-wise (renderer-features supported in the forward renderer, but not supported in the 2d renderer, similar with camera-stacking only in forward, but then 2d-spritelights only in the 2d renderer).
Some features (renderer-feature list) did work in LWRP 5.x (Unity Issue Tracker - [LWRP] Add to list button gives empty list when trying to add features to the Forward Renderer), stopped working in 6.x (feature removed?) and “might be supported again, but not a priority” for the future ( Will 2D Render Pipeline support Renderer Features? )
Ok, got it working:
- Upgrade to Unity 2019.3.3f1
- Use the package manager to upgrade “Universal RP” to 7.2.1 (or 7.3.1 now)
- 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”).
- Change your main camera (rendering the foreground) to rendertype “overlay” (it’ll be rendered on top of the background).
- Add a layer “BackgroundLayer” and assign everything in your scene which is in the background to be in this layer.
- Let the main camera render everything, except the “BackgroundLayer” using the “culling mask”
- Make sure this one is not rendering post-effects (in my case resulted in broken graphics)
- 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.
- Let the "Background camera render only objects in the “BackgroundLayer” using the “culling mask”
- For the “Background camera” click the + for “Stack” and add the “Main camera” (so it’s rendered first).
- 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.
Be sure to update to URP 7.4.1 first, then you do not need to modify the code (as in step 3) anymore!
Here’s a screenshot of what I have… If I select my bg-camera, the preview-windows only shows what that camera renders (so everything in the backgroundlayer), selecting the fg shows only the foreground.
I might have forgotten to mention something in my steps, if you figure out what is different and makes it work, please do report back, so I can update my steps and other people also benefit from it - thanks.
Sidenote, when modifying code from Unity \Packages (like URP), each time you restart Unity it will revert that code-change, so with unity 7.3.* step 3 would need to be done on every restart, which is one more reason to upgrade to 7.4.1!
I was able to make it work - kinda. I had two problems:
First of all, the I used canvases with Screen Space - Camera mode, so I had to change the camera to the new one for what I wanted it to see.
Second, I had to switch around which one is the base and overlay. I had to put my Main Camera as Base that sees all except the what I wanted to apply Post-Processing to. If I has the Main Camera on Overlay, I wouldn’t see anything from the secondary camera (despite being able to see the right objects in the camera’s own preview).
Now, the Camera Stack works but the Post-Processing still applies to everything but it’s only enabled for the secondary camera. If I enable it for the Main Camera too, it applies the effect twice enhancing it’s strength. I’m trying to use Chromatic Aberration but for certain Sprites only which I have on a Canvas only the secondary camera sees. I’ve tried other effects as well and they all work (don’t work) the same.
Also, I’m using URP 7.3.1, it says it’s up to date though. Is 7.4.1 a beta?**
Also also
, having the secondary camera be the child of the primary one doesn’t seem to make a difference.
**Looks like I didn’t have 2019.4x so that’s probably it.
I upgraded to 7.4.1 last week or so while I was still on 2019.3.12 (or so… which was not even the latest which was 2019.3.15 I think), and only yesterday upgraded to 2019.4 LTS, so it must work in earlier version. Also doesn’t look like urp 7.4.1 is in beta:
Be sure to figure this out and upgrade, because when hacking in the cameraStacking bool in 7.3.1 postprocessing is broken (I also had weird artifacts, like smearing persisting over multiple frames). It all works fine in 7.4.1. Which is the first time since I started with Unity in december that all features (stacking, postprocessing, custom renderer-features (which still needs a manual change)) are all working…
The Project Managed doesn’t offer me 7.4.1 (I’m using x.3.15f1) which is weird. I can’t seem to be able to get 2019.4 installed either… something is wrong with the Hub too now… I’ll try to sort this out and get 7.4.1 working - I might have to download and install it manually (I think it’s possible). I’ll throw a reply once I’m there and I can test camera stacking with PP.
Ok, so I managed to get the latest release Unity and found the URP 7.4.1 upgrade. No difference in my results though. I changed the variable to true once again in a the cs file too.
- Whether or not the secondary camera is a child of the main one makes no difference
- I only see what is enabled in the culling mask of the secondary camera (and disabled for the main one) when the main camera is the base of the stack and the secondary one is overlay
- The post processing effect I use, which is only enabled on the secondary camera does still apply to every sprite regardless of what layer they are on (UI, etc). The effect goes away from everything if I disable the secondary camera (along with all the objects that are on the layers specific to that camera ofc).
I added one camera as a child, so that then the “parent” one moves, the child camera (relative 0,0,0 position to the parent) moves “in sync” with it. I don’t think it’s a hard requirement, but it’s just convenient (can’t think of a situation where it would make sense to not have them in a parent-child hierarchy).
I didn’t explicitly say so, but the sprites I wanted rendered in the background (and in my case blurred) are all assigned to the backgroundlayer. But I think that is what you mean with your “regardless what layer they are on”.
Not sure what else to suggest, running out of ideas now too…
I have a “Post-Processing” layer. I have everything that I want post-processing to apply to on this layer. I also have a Global Volume on this layer. My “Post-Processing Camera” is on Overlay and it’s added to the stack of the Main Camera, chis is the Base. If I put them the other way around, I don’t see any objects from the secondary camera. Post Processing is enabled on the secondary, and disabled on the Main Camera. Also, to make sure, The Volume Mask layer selector is set to Nothing (so it won’t pick up any Volumes on any layers) and for the “Post-Processing” camera it’s set to the “Post-Processing” layer (so it sees the Volume).
What happens now is: in Scene view, no Post-Processing effects are visible on any objects. After hitting Play, in Game view, the Post-Processing effects selected on my Global Volume are applied to everything on all objects any camera sees. If I disable Post Processing on the secondary camera or change the Volume Mask so the camera doesn’t see the the Global Volume to “Nothing” for instance) as a test, the effects don’t get applied to anything (as it should be).
I even tried creating a second Global Volume where I set the Weight to 0 and put it to the Default layer, and tell the Main Camera to search for Volumes on the Default layer via the Volume Mask option - Post Processing enabled so it would hopefully overwrite the other one from the Overlay secondary camera but it doesn’t work.
Ok, I was fiddling around with stuff and I got the opposite working. I thought maybe the Overlay camera overwrites whatever the Base does in this regard, I couldn’t switch their roles in the Stack around but I thought I’ll switch which camera applies the Post Processing effects.
If Post Processing is enabled on the Base camera but disabled on the Overlay camera it DOES get overwritten. Whatever is seen on the Overlay camera will not get the Post Processing effects applied to the main camera.
It does work like what you described but I have zero clue why I wasn’t able to just swap which camera is Base and which one is Overlay. I’ll try swapping the Culling masks of the two cameras, essentially swapping what they see.
Aaaand no. If I switch them around it doesn’t work anymore. Now anything that I don’t wand post processing to apply to is on the secondary Overlay camera and I still don’t see anything on the Base camera. It only works in reverse. When the elements I don’t want Post Processing to apply to are on the Base camera that have Post Processing enabled, it works. Whatever is on the Overlay camera doesn’t get the effects. Sadly, that’s just the stuff I want to have the effects on. This is such a crazy and weird issue to have I’m sore it’s pretty close to working. I’ll fiddle around some more and will post an update when it’s working.
Also, I’m using 7.4.1, and even if cameraStacking is set to true or not it doesn’t seem to make a difference. I assume it’s used whenever a camera is switched between Base and Overlay mode to show and hide a Stack UI element in the editor.
So when you say “they are applied to all objects any camera sees”, that might actually be what is expected if you run a PP effect on the foreground (it would be for my case at least)… So as I understand it, the camera’s render in a back-to-front order (as defined by the camerastack), and the ones which have a PP effect set, apply it to everything which was rendered before it by any camera (so not only the objects the “current” camera itself renders!).
scenario 1. my scenario of only blurring the background:
- Render Background + pp-blur
- Render Foreground
→ result: background is blurred, foreground is sharp → which is exactly what I want.
scenario2. instead of bg, let’s blur the foreground (this is similar to your scenario), so:
- Render background (sharp, no PP)
- Render foreground (on top of the background) + blur-PP
→ result: background is blurred, foreground is blurred. → so yes, you could indeed say “it’s applied to everything on all objects each camera sees”.
scenario3. blurring background and foreground: PP enabled on both camera’s
- Render background (blurred, PP)
- Render foreground blur-PP (on top of the already blurred background)
→ result: so basically the background gets blurred twice and the foreground gets blurred once.
This expectation seems to match with what Unity does (I briefly tested both scenario 2 and 3 and it behaves like predicted). Not sure what pp-effect you are running, but my guess is it will behave similar.
Correct, in 7.3.1 you needed to do the manual “cameraStacking = true” code-change to get the “Stack-UI-entry on the base-entry where you can select the overlay-camera” to appear in the UI (otherwise it was hidden). This is not needed anymore in 7.4.1 (it works differently, just compare the files and you can see where/how) and that part works correctly, so do not change it.
Hi, could you share your PP effect settings? I also didn’t manage to get them working for the blur to occur.





