LWRP/URP Shader No lighting/shadows

Hi, I’m trying to shade my geometry shader and I’m having issues getting the shadows to display correctly. It seems like they’re in the wrong space, but I used TransformObjectToWorld so I think it should be correct…

This is my frag function:

/* ==============================================================
                FRAG
            ===============================================================*/
           
            float4 Frag (g2f input) : SV_Target
            {   
                UNITY_SETUP_INSTANCE_ID(input);
                float4 col;
               
                float4 shadowCoord = TransformWorldToShadowCoord(input.positionWS);
                Light mainLight = GetMainLight(shadowCoord);
               
                float shadowValue = SampleScreenSpaceShadowmap(shadowCoord);
                float4 lightValue = float4(mainLight.color, 1.0);
               
                col = lerp(
                          UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _BottomColor),
                          UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _TopColor),
                          input.uv.y
                          );
               
                return col * lightValue * shadowValue;
            }

And this is the result:

Anyone have any ideas?

GetMainLight already computes shadow attenuation for you.

Replace this line:
float shadowValue = SampleScreenSpaceShadowmap(shadowCoord);

With this line:

float shadowValue = mainLight.shadowAttenuation;

Also make sure you have the following pragma compiles in your custom shader:

#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE

Hi, thanks for the reply; I really appreciate it! Unfortunately, that still gives me shadow values that are all messed up (in the wrong space or something. I’ve tried converting the position fed to TransformWorldToShadowCoord to different spaces with no luck. Do I have to transform the shadow attenuation? I feel like that should already be in screen space?

Current shadow values show values for objects in the wrong place, projected incorrectly:
5342052--539202--upload_2020-1-6_6-40-43.png

You should just multiply the color by shadowAttenuation. As a debug you can also make the shader output shadowAttenuation.