# Blender 2.8 - Cycles - Math (Sign)

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!

Edit:
This is the closest I can come up with, but I need the math worked out. 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.

• Maximum and Minimum operations may help – Duarte Farrajota Ramos Nov 30 '19 at 3:49
• @DuarteFarrajotaRamos can this also be done using the Sine node with Modulo? – Luciano Dec 6 '19 at 13:08

Your node tree almost worked, it just required a different approach at the end. Let me show you a working example here: 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: Here is the file for testing: • 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 – aliasguru Dec 7 '19 at 12:44
• 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! – Podis Dec 7 '19 at 13:16