Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

LWRP Shadows

Discussion in 'Handheld AR' started by m3rt32, Mar 28, 2019.

  1. m3rt32

    m3rt32

    Joined:
    Mar 5, 2013
    Posts:
    73
    Hey! In GDC AR Foundation talk, we saw that Unity showed LWRP along with shadows in transparent surfaces. Unfortunately, it doesn't exists in lightweight rp branch in arfoundation-samples repo. So is there a way that you can provide it ? Because shadows are quite important and old shaders are not working with lwrp.
     
    Saicopate likes this.
  2. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    71
    Same issue here. This is a must-have for AR.
     
  3. DanMillerU3D

    DanMillerU3D

    Unity Technologies

    Joined:
    May 12, 2017
    Posts:
    11
    m3rt32 likes this.
  4. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    71
    I'm getting:

    Shader error in 'Custom/Shadows Only': failed to open source file: 'ShadowsOnlyPass.hlsl' at line 70 (on metal)


    Any clue where to get it from?
     
  5. m3rt32

    m3rt32

    Joined:
    Mar 5, 2013
    Posts:
    73
    @Saicopate I see an hlsl shader include in this shadowsOnly.shader file but since this is a gist I assume @DanMillerU3D didn't push push it. So, it would be great if you can also add hlsl shader @DanMillerU3D
     
  6. superjayman

    superjayman

    Joined:
    May 31, 2013
    Posts:
    178
    Where is #include "ShadowsOnlyPass.hlsl" ?
     
  7. DanMillerU3D

    DanMillerU3D

    Unity Technologies

    Joined:
    May 12, 2017
    Posts:
    11
  8. fotalik

    fotalik

    Joined:
    Sep 23, 2017
    Posts:
    24
    @DanMillerU3D Hi, when i import ShadowsOnlyPass.hlsl I get the following error:

    upload_2019-5-2_11-52-46.png
     
    a11zdf and azevedco like this.
  9. azevedco

    azevedco

    Joined:
    Mar 2, 2014
    Posts:
    3
    Wow, was literally about to post this at the exact same time.
    Currently having this issue as well.
    To add on, here is the full error message:
    Shader error in 'Custom/Shadows Only': undeclared identifier '_MainTex_ST' at Assets/_Core/Shaders/ShadowsOnlyPass.hlsl(92) (on metal)

    Compiling Vertex program
    Platform defines: UNITY_NO_DXT5nm UNITY_ENABLE_REFLECTION_BUFFERS UNITY_NO_CUBEMAP_ARRAY UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_DLDR_ENCODING
     
    Last edited: May 2, 2019
    a11zdf and fotalik like this.
  10. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    206
  11. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    929
  12. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Technologies

    Joined:
    May 5, 2014
    Posts:
    1,018
    fotalik likes this.
  13. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    206
    Thank you @steego ! This is a snapshot of the shadow I get with your shared shader, one whitish directional light and soft shadows, it comes out jagged and pitch black in my test.

    How can I remove the occlusion feature in the shader please?

    My settings below if that helps,
    Cheers, Sergio
    On Unity 2019.1.0f2, ARFoundation LWRP 2019-1 from git

    upload_2019-5-17_18-14-9.png

    upload_2019-5-17_19-17-39.png
    upload_2019-5-17_19-18-9.png
    upload_2019-5-17_19-18-31.png
     
    Last edited: May 17, 2019
  14. fotalik

    fotalik

    Joined:
    Sep 23, 2017
    Posts:
    24
    @Tarrag you can play with cascades and just decrease distance in LighweightRenderPipelineAsset - Shadows
     
  15. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    206
    Hey @fotalik , thanks for the guidance, I played with those but none did the trick (distance 0, 2, 30, 40, cascades 0, 2 - combining the two)
     
  16. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    539
    @Tarrag Distance is in unit meters, currently LWRP doesn't fade distance like the default RP, but it will cut off at that distance and give you all the resolution in that area. If you set it to 5 meters or so, the shadows will be sharp. To get soft shadows, you'll need to tick the box on your LWRP profile that says "soft shadows" - just changing the light settings has no effect.

    To make the shadow less black, just reduce the shadow strength in light settings.
     
    Tarrag likes this.
  17. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    206
    Thank you @hawken ! Yes reducing the strength setting on the actual light with some distance did it ! :)
     
  18. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    382
    @hawken What do I do then in an architectural situation where the building is 200 metres long? I need sharp shadows all the way. I would for example stand on the corner of the building looking down the long wall, or I can look from birdseye at the entire building. I can't have lowres shadows across entire thing, or only sharp shadows for 5 metres when I typically view the building from more than 5 metres away...

    Any ideas or thoughts come to mind?
     
  19. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    539
    In this instance use the cascade editor, you can set where sharp shadows end, and lower res ones start by adjusting the 3 sliders.

    In standard RP there is a visual preview of this in the editor window. It doesn't appear in LWRP but it does work.
     
  20. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    382
    yeah I tried that but it produced very destinct differences in the line where the cascade takes place. Looking down a 200m wall for example, you can clearly see the 4 different qualities
     
  21. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    539
    Theres a plugin on the asset store called “next-gen soft shadows” that might fit your needs. I’ve not tried it in AR yet so I can’t vouch for performance but it does do away with banding.
     
    newguy123 likes this.
  22. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    206
    cool plugin, says not avail for lwrp "Unity 5.6 up to 2019 (Built-in Renderer) HD & LW pipeline support coming in the future"
     
  23. Tibor-Udvari

    Tibor-Udvari

    Joined:
    Apr 1, 2015
    Posts:
    13
    Is there any way to modify this to render the shadows but also render what is behind it?
     
  24. a11zdf

    a11zdf

    Joined:
    Dec 27, 2018
    Posts:
    3
    When I tried to use this shader, the shadows work (woo!) but my shader isn't transparent... for some reason it comes out blue. Any idea what I'm doing wrong, or not understanding here?
     
  25. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    929
    Blue? No, sorry, no idea why that would happen.

    You can modify this line:
    return half4(0, 0, 0, 1 - s);
    -- s is the shadow strength, 1-s is the output alpha. You could either multiply s with some value to affect it's strength, or add some value to 1-s so it's never 0.
     
  26. a11zdf

    a11zdf

    Joined:
    Dec 27, 2018
    Posts:
    3
    it's so wierd, I can't figure it out. I placed a cube and a plane in a scene and added a mesh to them, added your shader to both and then placed a sphere on top to cast a shadow onto the surfaces. I was expecting just to see shadows on the cube and plane but instead I get a solid flat color on both. Or did I missunderstand what the shader is suppose to do? Or how to set it up?

    I'm using LWRP, and the same settings you get when you create a new LWRP project...
     

    Attached Files:

  27. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    929
    Tarrag and a11zdf like this.
  28. a11zdf

    a11zdf

    Joined:
    Dec 27, 2018
    Posts:
    3
    Thanks! Now I see what was wrong. The camera background type needs to be a solid color, I had it set to skybox... doh...
     
  29. PunkCG

    PunkCG

    Joined:
    Sep 8, 2015
    Posts:
    4
    Hi to everyone, i was looking for this kind of shader for a while, recently we changed Unity version to 2019.3.0f1, @steego shader didn´t work out of the box for me, it was related to the naming changes made to LWRP (now URP), so I made a new shader with the new includes for URP and it worked find. Sharing is caring so there you go.

    https://gist.github.com/PunkCG/a84eb78d5526ec47d6ce2aab5dd9df73
     
    chrismarch and Tarrag like this.
  30. Tech-Unity3d

    Tech-Unity3d

    Joined:
    Apr 25, 2016
    Posts:
    3
    @steego I want to know how I convert this into a transparent shadow receiver for LWRP.
     
  31. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    929
    Isn't that what it is already? Sorry I haven't looked at it in a while so not sure if it still works with the latest versions.
     
  32. Dnine

    Dnine

    Joined:
    Oct 10, 2013
    Posts:
    6
    This is not transparent in URP

     
  33. sumit9236

    sumit9236

    Joined:
    Dec 14, 2013
    Posts:
    1
    I use this with LWRP and AR foundation, its working fine. My unity3d version - 2019.2.13f
     
  34. circuscompany

    circuscompany

    Joined:
    Jan 25, 2017
    Posts:
    2
    set your material Render Queue 3000
    upload_2020-1-22_15-31-14.png

    upload_2020-1-22_15-31-43.png
     
  35. x-larrode

    x-larrode

    Joined:
    Sep 23, 2014
    Posts:
    3
    Hi, Anyone made the change for the Universal RP ?
     
    coidevoid likes this.
  36. killroy

    killroy

    Joined:
    Nov 8, 2011
    Posts:
    13
    Code (CSharp):
    1. Shader "Custom/AR Proxy"
    2. {
    3.     Properties
    4.     {
    5.     }
    6.  
    7.     SubShader
    8.     {
    9.         Tags
    10.         {
    11.             "RenderType" = "Transparent"
    12.             "RenderPipeline" = "UniversalPipeline"
    13.             "IgnoreProjector" = "True"
    14.         }
    15.         LOD 300
    16.  
    17.         Pass
    18.         {
    19.             Name "AR Proxy"
    20.             Tags
    21.             {
    22.                 "LightMode" = "UniversalForward"
    23.             }
    24.  
    25.             Blend SrcAlpha OneMinusSrcAlpha
    26.             ZWrite On
    27.             Cull Off
    28.  
    29.             HLSLPROGRAM
    30.             #pragma prefer_hlslcc gles
    31.             #pragma exclude_renderers d3d11_9x
    32.             #pragma target 2.0
    33.  
    34.             // -------------------------------------
    35.             // Material Keywords
    36.             #pragma shader_feature _ALPHATEST_ON
    37.             #pragma shader_feature _ALPHAPREMULTIPLY_ON
    38.  
    39.             // -------------------------------------
    40.             // Lightweight Pipeline keywords
    41.             #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
    42.             #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
    43.             #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
    44.             #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
    45.             #pragma multi_compile _ _SHADOWS_SOFT
    46.  
    47.             // -------------------------------------
    48.             // Unity defined keywords
    49.             #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    50.             #pragma multi_compile _ LIGHTMAP_ON
    51.  
    52.             //--------------------------------------
    53.             // GPU Instancing
    54.             #pragma multi_compile_instancing
    55.  
    56.             #pragma vertex HiddenVertex
    57.             #pragma fragment HiddenFragment
    58.  
    59.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    60.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
    61.  
    62.             struct Attributes
    63.             {
    64.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    65.                 float4 positionOS   : POSITION;
    66.             };
    67.  
    68.             struct Varyings
    69.             {
    70.                 float4 positionCS   : SV_POSITION;
    71.                 float4 shadowCoord  : TEXCOORD0;
    72.             };
    73.  
    74.             Varyings HiddenVertex(Attributes input)
    75.             {
    76.                 Varyings output = (Varyings)0;
    77.  
    78.                 UNITY_SETUP_INSTANCE_ID(input);
    79.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
    80.  
    81.                 VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
    82.  
    83.                 output.shadowCoord = GetShadowCoord(vertexInput);
    84.                 output.positionCS = vertexInput.positionCS;
    85.  
    86.                 return output;
    87.             }
    88.  
    89.             half4 HiddenFragment(Varyings input) : SV_Target
    90.             {
    91.                 UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
    92.  
    93.                 half s = MainLightRealtimeShadow(input.shadowCoord);
    94.  
    95.                 return half4(0, 0, 0, 1 - s);
    96.             }
    97.             ENDHLSL
    98.         }
    99.  
    100.         UsePass "Universal Render Pipeline/Lit/DepthOnly"
    101.     }
    102.  
    103.     FallBack "Hidden/InternalErrorShader"
    104. }
     
unityunity