Search Unity

[LWRP/URP] Can I make a fully transparent object cast shadows as if it's fully opaque?

Discussion in 'Universal Render Pipeline' started by Ratslayer, Jan 17, 2020.

  1. Ratslayer

    Ratslayer

    Joined:
    Feb 6, 2014
    Posts:
    37
    I want to use dissolve shader for a see-through-walls effect. However, I don't want the shadows to dissolve, I want them to remain the way they were as if the object was fully opaque. Is there a way to do it?
     
  2. Shane_Michael

    Shane_Michael

    Joined:
    Jul 8, 2013
    Posts:
    158
    Create a local copy of "Lit.shader" and "ShadowCasterPass.hlsl". Call them "LitSolidShadow.shader" and "SolidShadowCasterPass.hlsl" or whatever you'd like. Then in the base shader switch:

    Code (csharp):
    1.  
    2. #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
    3.  
    to
    Code (csharp):
    1.  
    2. #include "../SolidShadowCasterPass.hlsl"
    3.  
    In "SolidShadowCasterPass.hlsl" simply remove the line:

    Code (csharp):
    1.  
    2. Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
    3.  
    Then your shadows will always be solid regardless of your alpha settings for the lit pass.

    Alternatively, you could write a custom Alpha() function to ignore your dissolve settings but include other sources of alpha.
     
    Last edited: Jan 17, 2020
  3. Ratslayer

    Ratslayer

    Joined:
    Feb 6, 2014
    Posts:
    37
    Thanks for the quick reply. I want those changes to be used by shaders made with URP Graph. Is there an entry point where I can put this new Lit/ShadowPass shader so that URP uses it instead of the current one?
     
  4. Shane_Michael

    Shane_Michael

    Joined:
    Jul 8, 2013
    Posts:
    158
    In that case, the simplest way is to use a local copy of the URP package and modify the shadowcasting shader file directly.

    In theory, it may be be possible to create your own master node and get it to use your own custom shader code to avoid making changes to the URP code, but that isn't something I've done before and I don't use shadergraph much.
     
  5. soorya696

    soorya696

    Joined:
    Dec 13, 2018
    Posts:
    71
    Not working for me. I followed all the steps. Any idea?
    I'm using URP 7.2.1
     
  6. mokhabadi

    mokhabadi

    Joined:
    Jul 25, 2018
    Posts:
    28
    you can create an exactly same object with an opaque material and make it child of original transparent one, and then choose "shadows only" in its mesh renderer component in lighting section for "cast shadows" property, and also disable shadows for transparent one.
     
    IgorAherne and nahrens like this.
  7. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    There is no such option anymore in URP 12 to choose "cast shadows only"
     
  8. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,662
    I was going to say the same idea, duplicate the object and make one "shadows only"
    The option is there. URP 12
     

    Attached Files:

    • aaa.jpg
      aaa.jpg
      File size:
      137.5 KB
      Views:
      346
    StrangeWays777 likes this.