Search code examples
unity-game-engineshadershadowurp

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


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.

figure1

figure2

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

frame debugger 1

frame debugger 2

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/UnityURPAlphaTestShadow/blob/master/Assets/Shaders/URPAlphaTestUnlitShadow.shader

I would be very grateful if you could help.

※ I'm already using Opaque and AlphaTest (AlphaClip).


Solution

  • 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:

    TEXTURE2D(_MainTex);
    TEXTURE2D(_LightTex);
    SAMPLER(sampler_MainTex);
    SAMPLER(sampler_LightTex);
    
    CBUFFER_START(UnityPerMaterial)
    half4 _MainTex_ST;
    half4 _LightTex_ST;
    CBUFFER_END
    

    I have also updated the Project repository.