Search Unity

Water shader graph: Transparency and shadows / universal render pipeline order

Discussion in 'Shader Graph' started by wahntin, Sep 20, 2019.

  1. dogsaregreat

    dogsaregreat

    Joined:
    Sep 5, 2018
    Posts:
    21
    Ty so much. It works so well. How would I go about getting it to work with spotlights?
     
    AlexGone likes this.
  2. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    This only works for me when queue is set to <2499, zwrite on (and therefore default blend mode).
    I don't get any shadows in URP 11 on transparent objects. any idea whats wrong?

    I was stupid: Obviously you have to set Transparents receive shadows in the URP renderer asset
     
    Last edited: Mar 25, 2023
  3. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    By some reason doesn't work with URP 12+
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,048
    How would you go about using this with multiple cascades?
     
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,048
    Enable shadows on transparent objects in urp settigns
     
  6. hineworks

    hineworks

    Joined:
    Nov 1, 2021
    Posts:
    4
    Change:
    #ifdef _MAIN_LIGHT_SHADOWS

    To:
    #if defined(_MAIN_LIGHT_SHADOWS) || defined(_MAIN_LIGHT_SHADOWS_CASCADE)
     
  7. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,048
    Got it working in a custom shader graph shader already, but thanks for the response!
     
  8. sihanzhang26

    sihanzhang26

    Joined:
    Jan 28, 2022
    Posts:
    1
    How to make this work with the built-in render pipeline? Need the same effect but don't know what to modify...

     
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    If you're asking how do you get shadows on transparent water with the built in renderer, the answer is you don't because it doesn't support that.
     
  10. TobiasMTM

    TobiasMTM

    Joined:
    Mar 26, 2021
    Posts:
    5
    Thank you @bgolus for your shader. I am currently using it with a camera which has a solid black background. That's probably also the reason why the shadows are only visible within the editor but not the game view.
    Could the shader be adjusted to also work with a solid black background?
     
  11. BionicWombatGames

    BionicWombatGames

    Joined:
    Oct 5, 2020
    Posts:
    33
    Did anyone ever figure out how to get this to work with RenderTextures?
     
  12. arnoldxyz

    arnoldxyz

    Joined:
    Dec 20, 2020
    Posts:
    1
    Hi everyone. Hi @bgolus thx for sharing shader.
    I have one question. if i have two or more planes under each other each of them are catching the shadow (in this exapmle from cube). is there any way to block such behaviour?
     

    Attached Files:

  13. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,048
  14. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,048
    Only way would be to disable shadow receiving on the underlying object
     
  15. matanbotansky

    matanbotansky

    Joined:
    Dec 1, 2019
    Posts:
    1
    To get this to work under Tags in the shader code, change :
    "Queue" = "Transparent-1" to "Queue" = "AlphaTest"

    If that doesn't work make sure that the inherited "Render Queue" under the shader in the material is set to "From Shader".

    Hope this helps!
     
  16. patek-monsarrat

    patek-monsarrat

    Joined:
    Nov 21, 2022
    Posts:
    4
    hey man this did not help :c I am still seeing a fully transparent plane and nothing more in URP12.
     
  17. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,048
    You can use the free asset linked. Tested in urp 12
     
  18. Tious

    Tious

    Joined:
    Jan 24, 2023
    Posts:
    1

    Hello,
    I'm having troubles with making this work. It doesn't compile correctly. I first had to change the path to Lighting.hlsl to
    "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Lighting.hlsl", but then got these 2 error messages that I don't know how to fix.

    Shader error in 'URP AR Shadow Receiver': undeclared identifier 'unity_MatrixPreviousM' at test/Library/PackageCache/com.unity.render-pipelines.core@12.1.8/ShaderLibrary/SpaceTransforms.hlsl(23) (on d3d11)

    Shader error in 'URP AR Shadow Receiver': undeclared identifier 'unity_MatrixPreviousM' at test/Library/PackageCache/com.unity.render-pipelines.core@12.1.8/ShaderLibrary/SpaceTransforms.hlsl(23) (on d3d11)

    Can somebody help me ?
     
  19. zhare86

    zhare86

    Joined:
    Mar 28, 2017
    Posts:
    28
    Couldn't make it work on Android in 2022.2.8f1 and URP 14.0.6. Interestingly enough it works in editor, but in build the shadow is not renderer. I have tried every suggestion in this thread.

    Anyone seeing similar behaviour?
     
  20. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,048
    It's a Unity bug, I have the same in my asset.
    Remove the shadow cascade keyword, or put shadow cascades higher than 1 in URP asset.

    Vote on the issue here to get it fixed:
    https://issuetracker.unity3d.com/is...rking-when-used-on-android-with-ar-foundation
     
    Radawaypl likes this.
  21. zhare86

    zhare86

    Joined:
    Mar 28, 2017
    Posts:
    28
    Removing the shadow cascade keyword was the part that I was missing. Thanks a lot!

    I ended up using your asset since I want to let my artists tweak it a bit in the SG. Good work.
     
    DevDunk likes this.
  22. vocescol

    vocescol

    Joined:
    Aug 23, 2020
    Posts:
    2
    Hello, for me, it only works in editor but no on mobile.
    Is there something that i missed?
     
  23. two7two

    two7two

    Joined:
    Aug 3, 2023
    Posts:
    9
    Hi, have you found the answer to your question? What was advised above did not help, I need shadows on both the lower object and the main one.
     
  24. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    I use this shader and seems it still works on 2022.3 URP 14

    Code (CSharp):
    1. Shader "Custom/Transparent Shadow Receiver"
    2. {
    3.     Properties
    4.     {
    5.         _ShadowColor ("Shadow Color", Color) = (0.35, 0.4, 0.45, 1.0)
    6.     }
    7.     SubShader
    8.     {
    9.         Tags
    10.         {
    11.             "RenderPipeline" = "UniversalPipeline"
    12.             "RenderType" = "Transparent"
    13.             "Queue" = "Transparent-1"
    14.         }
    15.         Pass
    16.         {
    17.             Name "ForwardLit"
    18.             Tags
    19.             {
    20.                 "LightMode" = "UniversalForward"
    21.             }
    22.             Blend DstColor Zero, Zero One
    23.             Cull Back
    24.             ZTest LEqual
    25.             ZWrite Off
    26.      
    27.             HLSLPROGRAM
    28.             #pragma vertex vert
    29.             #pragma fragment frag
    30.             #pragma prefer_hlslcc gles
    31.             #pragma exclude_renderers d3d11_9x
    32.             #pragma target 2.0
    33.             #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
    34.             #pragma multi_compile _ _SHADOWS_SOFT
    35.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
    36.             CBUFFER_START(UnityPerMaterial)
    37.                 float4 _ShadowColor;
    38.             CBUFFER_END
    39.             struct Attributes
    40.             {
    41.                 float4 positionOS : POSITION;
    42.             };
    43.             struct Varyings
    44.             {
    45.                 float4 positionCS : SV_POSITION;
    46.                 float3 positionWS : TEXCOORD0;
    47.             };
    48.             Varyings vert(Attributes input)
    49.             {
    50.                 Varyings output;
    51.                 VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
    52.                 output.positionCS = vertexInput.positionCS;
    53.                 output.positionWS = vertexInput.positionWS;
    54.                 return output;
    55.             }
    56.             half4 frag(Varyings input) : SV_Target
    57.             {
    58.                 half4 color = half4(1, 1, 1, 1);
    59.                 #if (defined(_MAIN_LIGHT_SHADOWS) || defined(_MAIN_LIGHT_SHADOWS_CASCADE) || defined(_MAIN_LIGHT_SHADOWS_SCREEN))
    60.                     VertexPositionInputs vertexInput = (VertexPositionInputs)0;
    61.                     vertexInput.positionWS = input.positionWS;
    62.                     float4 shadowCoord = GetShadowCoord(vertexInput);
    63.                     half shadowAttenutation = MainLightRealtimeShadow(shadowCoord);
    64.                     color = lerp(half4(1, 1, 1, 1), _ShadowColor, (1.0 - shadowAttenutation) * _ShadowColor.a);
    65.                     // #else
    66.                     //     color = half4(1,0,0,0.2);
    67.                 #endif
    68.                 return color;
    69.             }
    70.             ENDHLSL
    71.         }
    72.     }
    73. }
     
    chihchanglin likes this.
  25. chihchanglin

    chihchanglin

    Joined:
    Jul 24, 2015
    Posts:
    28
    Thank you!