0
\$\begingroup\$

I guess the verb form of gradient is "gradate" and not "gradiate"?

Hi! I have a set of 2D points (actually 3D, but we can ignore the Y axis unless it's trivial) bound to color values. I'd like to know, given an arbitrary point in space, what the color would be if there was a smooth gradient between all of the defined points.

Here's a visual of what these points might look like. enter image description here

In the above image, I would expect the color value to be an approximately equal mix between the Red, Cyan, Yellow and Purple points that surround the gizmo's location, since it lies approximately central to these four points.

This is a bit more complicated than I originally anticipated, because:

  • Simply averaging all of the points and weighting by distance will not work. If I ask for the color at the red point's exact position, I want red's exact color - with zero influence from any other point.

  • Likewise, if I'm inside the "quad" of 4 of the closest points, there should be no influence from points outside of that quad - as the surrounding points should "block" their influence.

I'm guessing this isn't a particularly unique problem, so if this algorithm has a name, feel free to let me know what it is and I'll chase it down! I'm having a surprising amount of difficulty Googling an example - possibly because I just don't have the right keywords.

Thanks!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Difficult problem to define... for example your gizmo is in the red-teal-purple-yellow quad. It is also in the red-green-teal-yellow quad. Not to mention the red-teal-yellow-blue quad. Depending on your position, the closest points might not give you consistent results \$\endgroup\$
    – Jay
    Dec 14, 2021 at 1:09

1 Answer 1

3
\$\begingroup\$

An idea that occurs to me would be to use something like Voronoi cells to split the area by color, and sort of blend them into each other. Essentially past the border between two colors use a smooth falloff to weight either intruding color. I'm not quite sure how to go about actually implementing such a thing though. You could also create a mesh of triangles between all the points and then sample the point's color as a sum of every triangle's blended color at that point, also with a falloff for how relevant each triangle would be for the point. This might actually be easier than my first method. Finally, you could adjust the weights so that not only distance but being closest is a contributing factor, such that other colors fall off rapidly by not being closest.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .