Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question In Unity URP, AlphaTest Shader's shadows are displayed the same

Discussion in 'Shaders' started by Vindy_, Mar 9, 2021.

  1. Vindy_

    Vindy_

    Joined:
    Dec 6, 2018
    Posts:
    2
    I am a developer who has just started programming shaders.

    I'm making a shader that renders shadows while using alphatest in a Unity URP environment.

    However, as shown in the following figure, there is a problem that the shadows are rendered the same even though they are different objects.







    I checked in the Frame Debugger that the texture doesn't change when creating the Shadowmap.


    upload_2021-3-9_16-41-43.png

    upload_2021-3-9_16-41-55.png


    The project environment is as follows:
    Unity version: 2019.4.21
    URP version: 7.5.3
    Project repository: https://github.com/lklab/UnityURPAlphaTestShadow
    My shader code: https://github.com/lklab/UnityURPAl...Assets/Shaders/URPAlphaTestUnlitShadow.shader


    I would be very grateful if you could help.

    ※ I'm already using Opaque and AlphaTest (AlphaClip).
     
    Last edited: Mar 9, 2021
  2. Vindy_

    Vindy_

    Joined:
    Dec 6, 2018
    Posts:
    2
    I solved it.
    The problem was due to the SRP batcher.
    I solved it by writing the same CBUFFER for all passes in the shader like this:

    Code (CSharp):
    1. TEXTURE2D(_MainTex);
    2. TEXTURE2D(_LightTex);
    3. SAMPLER(sampler_MainTex);
    4. SAMPLER(sampler_LightTex);
    5.  
    6. CBUFFER_START(UnityPerMaterial)
    7. half4 _MainTex_ST;
    8. half4 _LightTex_ST;
    9. CBUFFER_END
    I have also updated the Project repository.
     
    PutridEx likes this.