I want to write plugin (library) for Unity3d (it doesn't matter which framework I will choose for this, question is ), for cutting arbitrary mesh with plane (for simplicity it will be plane for beginning).

Cutting simple (convex to be more precise) figures with plane

There are following steps:

1) check every triangle whether it lies above, under plane or intersected by plane, assign all vertices to VER_ABOVE or VER_UNDER lists, recalculate triangles, put them in TRI_ABOVE or TRI_UNDER lists

2) Split intersected triangles into triangle and quadrilateral, triangulate last one and put them in corresponding lists (TRI_ABOVE or TRI_UNDER)

3) Triangulate slice surface, assign it to TRI_ABOVE and TRI_UNDER

And now the question:

Where it is better to calculate intersections, triangulation (for example I will use Constrained Delaunay Triangulation or Sweep Line Non-Convex Polygonal Triangulation cutting into monotone polygonals) and other stuff: on CPU or on GPU (using Shaders), if someone could explain me general pipeline from loading cashing mesh to memory and so on on GPU and on CPU, so I can better understand the most time consuming actions and can optimize some stuff.

I will also be thankful for sharing link on code examples calculating similar stuff.

  • 3
    $\begingroup$ In general it's about 10 times harder to get your code correct on the GPU than on the CPU, so regardless of where it's faster, I'd recommend you start by getting everything working on the CPU. $\endgroup$
    – Dan Hulme
    Jun 16, 2017 at 9:07
  • $\begingroup$ Thanks, Dan, you are quite right, I do not have enough experience writing for GPU, I just want to understand general performance ideas. $\endgroup$ Jun 16, 2017 at 16:37
  • $\begingroup$ It really depends on what your goals are. Is this something you want to do in real time? During runtime of your game? During "real time" editing in the editor? How complex are the meshes you intend on splitting? $\endgroup$
    – Alan Wolfe
    Jun 16, 2017 at 21:57

1 Answer 1


doing the calculation to decide whether a point is on one side of a plane or the other is very simple (a single dot product). Doing that 3 times and having a special case when they don't match to split the triangle is pretty fast. It's also a parallel problem. The hardest part is reserving the space for the output.

Preparing the data to start computing this on the gpu is already enough overhead that it's not worth doing it on the gpu unless the mesh is very big or you are splitting it multiple times (due to the plane moving for example). Or the data is already in good enough condition to be sent over to the gpu directly through DMA without the cpu needing to touch it at all.

  • $\begingroup$ Well, yeah, you are quite right. I'd better do it on CPU and if I am not happy with performance, I'll try to find different ways. Thank you! $\endgroup$ Jun 27, 2017 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.