I need to interpolate the red triangle on the left from white to black as depicted in the figure. I've extended it to a parallelogram to better understand the kind of interpolation that i'm trying to achieve.
By assigning 1 to the white extremes of the triangle and zero to the bottom i'm not getting the expected results, I thought that this specific case wouldn't cause perspective coordinates issues due to the fact that triangle values are still mapped to a parallelogram and not a trapezoid, but I guess I was wrong.
One solution would be as drawn in the right figure to find p1 by computing a vector intersection, compute the lenght of frag - p1 and compare it to length(v3 - v1) which would be too overkill for the fragment shader i'm using.
Another also expensive solution would be to store the angle formed from the dots of the vertices vectors, and use a bit of trigonometry with p2 and frag to get a point in v1 - v3 to interpolate with the full segment, which is also crazy inefficient
The end goal would be to draw a convex hull made of triangles from it's center to it's edges in a black to white fashion
Edit: this question was marked as 'exact duplicate' of another one that as far as my understanding goes, has little to with what I asked. None of the provided responses helps my case and I'd like to at least know where exactly it could be defined as 'exact duplicate'