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. Dismiss Notice

Feature Request Depth output for shader graph -> PDO(Pixel Depth Offset) -> terrain blending -> billboard shadows

Discussion in 'Shader Graph' started by Nexusmaster, Apr 21, 2023.

?

Do you want custom depth output in shader graph?

  1. Yes

    37 vote(s)
    100.0%
  2. No

    0 vote(s)
    0.0%
  1. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    362
    Hi,

    I think a lot of people would appreciate having the possibility to add the SV_Depth output in shader graph for all render pipelines. (Like HDRP "Depth Offset output" but with no dependencies.)

    The SV_Depth is just an additional target in the fragment shader which will overwrite the depth information of the rendered object.
    Normally in a custom shader you just define it as an output, so in shader graph this could be an option or could be enabled by a local keyword definition.

    Here a possible use cases:





    See how it's implemented in Unreal, very simple, just an input value that can be overwritten:


    These are only 2d textures, with SV_Depth you can make them look 3d:



    More infos about this see here:
    https://bgolus.medium.com/rendering-a-sphere-on-a-quad-13c92025570c

    Please Unity add this feature to all render targets in the fragment shader of shader graph! Thx!
     
    Last edited: Apr 21, 2023
  2. AbelSierra

    AbelSierra

    Joined:
    Jul 19, 2018
    Posts:
    19
    A totally needed feature!
     
  3. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    362
    Thanks!
    Everyone who needs this feature should post something here to keep this feature request visible for Unity Devs!
    Thank you!
     
  4. backwheelbates

    backwheelbates

    Joined:
    Jan 14, 2014
    Posts:
    225
  5. Radivarig

    Radivarig

    Joined:
    May 15, 2013
    Posts:
    92
    Yes, needed
     
    Nexusmaster likes this.
  6. Arron_Davies

    Arron_Davies

    Joined:
    May 10, 2013
    Posts:
    3
    Needed, i'm sick of looking around for alternatives.
     
  7. BenCloward

    BenCloward

    Unity Technologies

    Joined:
    Jul 15, 2021
    Posts:
    93
    Unless I missed something, this feature already exists in HDRP, right?

    upload_2023-8-15_14-46-44.png

    So is this thread just about adding the same thing to URP, or is there more to it?
     
    Qriva likes this.
  8. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    362
    Hi Ben,
    looking into the gen-shadergraph-shader it seems to me that even in HDRP the Depth Offset value is not passed direct to SV_Depth it gets a bit of extra calculations that might alter the result,but...
    upload_2023-10-10_13-55-23.png
    upload_2023-10-10_13-57-58.png
    upload_2023-10-10_14-0-26.png

    ...I think it's ok that the DepthOffset is multiplied with -V, I will do some tests if I find any use-cases that don't work with this method.
    Back to your question, yes URP seems to be missing that feature and as some of my users still use builtin it might be helpful to have that too, but URP would be more important! Thanks!

    Best regards,
    Chris

    Edit: After further testing it seems to be an issue to have a Depth Offset and not a direct Depth output, not sure how to fix this easily... the offset just gets added on top of the geometry, but in the imposter case you want to replace the depth... maybe someone has figured that out? Multiplying with a higher negative number seems to get something, but I didn't figure this out yet, maybe need to reverse the whole deviceDepth chain...
     
    Last edited: Oct 10, 2023
  9. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    362
    After a few tests
    Code (CSharp):
    1. outDepth = -mul(float4(surfacePos, 1.0), UNITY_MATRIX_V).z;
    seems to do the trick. (You could put that into a custom function.) However, in my test the imposter quad still affects the shadows, maybe need to render the quad differently...

    Edit: After a few more tests I found out that this only is important for my current shader test, normally you don't need that, so you can directly use DepthOffset with a normal Camera depth buffer and it works!
     
    Last edited: Oct 11, 2023
  10. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    362
    And again @BenCloward and @Unity: Please add this feature to URP and Builtin in the shadergraph, thanks!
     
    lilacsky824 and NikolaNikolov like this.
  11. MajorWolph

    MajorWolph

    Joined:
    Apr 28, 2018
    Posts:
    19
    Amplify Shader Editor already supports this feature for URP and built-in shaders, I don't see a reason why this could not be added to ShaderGraph as well (for URP/built-in)
     
    Nexusmaster likes this.