I have worked on plenty of Math operations within Cycles without the need to use GLSL. The only operation/function so far that I Can't figure out however, is Sign.

Basically, this operation will take in a value x, and return:
if (x < 0): x = -1
if (x > 0): x = 1
if (x = 0): x = 0

I want to do this using existing cycles Nodes from 2.8 without having to download extensions/add-ons. Any help would be Greatly Appreciated!

This is the closest I can come up with, but I need the math worked out.
enter image description here
I'm a little unsure how Blender handles a Vec3 to a Scalar. The idea behind this is that the top to values of the Greater/Less Than's are inputs, Using the 2 Middle Mixes as booleans, the final Mix will hold the values needed.
Please correct me if I am wrong or if there is a better way.

  • 2
    $\begingroup$ Maximum and Minimum operations may help $\endgroup$ Commented Nov 30, 2019 at 3:49
  • $\begingroup$ @DuarteFarrajotaRamos can this also be done using the Sine node with Modulo? $\endgroup$
    – Luciano
    Commented Dec 6, 2019 at 13:08

1 Answer 1


Your node tree almost worked, it just required a different approach at the end. Let me show you a working example here:

working tree

for clarity's sake I have added value nodes to give the inputs a caption. There is the Test Value, which is basically the number you input, and a Tolerance, which circumvents the problem that there is no real a == b node. So if the value you feed is inbetween +Tolerance and -Tolerance, the node tree outputs 0.

Besides that, the only change is the Multiply and Add node at the end of the tree. Why that? Let's walk through a few sample values:

TestValue = 5.333
GreatherThan will be +1
LessThan will be 0
-> Multiply will be 0 too
-> Add will do 1 + 0 = 1, which is what you want

Let's change TestValue to something negative:

TestValue = -2
GreatherThan will be 0
LessThan will be +1
-> Multiply will be -1, as 1 * -1 = -1
-> Add will do 0 + -1 = -1, which is what you want

And finally, something lower than Tolerance:

TestValue = 0.000001
GreatherThan will be 0
LessThan will be 0
-> Multiply will be 0 too
-> Add will do 0 + 0 = 0, which is what you want

To make this a bit more visible, I have added this node setup at the end of the tree:


The Add and `Multiply basically bring the -1 to +1 range to a 0 to 1 range. The Color Ramp has three slots, if the input value is 0, the output is red, if input is 0.5, output is green, and if input is 1, output is blue. See it in action here:

in action

Here is the file for testing:

  • $\begingroup$ Just saw that there will be new modes for the math node coming to blender, sign being one of them. See developer.blender.org/D5957 for reference, this has been committed today $\endgroup$
    – aliasguru
    Commented Dec 7, 2019 at 12:44
  • $\begingroup$ That is some good news! Also, Thanks so much for helping out with the math! I just tested it on some SDF's and it works beautifully! $\endgroup$
    – Podis
    Commented Dec 7, 2019 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .