barycentric hecking interpolation!!
a little thread on a neat way to interpolate across a triangle!
say you have three points, each with a color - how do you get the blended color for an arbitrary point inside? 🤔
Conversation
Replying to
byerp (coining this term now~) uses the area of the triangle on the *opposite* side of each vertex, as a fraction of the total area, to determine how much influence each vertex has!
❤💙💚
these three influences, or, weights, together form the barycentric coordinate of that point
GIF
7
21
240
we can then multiply each weight with their corresponding color, and add them all up, to get the final blended color at that coordinate!
since models in games are made of triangles, this is actually how mesh data like normals, UVs, vertex colors etc. is interpolated by your GPU!
5
5
99
that's not to say it's perfect - this can only interpolate the data on the triangle, but there are cases where you want to use 4 points, where two barycentric interpolations can't really get you an accurate result :c
Quote Tweet
implemented proper bilinear color interpolation for my quad primitive and holy heck - it's *wild* how wrong barycentric is on even simple shapes like this
how do games get away with this it's all a facade gosh
Show this thread
4
3
68
anyhow that's it, it's getting super late and I need to feed thor~
as usual, if you want to support what I do, please consider supporting me on Patreon!
it really does help me stay afloat and do things like this 💖
3
1
43
Replying to
I'd do something like this:
- calc dist to each point
- divide each dist by the sum of all distances (to get normalized dist)
- each color weight is color * (1-normDist)
- add weighted colors together
1
2
Replying to
this doesn't work as it's not a balanced weighted sum anymore, the weights have to add up to 1, which, they don't using this method
consider the case where evaluating the point at vertex A
A*(1-0)+
B*(1-.5)+
C*(1-.5)
=
A*(1)+
B*(.5)+
C*(.5)
1
Show replies
One neat thing about barycentric coordinates is how easy they make it to find the points of intersection between a ray tangent to a given triangle, and the edges of the triangle!! Its great for tracing geodesics on triangle meshes!!!
1
2
8
Replying to
off topic. Do you have any recommends or refs for doing something like sliding verts along edges? Trying to think how to do it, but also be able to rotate them via a projected plane between them. So a edge loop through a cylinder , if you rotate, the verts slide on those edges.
Replying to
Very cool. I needed something like this for a project. I put together an only-slightly-broken version on observablehq.com/@amoeba/byerpi. Mouse isn't quite right but it still works. Thanks for sharing.





