that is cool thanks a lot for sharing, unfortunatley I am not cleaver enough to understand how it fully works. I am right to assume this would only work with basic sphere and cubes?

And also all the other things you can define/describe with formulas
For example, have a look at these topics: topic 1, topic 2, topic 3.
In the third one, the heart is just a deformed sphere (reference), and the data for the three.js logo is taken from a texture

It might work to perform some kind of screenspace csg for arbitary meshes by rendering subtracting meshes separatelly in buffers using flipped faces comparing fragment depth, but that’s just a theory.

It would require at least 2 for the subtracting shapes, once regular and once flipped, as well as the original geometry being rendered double sided.

It’s not you it’s the onBeforeCompile that code just cannot not melt your mind

But yes, it evaluates these two primitives, the cube geometry has the sphere in the shader, the sphere geometry the box. The surfaces are still rendered from triangles, but clipped with the implicit shapes. You could also just do it with one and raytrace the intersection.

I wonder if this could be achieved with arbitrary shapes using depth and stencil tests.