Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Depth of Field Scatter blurs everything

Discussion in 'Scripting' started by obscene, Dec 1, 2013.

  1. obscene

    obscene

    Joined:
    Oct 26, 2013
    Posts:
    34
    I am getting so frustrated with Unity. Nothing works as expected. This script is a good example. It blurs everything, no matter what I change the focal distance or focal size to. I can only get varying degrees of blur for everything. My player is 10 units from the camera, it should be that simple. Is it my video card, do I have a buggy version?

    As an alternative I tried using two cameras. That only works if you want to blur the background. Blurring foreground, blurs everything.
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    No that is how it works.
     
  3. obscene

    obscene

    Joined:
    Oct 26, 2013
    Posts:
    34
    I watched a video on youtube of someone showing it and it worked correctly for him with the default settings. I'm actually wondering now if it has something to do with the fact that I am using 2d sprites and not 3d objects.

    Edit: Dropped a cube into the scene and it works properly for it, So apparently it doesnt work with sprites. Anyone know of a depth of field solution for sprites?
     
    Last edited: Dec 1, 2013
  4. GrantGamesGames

    GrantGamesGames

    Joined:
    Dec 29, 2013
    Posts:
    3
    I'm having the same issue, it would be really nice if it worked with sprites. Even better if it could be applied to 2d scenes with orthographic cameras.
     
  5. Remiel

    Remiel

    Joined:
    Oct 17, 2012
    Posts:
    103
    I am experiencing the same issue.
    Does anyone know how to fix it?
    It is as though all spirtes are on same z regardless of their actual z, it blurs either everything or nothing.
     
  6. Esperento

    Esperento

    Joined:
    Jul 24, 2011
    Posts:
    7
    I'm facing the same problem - I have sprites and an orthographic camera and even with the sprites massively far apart I still get either everything or nothing blurred.
     
  7. EliBrick

    EliBrick

    Joined:
    Jun 1, 2020
    Posts:
    10
    If anyone is looking for a solution to this problem, experiment with adding a child gameobject to the objects with sprites that you want to react to DoF. Add a meshrenderer and a meshfilter the same shape as the sprite to the empty gameobject.
    I used a sprite-to-mesh-converter here sent by agiro and a mesh-saver here made by pharan to generate a mesh from a sprite at runtime and then save the mesh. It made the workflow feasible when I figured out how to use these tools.
     
  8. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    @EliBrick you are responding to a thread that is 6 years old. You may want to check the last response before posting.

    In any event, Unity's post processing stack has resolved this in Unity 2018.1.
     
  9. EliBrick

    EliBrick

    Joined:
    Jun 1, 2020
    Posts:
    10
    Just leaving a note for anyone searching up this specific issue, as I have not found the solution elsewhere.

    It seems it has not been fixed. When using URP DoF with Sprites, either everything is blurred or nothing is. If I am implementing this wrong, please reply with a video/documentation describing the correct implementation.
     
  10. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    The camera DoF effect is quite simple: is looks at the Z Buffer info, and blurs any pixel that is not within the given range. For it 'not to work' usually means that something is overwriting the z buffer information for the camera.
    That is most probably the shader you are using for your sprites and / or canvas (which probably is overlaying your entire view).
    Here's something that might be worth a shot: ook at the sprite and check the shaders to see how they treat Z info and which pass they are running. Then perform the following test half the screen isn't covered by the canvas, the other half is. Now try the DoF effect.

    Does DoF work on the uncovered part? If so, you are need to check the way your canvas shaders are overwriting Z buffer information with that of the canvas even when the pixel is invisible.