Search code examples
openglgraphicsprojectionlinear-interpolation

What's the relationship between the barycentric coordinates of triangle in clip space and the one in screen space


Suppose I have a triangle say(PC0,PC1,PC2), and its barycentric coordinates is((1,0),(0,1),(0,0)), they are all in clip space.

And now I want calculate the interpolated barycentric coordinates in screen space, how can I do that so it could be correct? I have see something like perspective correct interpolation, but I cant find a good mapping relationship bewteen them.


Solution

  • The conversion from screen-space barycentric (b0,b1,b2) to clip-space barycentric (B0,B1,B2) is given by:

                    (b0/w0, b1/w1, b2/w2)
    (B0, B1, B2) = -----------------------
                    b0/w0 + b1/w1 + b2/w2
    

    Where (w0,w1,w2) are the w-coordinates of the three vertices of the triangle, as set by the vertex shader. (See How exactly does OpenGL do perspectively correct linear interpolation?).

    The inverse transformation is given by:

                    (B0*w0, B1*w1, B2*w2)
    (b0, b1, b2) = -----------------------
                    B0*w0 + B1*w1 + B2*w2