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

Question There is a way to write on Depth Texture using a Unlit Shader Graph on URP?

Discussion in 'Universal Render Pipeline' started by AlanPereiraArt, Aug 20, 2021.

  1. AlanPereiraArt

    AlanPereiraArt

    Joined:
    Apr 29, 2014
    Posts:
    17
    Hello everyone,

    I tried searching for some hours, but maybe I am not using the best words to find it, so if it is a duplicate, sorry!

    Context:

    Well, I created a simple Unlit Shader Graph in order to create a Cel-Shading based on BOTW (Binay Lunar Tutorial).

    The Unity's Custom Lightning which I adapted to URP (10.5.1) is the following one:
    https://pastebin.com/atb6fRMS

    Link for the original one from Unity's Github (https://github.com/Unity-Technologi...ob/master/Assets/Includes/CustomLighting.hlsl)

    When I say, adapted, I just adjusted the if directives to define (which was generating errors)
    and added the 2 multi compile functions to be able to receive Shadows (before that, the Shadow Attenuation was always returning 1):
    1. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
    2. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
    _____________________________________________

    Issue:

    My problem is that my cel-shader seems not to be writing on the Depth Buffer. So, I was trying to make a simple Water Shader and when I used the Scene Depth for the effect, it happened:
    upload_2021-8-20_18-17-26.png
    (Ellen being cut by half)

    My question is, similar to how I added the Shadow Receive function through a multi_compile keyword, there is one to make it draw on the Depth Texture?

    On a Simple HLSL it was just a matter of putting ZWrite I guess, but on URP Unlit Shader Graph I don't know how I would be able to do it (and also, if I am able to do it).

    Example of the Depth (after changing it to Lit), but this way all the custom lightning calculations are gone:
    upload_2021-8-20_18-19-30.png

    Thanks in advance for any help.
    And yet again, sorry if it is a duplicate (in this case, please send me the link for the answer if possible).
     
  2. AlanPereiraArt

    AlanPereiraArt

    Joined:
    Apr 29, 2014
    Posts:
    17
    Oh gosh, was trying a Renderer Feature to force it draw on Depth, and for somewhat reason I discovered that the SSAO Renderer Feature was overwriting any depth data only from my cel-shader.
    upload_2021-8-20_18-44-3.png

    But by changing it to only Depth as a Source it works as expected
    upload_2021-8-20_18-44-37.png

    Lesson of the day, don`t try new tutorials with "cool" features enabled.
     
    shibi2017 likes this.