Page MenuHome

WIP Shader: SDF Node
Needs ReviewPublic

Authored by Charlie Jolly (charlie) on Dec 21 2019, 4:04 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Shader node providing 2D and 3D SDF functions.

Based on Inigo Quilez SDF work here: https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm

Notes: Some functions have been normalised to 1.0 size.

Tips: Combining SDF outputs using maths node min max functions provides a way to create unions, subtractions and intersections.

Rounding = moves the threshold of the sdf function. This is equivalent of subtracting/adding values.
Thickness = this creates an edge at the threshold and creates inset effect.

Edges/Radius: Used with Star function only.

Bugs: Issue with texture mapping in cycles. Not sure if this is a bug in this code or elsewhere.

Diff Detail

Repository
rB Blender
Branch
master
Build Status
Buildable 6092
Build 6092: arc lint + arc unit

Event Timeline

Charlie Jolly (charlie) retitled this revision from Shader: SDF Node to WIP Shader: SDF Node.Dec 21 2019, 4:21 AM
Charlie Jolly (charlie) edited the summary of this revision. (Show Details)

I LOVE the idea of having an SDF shader, and I am familiar with the math behind them, however, oh boy, this implementation is hard to control

I don't think this is quite ready for review just yet, i think once there is confirmation from the core team that a patch like this would not be flat out rejected for some reason it is probably be best to move over to devtalk and work with some artists to 'spit and shine' these nodes and make them user friendly.

But from my first round of playing with just the 2d Box

  • There's 2 vector sockets, and it's virtually impossible to see what their purpose is or what their values are , mouse over just gives you 'input value used for unconnected socket'.... very helpful.. one of them is the size of the box I found out.
  • Scale, no idea what this does, sometimes it works, sometimes it doesn't.
  • float socket size Size, no idea, perhaps this meant to be hidden for box 2d?
  • Rounding, grows the size of the shape, while it makes sense with the math behind it, artist wise you now have to twiddle with the size of the box to correct for that which is not great.
  • Thickness, this should probably be extracted into its own sdf annular node, i'll probably want to use this later on once i combined a few shapes, on top of that having control of the location (inside the shape, on the edge, outside the shape) would be nice.
  • Lack of union node, sure i can with this with the math node for a simple union since i know the math, artists won't and even when you do know the math the smooth variants (which are the ones you really want) are quite a pain to implement in a node group.
  • 2d sdf shapes work best in the -1 .. 1 range, most people will probably stick UV coords into this which will lead to 1/4 of the shape just sitting in a cornet which will confuse people

Overall, I see great potential here but it needs some love

@LazyDodo (LazyDodo) Great feedback. Yeah the controls are a bit sensitive in its current state as they need their ranges adjusting. The socke

  • There's 2 vector sockets, and it's virtually impossible to see what their purpose is or what their values are , mouse over just gives you 'input value used for unconnected socket'.... very helpful.. one of them is the size of the box I found out.

The mouse over message is a general issue for all nodes not just this patch,
The functions need some love in an attempt to normalise them so that switching between them is intuitive.
There are other SDF functions that I have not included for this reason. I intend to work on this some more. Feedback is crucial.

  • Scale, no idea what this does, sometimes it works, sometimes it doesn't.

Scale is just scaling the input vector in common with all texture nodes.

  • float socket size Size, no idea, perhaps this meant to be hidden for box 2d?

This changes the size of the shape. It's added so that I can normalise the functions.

  • Rounding, grows the size of the shape, while it makes sense with the math behind it, artist wise you now have to twiddle with the size of the box to correct for that which is not great.
  • Thickness, this should probably be extracted into its own sdf annular node, i'll probably want to use this later on once i combined a few shapes, on top of that having control of the location (inside the shape, on the edge, outside the shape) would be nice.
  • Lack of union node, sure i can with this with the math node for a simple union since i know the math, artists won't and even when you do know the math the smooth variants (which are the ones you really want) are quite a pain to implement in a node group.

Smoothmin is already added to the Maths node in a previous patch. For this node I decided to add the Rounding and Thickness variables as they act on a single SDF function, For Union etc, either document this clearly or possibly add another SDF companion node is an option.

  • 2d sdf shapes work best in the -1 .. 1 range, most people will probably stick UV coords into this which will lead to 1/4 of the shape just sitting in a cornet which will confuse people

By their nature, these functions work with a 0,0 origin. For 2D functions a UV option could be added to center around 0.5, 0.5.

Overall, I see great potential here but it needs some love

Adding the functions is the easy part!

I can also see the potential building-blocks for robust light blockers as well here, great job @Charlie Jolly (charlie) !