Artifacts when sampling heightmap in vertex-shader


I have a surface shader that performs a vertex texture fetch as such:

void vert (inout appdata_full v) {
            float4 tex = tex2Dlod (_MainTex, float4(v.texcoord.xy, 0, 0));
            v.vertex.y += tex.r * _Height;

The weird artifacts occur at the edges of the mesh, sometimes only when x = 0 but sometimes when x is on the far edge. It does this even using different heightmaps.

I tried using different texture formats like RGBA32 and lower precision ones, different resolutions like 128, 129 and double that etc - nothing seems to work.

I even tried recreating the problem on the CPU by using the exact same heightmap but sampling the red channel on the CPU instead and displacing the actual vertices of the mesh - this resulted in a perfectly good mesh so I conclude that it probably isn’t the heightmaps (they’re procedural).

I’m going nuts, what am I missing here?

Vertex shader displacement:

CPU displacement:

I had completely missed the TextureWrapMode. If anyone encounters this problem it’s solved by:

texture.wrapMode = TextureWrapMode.Clamp;