I’ve uploaded a patch that adds SDF functions to the Shader nodes in Blender. The patch is mostly working ok but it could really do with some artist feedback to polish how these functions should be implemented. If you are able to build Blender, please try out the patch. If you have some ideas on how you would use SDF functions that would be great too.
Can you explain in more practical terms what such a node will be useful for? With an example node setup?
SDF functions like this are quite useful in the demo scene, but it’s not as obvious they are useful in Blender shader nodes. If we supported rendering signed distance fields as surfaces directly, by using the signed distance for ray marching, then it would make a bit more sense. Right now it feels like a math function made for a use case we don’t have yet?
The current nodes are somewhat difficult to control, and lack some basic functionality like csg and shape blending (you can still do it, but you have to know the math behind it: not very artist friendly) so best i could do on short notice is this shoddy rivet looking shader
Using SDF for ray marching is outside the scope of this patch but having SDF functions available in shader nodes provide a wide range of use cases. It also expands the artists toolset.
2D for texture generation
3D functions for manipulating volume and displacement
Had another whirl at this branch last night, it’s still remarkably hard to control things here’s some suggestions (they are just that, they could be bad ideas, use your own judgment there)
options that do nothing be removed, i tested with a 2d circle and i’m still unsure if any of the parameters actually do anything.
coordinate system, most sdfs work in the -1 … 1 range, most UV’s are in 0…1 range…solved it with a mapping node, but that may not be obvious to every user. perhaps a dedicated node would help? uv -> sdf coords?
most SDF shaders on shadertoy use a visualizer to easily visualize the field, we should have one.
The textures should just be the base properties, ie circle should just have one property: size if you want to make it annular that’s the job of a different node, conflating too many options into a single node just makes it harder to work with than it should .
I’m in process of working through the patch to make it easier to use. I’ll update d.b.o with working changes as I go.
options: Options for each primitive vary a lot. I’m also adding extra primitives too. This will be simplified but feedback will be useful after the next patch or two!.
visualizer: In the test blend on d.b.o there is a shader that can be used. This is probably best left out of the patch as it stands.
annular/thickness: Having these options on the primitive node is really useful as they will be used a lot and adding extra nodes all the time will be annoying! At least I’ll keep them in until it’s closer to being finished.
This looks awesome! I really like how much effort you’re putting into getting the node interface right. Maybe “K” and “Radius2” could still change? I’m guessing “Radius and Radius2” are the inner and outer radii.
Also, I briefly looked around the internet and I haven’t found what SDF actually stands for. Shadertoy distance functions? I’ve noticed some acronyms being added to Blender recently which can make it harder for new people to learn. Could it make sense to expand the name and not use the acronym? I understand there are probably lots of reasons why it wouldn’t.