Seems to be using barycentric coords and is generating positions outside the triangle. Workaround is to switch to custom+uniform and feed in your own random x/y
Was a glitch. Toggling stuff fixed it.
Hello,
Actually, the barycentric coordinates aren’t clamped in surface mesh sampling, it can be confusing. Let me elaborate on this.
Short answer
With the Mesh Sampling operator, you can use raw barycentric coordinate. The barycentric coordinate defined the position of a point based on a triangle, in our case, it’s a position on a plane defined by this triangle.
The input is two-dimensional but the actual barycentric coordinate is defined by three values X, Y, Z. Z is deduced from Z = 1 - X - Y. So, if X or Y are below zero or X + Y is greater than 1, then, the sampling will be outside of the triangle.
Long answer
Let’s take this basic setup with 16 by 16 positions between zero and one.

Now, use this input for barycentric coordinate:

The red triangle highlight the edges of the current triangle. You can notice half of the sampled positions are outside the triangle, it’s expected, it corresponds to every positions where X + Y > 1
We can potentially manually clamp the sampling outside the triangle:

The problem of this solution is the several points which are collapsing on the right edge (highlighted by the green rectangle).
Actually, we want to remap a square inside a triangle, we can use the well known square root approach (see p24 “uniform distribution from two numbers in triangle generating barycentric coordinate” of this document)

But, we can also directly use the uniform sampling which is a variant of the previous square root solution,it provides a low distortion mapping (it’s a direct implementation of this paper)

Back on the raw barycentric coordinates, at some point, we would like to provide a way of clamp the value (or even better, provide the addressing mode none/clamp/wrap/mirror we are already using in several operators), this addition is one of the consideration behind the out of experimental of the Sample Mesh operator.
You can find the Visual Effect Asset I used to illustrate the previous post attached below.
Thanks. That’s useful info.
I hope this gets added to the docs so I can actually find it when I next need it!
(PS - the lack of a quick “search just this forum” button is such a pain point… Surely it can’t be that hard to fix?)