Search Unity

Matte Shader (Only Shadows) in HDRP

Discussion in 'High Definition Render Pipeline' started by herrenderschoepfung, Sep 6, 2019.

  1. herrenderschoepfung

    herrenderschoepfung

    Joined:
    Nov 18, 2016
    Posts:
    5
    Hi everyone,

    I'm using HDRP for my current project and I need to cast a shadow on a transparent plane. So far I found quite a bunch of tutorials on how to do that using regular Unity shaders in SRP, but none for HDRP (preferably using default shaders or Shader Graph).

    Thanks for your help!
     
  2. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    I think semi-transparent shadows are for Realtime Raytracing only. That's the only way I know that works in Unity out of the box.
     
    chap-unity likes this.
  3. max_coding13

    max_coding13

    Joined:
    Apr 24, 2016
    Posts:
    34
    @Bordeaux_Fox what do you mean exactly? Like you can make a Shadow Matte shader (transparent shader that receives only shadow info) for RTX shadows in HDRP? How would you go about doing that?
    I realized last night that Unity has an option for making a shadow matte in the Unlit shader graph, but when I played around with it it had fairly bad results with RTX shadows. Have you had success making an RTX shadow matte shader?
     
    Last edited: Feb 14, 2020
  4. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    Last edited: Feb 15, 2020
  5. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    Hi,
    maybe there is confusion regarding name.

    For rasterization we support:
    - opaque shadow from opaque and transparent
    - shadow matte (with unlit shader, those are shadow only without lighting from light)

    For raytracing we support:
    - Colored or not directional shadow
    - Monochromatic spot / point shadow (what is call semi-transparent in the documentation)
     
  6. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    I think what you are looking for is an unlit master node with "Shadow Matte" enabled : upload_2020-2-18_14-55-14.png

    Once you've set the material to transparent and 0 opacity, you will have this : upload_2020-2-18_14-55-56.png
     
  7. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hi. In Blender EEVEE is use this method because on the ground there is mostly reflection involved.



    Is there an easy to do this in a SG as extension of the method described before?
    It s a little limitating to have the Shadow Matte only in the Unlit Master.
     
  8. UnivrseCore

    UnivrseCore

    Joined:
    Jul 14, 2013
    Posts:
    12
    @Remy_Unity
    I have tried to copy your shader but with no luck, for me there are no shadows appearing :(

    See the screen shots below for extra information:

    Here is my shader graph (copy of what you did):


    Here is my material:


    This is the material applied to the mesh (probably redundant):


    And here is the result, no shadow sadly..


    How can i get this to work?

    Side question also my properties are not showing up in the inspector.

    Extra information:

    Using unity version 2019.3.3f1
    Using HDRP version 7.1.8

    If more information is required pls let me know so i can add it :)
     
  9. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    If the properties are not appearing in the inspector, I suspect that there is a compilation issue on the shader.
    At this point it's getting hard to guess what is the root cause only looking at your screens, and it would be better to share your project.
     
  10. UnivrseCore

    UnivrseCore

    Joined:
    Jul 14, 2013
    Posts:
    12
    Hi sadly I cant share my project..
    But could you give me some pointers on where to look? Maybe player settings?
    Or could i just share the shader, or some other specific file?
     
  11. ReMix3D

    ReMix3D

    Joined:
    Sep 9, 2012
    Posts:
    14
    If you could isolate the issue in a specific scene with non protected assets, like the susane head and an open source HDRI, that would be great, to share it safely.
    If you can't, there is maybe the option to PM me the project.
     
  12. UnivrseCore

    UnivrseCore

    Joined:
    Jul 14, 2013
    Posts:
    12
    Thanks for the tip. See the files below:
    (If any other file is required let me know so i can also share those)
     

    Attached Files:

    tdpl_parthpatel likes this.
  13. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    I think your floor plane is in a layer that is not active in the camera culling mask.
    When I looked at it, the plane's layer was set to
    "             "
    , meaning it was using a layer that I did not define in my project.
    Once I moved it to "default", it showed up.
     
  14. UnivrseCore

    UnivrseCore

    Joined:
    Jul 14, 2013
    Posts:
    12
    Yeah you'r right that made the floor appear. But In gray without transparancy or shadows. How do i make sure it is transparent with shadows?

    EDIT @Remy_Unity Did you see shadows and transparency?
     
    Last edited: Mar 13, 2020
  15. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    In the example scene you provided :
    • The light was not emitting shadows
    • The master node didn't have shadow mate enabled
    • The alpha of the master node was still 1. Set it to 0 so it can be fully transparent (except shadows)
    Once those steps are fixed, you should have this :
    upload_2020-3-17_13-4-47.png
     
  16. UnivrseCore

    UnivrseCore

    Joined:
    Jul 14, 2013
    Posts:
    12
    Awesome, it turned out the light was not emitting shadows... Thank you
     
  17. bobthenob

    bobthenob

    Joined:
    Sep 2, 2013
    Posts:
    26
    cheers this helped me out
     
  18. penneyworth1

    penneyworth1

    Joined:
    Feb 7, 2015
    Posts:
    13
    Remy, can this be done in the latest version of shader graph? I don't see the shadow matte option anywhere. @Remy_Unity
     
    Last edited: Jun 26, 2021
  19. JorisdeJong

    JorisdeJong

    Joined:
    Feb 16, 2013
    Posts:
    1
    In the Shader Graph Editor, in the Graph Inspector on the right, go to the Graph Settings tab. Shadow Matte is all the way down at the bottom

    Screenshot 2021-06-29 121527.png
     
  20. GeniusKoala

    GeniusKoala

    Joined:
    Oct 13, 2017
    Posts:
    97
    Is there a way to have both matte shadow and ambient occlusion at the same time ?

    We would like to set characters on a live action environnement and we would like contacts with the floor. We currently use a proxy to cast shadow on it in the matte shadow way which works great. Now we would like to also have the contact shadows with the proxy and that's what the ambient occlusion would do. If I put an opaque plane the ambient occlusion works great but now I would like to make it with the matte shadow added. Maybe with a custom pass or the compositor?
     
    Last edited: Oct 12, 2021
    farfewgiants likes this.
  21. vuthang

    vuthang

    Joined:
    Mar 7, 2017
    Posts:
    50
    Can you push done project to here?
     
  22. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    I don't have the projet anymore, but you should easily be able to reproduce it with the mentioned steps and the assets provided at #12.
     
  23. Naomi-DevOps

    Naomi-DevOps

    Joined:
    Apr 14, 2021
    Posts:
    11
    I am not able to import package from #12 into Unity 2021.2.18f1, Silicon - package is grayed out and it cannot be selected. What i am missing? :\