Dynamic CSG at every frame render

In a similar scene below, I want to move yellow part continuously and remove the intersection from the main body. (Cutting the main body with yellow part)
All examples I could find demonstrates a CSG subtract operation only at one time. But I want this at every frame render. When I put CSG operation in scene.registerAfterRender, the app hangs.
Any help appreciated.

I would personally write a simple shader to invert intersecting normals on your rendered mesh. Then this could be set to invert normals at any distance from intersection. Continuous CSG will certainly over task your GPU. Although this shader doesn’t exist yet, I can’t imagine it would take much effort to write.


1 Like

yep as @Galen said you may need to consider other options as CSG is cool but slow

Potential idea:

  • Do it not on every frame but maybe once per second
  • Can that be done server side?
  • Maybe try to simplify your meshes to boost the CSG process

Thank you for ideas @Deltakosh
Meshes are already simple enough. Maybe doing CSG process in some interval can be solution. By the way I will move one mesh. Between two interval there will be some space. I think I should take into account that space as well. What would you recommend? somehow creating a union of meshes in t0 and t1 and the space between them?

Hi @Galen. The idea seems nice. Could you explain a little more detailed?
For getting intersection will I use CSG? Then how will I apply inverting normals? This will result the intersection being invisible, right?


I personally wouldn’t use CSG for your needs. I think the best solution is to turn off the camera to render back face normals, and apply a shader to invert the normals on your rendered mesh as it moves. This would be a very fast process in real time.


You don’t really need a shader. Just monitor collisions, and inverse normals based on proximity. How to calculate? You are moving on a single axis, and once a collision is registered, simply inverse the normals on part of the mesh based on proximity to the intersecting mesh’s center axis.


1 Like

Hello @Ergin_Akin, I’m in a similar situation right know, how did you finally solve this?