Transparency Shader Not Working In Build Version

This seems to be somewhat of a common problem.

Things I have tried: Transparency broken in URP builds (works in Editor) - Unity - Ready Player Me Developer Forums

Setting Strict Shader Variant Matching to on revealed that I had objects using built in shaders that weren’t working. Changing those shaders to my instanced shaders didn’t fix anything.

I checked the logs and it appears that the shaders aren’t being stripped.

I am using a combination of clip()/discard and returning a transparent color.

this works

            half4 LitPassFragment(Varyings input) : SV_Target
            {
                UNITY_SETUP_INSTANCE_ID(input);

                // Get the XZ coordinates of the fragment
                float3 xzPos = float3(input.positionWS.x, 0, input.positionWS.z);

                // Project XZ position to screen space
                float2 screenUV = WorldToScreenUV(xzPos);

                // Sample the stencil texture using screen space UV
                float stencilValue = SAMPLE_TEXTURE2D(_StencilTex, sampler_StencilTex, screenUV).r;

                // Perform visibility check
                clip(stencilValue - _StencilThreshold);

                // Continue with the rest of the fragment shader
                half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);

                float3 normalWS = normalize(input.normalWS);
                float4 shadowCoord = TransformWorldToShadowCoord(input.positionWS);
                Light mainLight = GetMainLight(shadowCoord);
                float NdotL = saturate(dot(normalWS, mainLight.direction));
                float3 lighting = mainLight.color * NdotL * mainLight.shadowAttenuation;

                float fogFactor = ComputeFogFactor(input.positionCS.z);

                float3 finalColor = col.rgb * (lighting + unity_AmbientSky.rgb);
                finalColor = MixFog(finalColor, fogFactor);

                return half4(finalColor, col.a * _StencilOpacity);
            }

not working (always opaque)

 half4 LitPassFragment(Varyings input) : SV_Target
 {
     UNITY_SETUP_INSTANCE_ID(input);

     float distanceOrigin = length(input.positionWS.xz - _Origin.xz);
     // float3 cameraPos = _WorldSpaceCameraPos;
     // float3 wPos = input.positionWS;
     // wPos.y = 0;
     // float3 rayDirection = normalize(wPos - cameraPos);

     // float3 planePoint = float3(0, 0, 0);
     // float3 planeNormal = float3(0, 1, 0);
     // float3 intersectionPoint = IntersectRayPlane(cameraPos, rayDirection, planePoint, planeNormal);

     // float4 clipPos = mul(UNITY_MATRIX_VP, float4(intersectionPoint, 1.0));

     // float2 screenUV = (clipPos.xy / clipPos.w) * 0.5 + 0.5;


     float2 screenUV = input.screenPos.xy / input.screenPos.w;
     float stencilValue = SAMPLE_TEXTURE2D(_StencilTex, sampler_StencilTex, screenUV).r;
     half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);

     float3 normalWS = normalize(input.normalWS);
     float4 shadowCoord = TransformWorldToShadowCoord(input.positionWS);
     Light mainLight = GetMainLight(shadowCoord);
     float NdotL = saturate(dot(normalWS, mainLight.direction));
     float3 lighting = mainLight.color * NdotL * mainLight.shadowAttenuation;

     float fogFactor = ComputeFogFactor(input.positionCS.z);
     
     float alpha = stencilValue > _StencilThreshold ? _StencilOpacity : 1.0;

     //if in visible portion
     if(stencilValue > 2500){

         float3 finalColor = col.rgb * (lighting + unity_AmbientSky.rgb);
         finalColor = MixFog(finalColor, fogFactor);

          return half4(finalColor, .25);
         }

     if(stencilValue > distanceOrigin + _StOffset){
         
         discard;
     }

     float3 finalColor = col.rgb * (lighting + unity_AmbientSky.rgb);
     finalColor = MixFog(finalColor, fogFactor);

     return half4(finalColor, alpha);
     
 }