Search Unity

Resolved How to create a shadow in URP and HDRP shader (Unlit)?

Discussion in 'Shader Graph' started by Volchok, Nov 22, 2021.

  1. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Hi!

    I have a shader that works in both URP (v. 7.3.1) and HDRP (v. 7.3.1).
    But I would like it to cast a shadow according to its shape.

    It would seem that the problem seems simple, but I have not found a solution. :rolleyes:

    I found the answer here, but I can't change properties Alphacrypt light and Opaque.

    Cast shadow of transparent plane in URP
    https://stackoverflow.com/questions/65693026/cast-shadow-of-transparent-plane-in-urp

    How do I display the simple shadow from the shader on the terrain (and on other objects in the scene)?

    Thank you!



     
    Last edited: Nov 23, 2021
  2. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    The easiest method would be to just duplicate the object, make it use opaque and alpha clip, then set the shadow mode in its mesh renderer to "Shadow Only".

    Hope that helps. ;)
     
    Volchok likes this.
  3. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
  4. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Can you tell me? How can I add my code to .shadergraph file? Is it possible?
    Maybe I need to compile it in .shader? But compiled files give errors and are not a file with the correct shader code, as I understand.
     
  5. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    AAA... I see! I can use Custom function and Keywords... :):):)
     
  6. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    I tried to implement everything they say here, but it didn't work.:(:(:(

    Shadow and distance attenuation do not work in URP Unlit Graph
    https://forum.unity.com/threads/sha...uation-do-not-work-in-urp-unlit-graph.803025/

    Shader Graph Custom Lighting (Shadows for URP Unlit Graph)
    https://cyangamedev.wordpress.com/2020/09/22/custom-lighting/

    Custom Lighting in Shader Graph: Expanding your graphs in 2019
    https://blog.unity.com/technology/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019

    I created a Custom Function, created nodes of Light source - but it doesn't work to attach them to the Color output in Unlit - there is no shadow and everything looks terrible (I tried Lerp, Multiply, Add, Blend).



    I'll probably have to follow your advice... :):rolleyes:
     
    Last edited: Nov 23, 2021
  7. Volchok

    Volchok

    Joined:
    Jul 26, 2017
    Posts:
    127
    Everything worked



    Thank you a lot!



    The question is closed!
     
    Ruchir likes this.
  8. Bovine

    Bovine

    Joined:
    Oct 13, 2010
    Posts:
    195
    How did you get this working? Did you manage to get unlit graph to pick shadow attenuation of main or other light? All of those tutorials seem to suggest it can work but none appear to actually work, shadow attenuation is always 1!!