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. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    Dismiss Notice

Question 2D renderer Depth of Field effect.

Discussion in '2D Experimental Preview' started by eterlan, Aug 31, 2022.

  1. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    146
    Hi everyone! I want to add some DOF effect just like Hollow Knight and Ori. Actually I was searching on this topic few days and still can't figure it out how to do it with Shader.

    What I already known is, sprite is all transparent so it doesn't open ZWrite by default. So I write a simple sprite shader with ZWrite on, and I can tell it has depth test working, but still not correct DOF effect. Why?
    However, I found something new in the 2D renderer data setting.
    So we already have depth buffer right? However, I can neither find depth texture nor the CameraSortingLayerTexture in the frame buffer. And the _CameraDepthTexture return nothing at all. Is there any info I missed?

    Hope someone can shed some light on me, thanks!
     

    Attached Files:

    RemDust likes this.
  2. yinhao7700

    yinhao7700

    Joined:
    Apr 7, 2019
    Posts:
    5
    I have the same question as you. Hope there is a solution.
     
    znagler, MaykeBr and RemDust like this.
  3. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    68
    Same here, anyone from unity can help with this?

    @rustum Maybe you can shad some light on this issue?
     
  4. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    409
    I straight up gave up on this.
    After weeks of digging what I found is that the 2D renderer is, sorry, horrible. If you really need DoF, you should use the good old Built In Renderer, where you will be able to found a good number of blur shaders, because on this renderer it was actually possible to write some !

    (You can look all you want, you won't find a single blur shader for the 2D renderer, at least, it was straight up impossible 2 months ago)

    Or of course you can take the road I'm taking : baking blur in all your sprites with different blur sizes, it's FAR from ideal, but at least you know what you will end up with...

    Good luck !