I have a polygon (for simplicity we can assume it is a cube) as shown in Picture 1 where each vertex has an attribute value as indicated in Picture 2. I would like to cut the cube with an infinite plane. The resultant shape is a plane with 4 points. I would like to calculate the resulting attribute value for each point of the plane by linear interpolation (Picture 3).
The end goal is to provide colors (vertex colors or face colors) to this plane based on some color legend.
I suspect the best way to achieve this is through some shaders and GLSL.
Any suggestions from where to start or some similar examples of how to do this.
You could do that with shaders and GLSL and stuff, but it would be hard. Why? Because you donât know ahead of time how many edges/triangles you would need to cut ahead of time, and doing it in a distributed manner just isnât trivial. You could throw every triangle at the GPU and ask if itâs being cut by the plane, but thatâs not optimal and youâd have to assemble things on the CPU anyway.
Anyway, enough of the reasons why itâs not a good idea, the actual solution is along the lines of âcuttingâ or âslicingâ a mesh with a plane. Or âbisectingâ. Try searching for that, I remember at least a few topic here on the forum that deal with this exact problem as well as a handful of github projects that do the same. Good luck!
Some optmizations can be done, like checking if the segment cross the plane before calculating its line equation. But even with that, this would be too slow to do in a GPU.