Vector Math, Polygon Lerp

So I don’t know exactly what this would be called, but here is an explanation of my problem.

I have a polygon like this:

Each corner of the polygon has it’s position and a height value assigned to it, I need to assign a height value to each pixel inside the polygon, interpolating between each corner equally.

My inital thought was to get the two closest corners and then lerp the values of their heights, based on the current pixels distance to one of the nodes. Which seems to work, but it results in something like this:

Would anyone be able to help me understand how I go about solving my problem, I’m working on this for my project for my degree. So I’d appreciate a point in the right direction, not code being provided.


You’re giving a few example values at points in 2D space, and want other points to be defined based on those points. There’s no correct way to do this, as there’s no intuitive correct answer. For example, you probably don’t want discontinuities, but that’s not a given.

What’s sure, though, is that this is very, very similar to 2D animation blending. Rune
Skovbo
Johansen (who works for Unity) discusses approaches to that in his master’s thesis. Chapter 6 about motion blending touches on various ways to find a function for blending between two animations in a 2D blend tree, but all of that is perfectly applicable to blending between heights in… whatever you’re making.

Maybe calculate a mid point (and it’s average height) and use barycentric interpolation in whichever triangle (mid point + edge) the current pixel is in?

1 Like

Thanks I’ll look into his approach and to explain what this is for, it’s just terrain generation using the Voronoi algorithm. I’ve everything working, I just want the values inside the Voronoi Regions to be smoothed, so I can convert it all into a height map the Unity Terrain to use.

Hmm, thank’s I’ll read up on that.

Thanks for recommending Barycentric, after reading up on it. I manged to implement it in a way that allows me to achieve what I was looking to do.
3275880--253278--Untitled.jpg

I’ll now be able to lerp the height values of the points in each node, based on the value that Barycentric has passed back.

1 Like