Here's a little script and some shader functions that let you write out an object's transformation matrix and then read it as a Signed Distance Field (SDF) in a shader.
I've included 3 SDFs, a basic sphere, a rounded box with adjustable roundness, and a capsule. They can be freely moved, rotated and scaled.
I'm so thankful to the SDF examples by Inigo Quilez here:
https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
It would be cool to add a few more primitive shapes to the mix in the future.
Each SDF type requires that the appropriate shader function be brought into your shader. If you want to use more than one of the same type, you'll need to use multiple shader functions, and use new Matrix4x4 inputs with names that match the propertyName in the SDFShaderEntity object.
The included shader example has all three SDFs, using local shader feature keywords to switch between them. That's only something you can do in the editor, not in a build, so you might want to want to strip out the "material.EnableKeyword" stuff in the script, and just have the shaders set up in advance for the shapes you know you're going to use.
I've used it for a cutaway effect here, but the output of the shader functions is just a simple 0-1 gradient of the inside of the SDF, so they could also be used for masks for other shader shenanigans.
I hope this is useful for people! Let me know if you have any questions on discord or in the comments. I'll make a few variations based on this soon, I can already think of a few exciting effects that could be made with this type of stuff.
TODO: I know there's a way to fill in the holes with Stencil Buffers, but I haven't got it working yet.