Search Unity

Question adding DepthNormals pass to Unlit URP shaderGraph (+feedback SG Devs)

Discussion in 'Shader Graph' started by XRA, Feb 19, 2021.

  1. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    Was hoping that the new Vertex & Fragment outputs would support this. In URP the SSAO can use DepthNormals, there is also the option of using Depth but I specifically need DepthNormals....

    I'm working with custom lighting in ShaderGraph & currently to do that you use an Unlit URP Shader graph to avoid any sort of double contribution from lights.

    With the new Fragment outputs (which seem similar to filling out a SurfaceParams struct) it would be excellent if we could specify other pass outputs there that the SRP supports.

    For example, I should be able to simply add "DepthNormals" to the fragment block, set it to use lightmode DepthNormals via string, and under the hood when building the shader it creates a pass that uses "LightMode"="DepthNormals" and any of the relevant code feeding into that output is put in that pass.

    Is a feature like this planned?
     
  2. morepixels

    morepixels

    Joined:
    May 21, 2014
    Posts:
    18
    I'd also like to have this.
     
  3. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,312
    I was really happy when they finally added AO to URP. I tested it during the first week after release and guess what?
    It is not usable xD
    I use custom lights in the game and I simply can't use AO, because Unlit has no support for depth normals.
    I can't describe my anger at that time - I even bothered to go and post feature request on the roadmap.
    Sadly I still do not know how to make it work.

    Can someone from Unity shed some light on this problem?
     
  4. Luxxuor

    Luxxuor

    Joined:
    Jul 18, 2019
    Posts:
    89
    You could add a RendererFeature to your pipeline that renders just the DepthNormals texture using the
    "Hidden/Internal-DepthNormalsTexture" shader for it. It will cost you an extra draw call for the whole scene but atleast you won't need shader support for it in your unlit materials.
     
  5. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,312
    Do you mean additional pass for all objects? It sounds like dirty hack, not real solution of "super flexible pipeline".
     
  6. Luxxuor

    Luxxuor

    Joined:
    Jul 18, 2019
    Posts:
    89
    You can always filter based on layers, shader tags or other custom logic implemented inside of an RenderFeature, not a dirty hack at all imho.
     
  7. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,312
    Ok, then how to do it well? I want to add my unlit based toon shaders in depth normals, filtering by layers for sure is no way to go and there is no way to add tags from what I know.
     
  8. adamgryu

    adamgryu

    Joined:
    Mar 1, 2014
    Posts:
    188
    Is there still no way to add a DepthNormals pass to a shader graph?
    I've been trying to convert my custom lighting model into a subgraph using a Custom Function node. It seemed like a nice idea in theory but I've run into a bunch of troubles.

    If I can't use AO in my unlit graph then I can't do this I suppose.

    In case the devs are looking at this:
    - I'd like to be able to define parameters in Shader Graph that correspond to variables inside my HLSL libraries. It currently thinks it's being redefined?
    - I'd like to expose boolean keyword properties without the _ON suffix. It seems like a weird restriction since there already is an Exposed field, and I'd prefer not to have to change the defines in my HLSL library to accommodate this.
     
    Last edited: Dec 2, 2021
  9. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,312
    I can tell you after upgrading project to 2021.2 my unlit shader managed to get AO from custom node, so it would mean it has normals pass (I just checked very fast without going deep).
     
  10. adamgryu

    adamgryu

    Joined:
    Mar 1, 2014
    Posts:
    188
    Interesting! Before I update my project to 2021, do you have any idea how the Shader Graph knows if to generate a normals pass? It must not be doing so for every Unlit shader?
     
  11. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,312
    I just toggled rendered feature to see if it works, so I recommend you to test this in separate project. What I made 6 months ago is Unlit shader graph with my custom AO subgraph, it has this custom function code:
    Code (CSharp):
    1. #ifndef CUSTOM_AMBIENT_OCCLUSION_INCLUDED
    2. #define CUSTOM_AMBIENT_OCCLUSION_INCLUDED
    3.  
    4. void AmbientOcclusion_float(float2 NormalizedScreenSpaceUV, out float Direct, out float Indirect)
    5. {
    6.     #ifdef SHADERGRAPH_PREVIEW
    7.         Direct = 1;
    8.         Indirect = 1;
    9.     #else
    10.         AmbientOcclusionFactor factor = GetScreenSpaceAmbientOcclusion(NormalizedScreenSpaceUV);
    11.         Direct = factor.directAmbientOcclusion;
    12.         Indirect = factor.indirectAmbientOcclusion;
    13.     #endif
    14. }
    15.  
    16. #endif //CUSTOM_AMBIENT_OCCLUSION_INCLUDED
    There is one more thing, this keyword:
    Code (CSharp):
    1. _SCREEN_SPACE_OCCLUSION
    Maybe this made it work.
     
  12. adamgryu

    adamgryu

    Joined:
    Mar 1, 2014
    Posts:
    188
    Thanks, maybe I'll take some time to test out 2021 to see how it works for me.
     
  13. richard_harrington

    richard_harrington

    Unity Technologies

    Joined:
    Sep 29, 2020
    Posts:
    22
    Sharing this for others who come looking:

    With 2021 you can use this attached script, which creates an Enable Depth Normals RendererFeature which you can add to your URP Renderer to enable the DepthNormals pre-pass when you're not using SSAO. Just place it in a non-Editor folder (as you need runtime access to it), and then add it to your URP Renderer as you would the SSAO RendererFeature.
     

    Attached Files:

  14. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742

    Will this just become built in at some point ? Kind've strange i have look through the forums to find things like this that i would expect to just be there in URP already as an option.

    Also how do you then sample the normals in shader graph ?