I have a textured triangle that I’m trying to subdivide, but I’m not sure how to calculate the UV coordinates for the smaller triangles. I’ve googled around and it seems like I need to use barycentric coordinates for this, but I don’t understand how they would work in this situation.
Can’t I just create a 2D triangle out of the 3 sets of UV coordinates and subdivide that alongside the actual triangle (using position data from that imaginary triangle as UV data for the real one)?
There are multiple ways to determine the coordinates of a point inside a triangle. Barycentric coordinates are one of them. For the simple case above one could come up with a relatively simple solution. But this won’t do you any good as soon as the tesselation algorithm and the base triangle changes. You should go for a general approach - like barycentric coordinates. It’s not that hard.
Barycentric coordinate system - Wikipedia shows it pretty straightforwardly. Write yourself a function which takes the three known vertices as inputs and spits out the barycentric coordinates lambda{1-3}. Then takes these coefficients and determine the uv-coordinate by
Thanks! That formula worked surprisingly well. I had a little trouble at first because I didn’t know that the lambda values were supposed to be calculated from the triangle that the UV coordinates make up, and not the 3D position coordinates of triangle i’m subdividing.