Get positive vertex co-ordinates for mesh when inside vertex shader, to prevent heightmap repetition

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By renderfix

I have got a plane mesh of size 2 by 2, subdivided 32 times as in: Vertex displacement with shaders — Godot Engine (3.0) documentation in English
I am applying a heightmap texture on it as:

shader_type spatial;
uniform sampler2D htmap;
void vertex() {
    float height = texture(htmap, VERTEX.xz).x;
    VERTEX.y += height;

Since the x & z co-ordinates go from -1 to +1, my heightmap gets repeated in the 4 quadrants:

I can pass the mesh size to prevent this(2.0 in this case as its a square mesh). But whats the usual way to avoid this?

:bust_in_silhouette: Reply From: Lola

You should use the UVs when sampling a texture:

float height = texture(htmap, UV);

In the case of a PlaneMesh the UVs are setup for you the way you expect them to be in this case.