Seems like this code might be the solution.
Can anyone explain what this code does?
sampler linearSampler = sampler(
filter::linear,
mip_filter::linear,
max_anisotropy(8)
);
float center = u_displacementTexture.sample(linearSampler, _surface.diffuseTexcoord).r;
float x_up = u_displacementTexture.sample(linearSampler, _surface.diffuseTexcoord, int2(1, 0)).r;
float x_down = u_displacementTexture.sample(linearSampler, _surface.diffuseTexcoord, int2(-1, 0)).r;
float y_up = u_displacementTexture.sample(linearSampler, _surface.diffuseTexcoord, int2(0, 1)).r;
float y_down = u_displacementTexture.sample(linearSampler, _surface.diffuseTexcoord, int2(0, -1)).r;
float threshold = 0.01 / scn_commonprofile.displacementIntensity;
if (abs(x_up - center) > threshold || abs(x_down - center) > threshold || abs(y_up - center) > threshold || abs(y_down - center) > threshold) {
discard_fragment();
}