Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

How to blur specific layers only?

Discussion in '2D' started by MadPropz101, Sep 14, 2018.

  1. MadPropz101

    MadPropz101

    Joined:
    Aug 29, 2018
    Posts:
    9
    I'm trying to figure out how to blur only the background and foreground layers, so that only my main layer is in focus. I used the post processing addon from the asset store and applies DoF through different cameras that all see different layers, but the problem with this is that the cameras in front still affect the stuff that's in the back.
    It doesn't have to be done with DoF, i just need a way to blur only the layers that i want during runtime, and at different blur intensities. I know it can be done by already preparing the sprites to look blurry but that's not very flexible, especially for my game where i use a lot of moving parts and Spine animations.
     
  2. Tim-Duval

    Tim-Duval

    Joined:
    Sep 2, 2015
    Posts:
    156
    You go to your project, click create, select post processing profile. It will appear in your assets (Project). You then drag and drop it in the "profile" slot on your camera. It'll be in the inspector at the bottom. Profile with an empty field. Drop it in there.

    Then you have the options, many options, to do everything from fog, blur, etc... I'm not sure if you have to download this asset or if it comes stock. However, Unity free standard assets should have it if not. I honestly don't know.
     
  3. Tim-Duval

    Tim-Duval

    Joined:
    Sep 2, 2015
    Posts:
    156
  4. MadPropz101

    MadPropz101

    Joined:
    Aug 29, 2018
    Posts:
    9
    Yeah that's exactly what i did but as i said the problem is that the cameras in the front add the blur even to the layers which they are not set up to see. This is the video i used:


    This is the effect i want to achieve, as you can see the squirrel is sharp but the stuff in the foreground and background is blurred:
     
  5. Tim-Duval

    Tim-Duval

    Joined:
    Sep 2, 2015
    Posts:
    156
    Go to Edit>>Build Settings>>Project Settings>>Physics

    This should bring up the layer matrix in the inspector window. You can UNCHECK the stuff you don't want the other cameras to see by the layer name. maybe this will help you?
     
  6. MadPropz101

    MadPropz101

    Joined:
    Aug 29, 2018
    Posts:
    9
    I just tried messing around with the layer matrix, but if i understand correctly this is only used for collisions?
    The way my game is set up is that i have multiple cameras all following the player, and each camera's culling mask is set to show specific layers.
    I thought that when i added depth of field/blur to a camera that i would only apply the effect to the layers set in the culling mask, but for some reason the effect also applies to all the objects/layers in the scene that are behind, even though they are shown through completely different cameras.
     
  7. roykoma

    roykoma

    Joined:
    Dec 9, 2016
    Posts:
    85
    You could create two Cameras.

    • First create a new Layer "Focus" (or whatever you like)
    • Set one Camera (your "Focus" camera) to "Depth only" for Clear Flags and its Culling mask to "Focus" only.
    • Set the other Cameras (your "Blur" camera) culling Mask to everything except "Focus"
    • Child the other Camera to you "Focus" camera and look out that the values are equal, so that they always see the same.
    • Create a new Post processing Volume with "Depth of Field" and set its values to whatever you like. Set this object on a Layer "PostProcessing" (or whatever you like)
    • Add a Post Processing Layer with the Layer set to "PostProcessing" to the seconds (blur) camera
    • enjoy
    Result and Images of the editor (so you can see how it is set up):
    https://imgur.com/a/umbnxaP

     
    Last edited: Sep 14, 2018
  8. MadPropz101

    MadPropz101

    Joined:
    Aug 29, 2018
    Posts:
    9
    How did you create a post processing volume and get the DoF settings shown?
    Is this the asset i need to use to have that option?
    https://assetstore.unity.com/packages/3d/post-processing-volume-89782
     
  9. roykoma

    roykoma

    Joined:
    Dec 9, 2016
    Posts:
    85
    Sorry, I forgot they didn't update the asset in the store yet.

    What I used is the Version 2 of the unity post processing stack that can be downloaded via https://github.com/Unity-Technologies/PostProcessing
    You can see the documentation for it here

    Can also be downloaded via the package manager in Unity 2018.
    I only changed the "Max Blur Size" to "Very Large" in this case.

    I can not tell you how to do this with V1 PostProcessing as I never used it.
     
  10. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    27
    I have been struggling with this. And I have easily been able to replicate the effect roykoma posted, with the sharp object being closest to the camera, but I cannot do the opposite having only the closest object blurred and the things behind it sharp. Which is also what madpropz101 requested (blurred front, sharp middle, blurred back).
     
    MadPropz101 likes this.
  11. MadPropz101

    MadPropz101

    Joined:
    Aug 29, 2018
    Posts:
    9
    @roykoma showed me a viable solution so i'll repost it here.

    • Put the "SpriteShaders" Folder from https://github.com/traggett/UnitySpriteShaders into your assets
    • Use only one camera
    • Put a Post Process Layer on that Camera and match the Layers again with your PostProcessing Volume
    • Create a new material and select the "Sprite (Unlit)" Shader
    • Check the "Write to Depth" checkbox on the material
    • Put this material on your sprites
    • Add the Depth Of Blur to your PostProcessing Volume and play around with the values till it is good. For me maxing out Focal Length and Aperture and then adjusting the Focus Distance did the trick.

    This method however no longer just works with layers but instead takes the real depth.
     
  12. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    27
    If it no longer works with layers it might be a problem for me, as I do parallax effects with multiple cameras already.

    EDIT: Actually this also works with layers, at least with blurring the foreground which is all i needed.
     
    Last edited: Sep 19, 2018 at 12:11 PM
  13. MadPropz101

    MadPropz101

    Joined:
    Aug 29, 2018
    Posts:
    9
    Yeah it does work.