Search Unity

URP - Achieving depth of field in 2D

Discussion in '2D' started by jcatreid_unity, Sep 30, 2020.

  1. jcatreid_unity

    jcatreid_unity

    Joined:
    Apr 22, 2020
    Posts:
    5
    Hello,

    My 2D game contains five layers of backgrounds, each placed apart by 20 on the Z-axis. I have a parallax effect applied on the layers and this works perfectly.

    I am attempting to blur the three most back layers in order to create a depth of field attempt, so far I have tried to create various gaussian blur shaders in order to do this, Youtube 'Unity 2D blur' and I have attempted every tutorial available only to realise this isn't viable.

    I have also tried several several assets on the Unity asset store and depth of field post-processing effect, none of this has worked.

    I am close to giving up, something that seems simple enough has really been a struggle for me.

    Any help would be greatly appreciated!
     
    RemDust likes this.
  2. ThisIsDangerous

    ThisIsDangerous

    Joined:
    Dec 3, 2018
    Posts:
    39
    Hi.

    Why didn't depth of field post-processing work for you?
     
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    If these background layers are never in focus, it'll be more performant to not use a shader and instead blur the texture itself in Photoshop/Gimp/etc.This would allow you to blur it perfectly.

    However, he's a very simple shader based technique.



    If that doesn't work what is going wrong?
     
  4. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    432
    I'm jumping in :D
    Thanks for the link !

    However this doesnt look like gaussian blur in any way :/
    I highly doubt that background can look good with this approach...
     
  5. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    Does blurring the texture itself work? Or is there some other consideration preventing that for your use case?
     
  6. jcatreid_unity

    jcatreid_unity

    Joined:
    Apr 22, 2020
    Posts:
    5
    Hello
    I have no idea, tried every which way to implement it following almost all tutorials I could find online and unfortunately nothing worked for me.
     
  7. jcatreid_unity

    jcatreid_unity

    Joined:
    Apr 22, 2020
    Posts:
    5
    Hi there, tried this tutorial and did not create the desired effect, blurring in photoshop/gimp is my last resort as I don't want multiple versions of the same sprite as I would like to use the sprites on different layers and therefore would need to have various versions of the sprite blurred at different levels. Thanks for the help though! Much appreciated.
     
  8. jcatreid_unity

    jcatreid_unity

    Joined:
    Apr 22, 2020
    Posts:
    5
    I have worked out a way to blur the material on the sprite which almost works however it is no longer effect by light
     
  9. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    You could try using low-res images - for example 4x blur of a 512x512 image just make it 128x128 and set to bilinear in the import settings. This also has the benefit of smaller file sizes and faster loading.
     
    jcatreid_unity likes this.
  10. unity_xn_4JKXWrpcnxg

    unity_xn_4JKXWrpcnxg

    Joined:
    Aug 18, 2019
    Posts:
    1
    How? Ive been searching and testing for several hour to try to have a DoF in my 2D game.