Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question REQUIRE_DEPTH_TEXTURE is not defined for custom function nodes?

Discussion in 'Shader Graph' started by whoisj, Aug 23, 2019.

  1. whoisj

    whoisj

    Joined:
    Jan 4, 2018
    Posts:
    26
    I'm trying to use SHADERGRAPH_SAMPLE_SCENE_DEPTH() to sample scene depth information, and it always returns 0. Then I tried using SAMPLE_DEPTH_TEXTURE but _CameraDepthTexture is not defined. In fact it seems like any definition guarded by REQUIRE_DEPTH_TEXTURE is undefined.

    And while that might make sense, the Screen Depth node functions normally in the same shadergraph.

    Can somebody help me understand what I'm doing incorrectly here?

    ShaderGraph 6.9.1
    LWRP 6.91
     
  2. whoisj

    whoisj

    Joined:
    Jan 4, 2018
    Posts:
    26
    Nobody knows why Scene Depth node works but SHADERGRAPH_SAMPLE_SCENE_DEPTH is a Custom Function node doesn't?

    I mean, more specifically ... why does #if defined(REQUIRE_DEPTH_TEXTURE) always resolve to false, even in the same shader graph as a Scene Depth node that functions properly?

    How can I force the HLSH in my Custom Node to define REQUIRE_DEPTH_TEXTURE (and enable all the feature that doing so would being)?

    Is this a bug? If so, then I'll happily file one.

    Thanks.
     
  3. H-Alex

    H-Alex

    Joined:
    Oct 2, 2012
    Posts:
    26
    Did you find an answer for that? Cheers.
     
  4. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    This is not a bug as much as a missing feature at the moment. Shader Graph uses defines like
    REQUIRE_DEPTH_TEXTURE
    to transfer requirements defined in the graph to the generated HLSL. Currently, custom function nodes on the graph cannot enable graph requirement defines like this. Some defines can be enabled inside of an HLSL include file and still resolve, but others need to be enabled in a very specific order that the custom function node cannot currently access.
    Is there a reason you can't use the built in Scene Depth node and pass the output in to your custom function to continue your calculations as a workaround?
     
  5. H-Alex

    H-Alex

    Joined:
    Oct 2, 2012
    Posts:
    26
    Hey, thank you for your feedback.

    Nothing really prevents me from using the Scene Depth Node, but I find it so much more convenient to use a custom node in my case... (I'm doing an outline effect and need to sample multiple times, with multiple variants).

    Is there any workaround by using defines / includes in a specific order in the custom node script?

    My current workaround:
    I tricked the system by adding a dummy Scene Depth node in my graph temporarily


    This is related to another topic I opened, it's question number 4.
    https://forum.unity.com/threads/custom-passes-and-buffer-access.843295/

    Btw, if you can help me with that other topic, that would be awesome :D

    Thanks !
     
  6. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    You've already nailed it on the head with your current workaround. Getting the requirement on the graph somewhere is the best way to ensure the define is enabled. c:
    That specific define needs to be enabled very early on in the generated shader and the custom function node doesn't access anything that can write to that section of the shader.
     
  7. H-Alex

    H-Alex

    Joined:
    Oct 2, 2012
    Posts:
    26
    Fair enough, thank you :)