Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Unity URP Unlit shader shadow bug

Discussion in 'Scripting' started by Huseyin4040, May 11, 2024.

  1. Huseyin4040

    Huseyin4040

    Joined:
    Jul 11, 2022
    Posts:
    4
    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
    float4 _MainColor;

    struct VertexInput{
    float3 positionOS : POSITION;
    float3 normalOS : NORMAL;
    };
    struct VertexOutput{
    float4 positionCS: SV_POSITION;
    float3 positionWS :TEXCOORD0;
    float4 normalWS : TEXCOORD1;
    float4 shadowCoords : TEXCOORD2;
    };
    VertexOutput vert(VertexInput v){
    VertexOutput o;
    VertexPositionInputs posnInput = GetVertexPositionInputs(v.positionOS);
    VertexNormalInputs normnInput = GetVertexNormalInputs(v.normalOS);
    o.normalWS = normalize(float4(normnInput.normalWS,1));
    o.positionCS = posnInput.positionCS;
    o.positionWS = posnInput.positionWS;
    o.shadowCoords = GetShadowCoord(posnInput);

    return o;
    }
    half4 frag(VertexOutput i) :SV_TARGET{


    Light mainLight = GetMainLight(i.shadowCoords);
    half3 Direction = mainLight.direction;
    half3 Color = mainLight.color;
    half DistanceAtten = mainLight.distanceAttenuation;
    half ShadowAtten = mainLight.shadowAttenuation;

    half3 lambertianDiffuse = saturate(dot(i.normalWS,Direction));
    half3 lightColor = Color*(ShadowAtten*DistanceAtten);
    half3 finalCol = lambertianDiffuse*lightColor;


    return half4(finalCol,1);
    }




    upload_2024-5-11_17-41-20.png