Custom Procedural CSG Code

I’m trying to make a custom CSG mode for a more…gooey version of Smooth Union. I built a shadertoy example (the left is like the built-in smooth union, and the right closer to what I want):

But I’m unclear on what the structure of the custom code should be. Does anyone have an example they could share to get me started?



The custom CSG code box is primarily designed for creating your own custom generative shapes, not blend modes - but that is a great idea. I’ll talk to the dev team about what we can do to add that sort of workflow.

– Ryan

I meant the “custom code” option on the CSG Mode parameter of the procedural 3d primitive node. I was able to get it working. Leaving these breadcrumbs for the next person to follow.

Info on the variables exposed is here:

Good code examples of sdf/csg modes:

One gotcha: it appears that the custom code parameter does not display changes to the code text unless you switch away from the “Custom Code” CSG Mode to a standard mode, and then switch back.

I used the following code:
float k = blendWeight;
float h = max(k-abs(dist-sdfValue),0.0);
sdfValue = min(dist, sdfValue) - hh0.25/k;

To make something that looks like this shadertoy example on the right:

Basically, it takes the blendweight parameter and uses it to make a a Smooth Union more… gooey. Ideally what I wanted was to preserve the mass of each object and just have them be attracted to each other, but this was close enough to function for what I needed.


Hey Dan

This is great thanks, hope you build more shaders

really would love a way to blend textures sets by procedurals
right now I’m throwing things back and forth from Houdini

Also to be able to split procedurals up in groups