ShadowSamplingMode.RawDepth and Graphics.DrawMesh

UPDATE IN THE COMMENTS
Hey everybody. Im trying to do custom shadow sampling in my shader by getting a raw depth shadow map from a directional light as shown in the SetShadowSamplingMode example here (Unity - Scripting API: Rendering.CommandBuffer.SetShadowSamplingMode) and everything works fine with scene game objects. However i have a custom terrain thats is rendered through Graphics.DrawMesh, and it appears to be wrong on the shadowmap. Heres the screenshot of the problem:


As you can see, the sphere and the orange car both cast correct shadows (they are scene gameobjects). But shadows from terrain are completely wrong, all patchy and gradienty. Am i doing something wrong? Is this an normal behaviour? What can i do to make it output proper depth?
This is how i sample shadow in the shader btw, if its important:

half3 shadCoords = mul(unity_WorldToShadow[0], float4(i.wpos, 1)).xyz;
float shad = UNITY_SAMPLE_SHADOW(_MyShadowMap, shadCoords);

Actually nevermind, i just understood that its not the DrawMesh problem, scene objects also have incorrect shadows. The problem is that the parts of the objects that are below my shader object, are still casting shadows on the surface of my object, when they shouldnt (you can see that on the orange car for example). That means my shadow sampling code is wrong. Do i need to manually do depth checks then? I assumed that shadCoord already contains depth from the light source in the .w component after multiplication by the WorldToShadow matrix. But apparently it doesnt.