Help with Cutting Holes Using Alpha in a customized URP Terrain Shader - Stretched Output Issue

Hi everyone,

I’m working on cutting holes in the terrain using an alpha channel with shaders. I managed to get it working using Shader Graph, but I’m having trouble integrating it with the URP terrain shader.

Shader Graph Example:


Scene View:
image
Game View (Ground Cropped, Working):

I tried adding the functionality in the URP terrain shader by modifying the ClipHoles function in TerrainLitInput.hlsl:

void ClipHoles(float2 uv, float3 positionWS)
{
    //based from https://discussions.unity.com/t/screen-position-from-another-cam/896789/6
    float4 matrixxWorld = mul(_MainCamMatrix_VP, positionWS);
    float2 finalUV = (matrixxWorld.xy / matrixxWorld.w) * 0.5 + 0.5;
    
    float hole = SAMPLE_TEXTURE2D(_TerrainHolesTexture, sampler_TerrainHolesTexture, uv).r;
    float holeCustom = SAMPLE_TEXTURE2D(_Holes, sampler_TerrainHolesTexture, finalUV).r;

    float holeFinal = 1 - (hole * (1 - holeCustom)); 
    clip(holeFinal > 0 ? -1 : 1);
    
    
    //if(positionWS.x > 8) clip(-1); //aligns with sahder graph, world position correct (checked with y also)
    
    //if (_MainCamMatrix_VP[0][0] < 45 && _MainCamMatrix_VP[0][0] > 38) clip(-1); // value was 41.sdfse when i tested, checked, it's valid

}

However, the output is stretched and seems to be cropped. I’m not sure what I’m missing or if there’s something wrong with how I’m calculating the UVs.

Stretched Output:


Shader Graph Cutout (Showing the Holes positions on top):

My head is fuming from this issue! Could anyone help me understand what might be going wrong?

(First time posting, so apologies if I missed any details or formatting.)