<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2017-06-27T08:51:19.307Z
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!
Ivan Yakovlev
CC BY-SA 3.0
2017-06-20T12:12:02.687Z
2017-06-20T12:12:02.687Z
ratchet freak
<p>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). </p>

<p><a href="https://i.sstatic.net/qvcgX.png" rel="noreferrer"><img src="https://i.sstatic.net/qvcgX.png" alt="Cutting simple (convex to be more precise) figures with plane"></a></p>

<p>There are following steps:</p>

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

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

<p>3) Triangulate slice surface, assign it to <code>TRI_ABOVE</code> and <code>TRI_UNDER</code></p>

<p><strong>And now the question:</strong> </p>

<p>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.</p>

<p>I will also be thankful for sharing link on code examples calculating similar stuff.</p>

CC BY-SA 3.0
2017-06-16T09:07:05.487Z
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.
Dan Hulme
CC BY-SA 3.0
2017-06-16T16:37:37.597Z
Thanks, Dan, you are quite right, I do not have enough experience writing for GPU, I just want to understand general performance ideas.
Ivan Yakovlev
CC BY-SA 3.0
2017-06-16T21:57:33.577Z
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?
Alan Wolfe
<shader><real-time><mesh><triangulation><tesselation>
What is better to use for real-time computing Mesh - Plane intersection points, GPU or CPU?
Ivan Yakovlev
# What is better to use for real-time computing Mesh - Plane intersection points, GPU or CPU?

(Asked by: username_0 on 2017-06-16)

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](https://i.sstatic.net/qvcgX.png)](https://i.sstatic.net/qvcgX.png)

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.

**Tags:** shader, real-time, mesh, triangulation, tesselation

> **Comments:**
> **username_1**: 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.  
> **username_0**: Thanks, Dan, you are quite right, I do not have enough experience writing for GPU, I just want to understand general performance ideas.  
> **username_2**: 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?  

---

## 1 answers

### Answer by username_3 on 2017-06-20. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_0**: 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!  

---

