- Home /
Shader that clips pixels outside of defined polygon
Basically is there a way to implement a [Point In Polygon Algorithm][1] in a shader? The shader takes as input 4 texture/uv coordinates and clips all pixels that lay outside of the convex polygon described by those 4 coordinates.
I have looked around but can't seem to find anything even close.
For reference this is an implementation in c++:
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{
int i, j, c = 0;
for (i = 0, j = nvert-1; i < nvert; j = i++) {
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
c = !c;
}
return c;
}
where nvert is the number of vertices in the polygon, vertx* and1 verty* are arrays containing said vertices and testx and testy are x,y of point to test. [1]: https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html
Comment
Did you find the answer for this question? Can you share it
Your answer
