|Home||Tutorial Links||My Tutorials||Sample Materials||Freebies|
The Sign function does exactly what you would expect - it tells you if a number is negative or positive (zero goes with positive).
The function looks at Value_1, and returns 1 if it is zero or higher, or -1 if it is less than zero.
Here we will look at how the Sign function can be used with the N variable to test for direction. The N node returns the surface normal (imagine it as an arrow pointing straight up from the surface of the model) as a vector - three numbers, one for X (left to right), one for Y (top to bottom) and one for Z (back to front), with each number ranging smoothly from -1 to +1.
On Figure 1 we are testing for parts of the torus that are facing towards the right of the scene. For X, right is positive, so we need to test for the X direction only (For Y, up is positive and for Z towards the front of the scene is positive). If you plug the N node directly into a normal maths node, the three values are averaged out. This means that +1 will be in the front, top, right position and -1 in the back, bottom, left.
Remember, what shows as black here is actually -1. If you plan to use the output from the Sign function to control a Blender node, that doesn't matter, as the Blender node clamps its controls, treating all negative numbers as zero, but if you are going to use this function as part of a larger calculation you will need to take that into account.
Figure 2 shows our shader tree. First, we need to strip out Y and Z from the N node, by setting them to zero. The output of the N node will now only contain the X value, running from -.333 to +.333 when it is plugged into a maths node. Next, we plug the output of our N node into the Sign function. As far as Sign is concerned, +1 and +.0001 produce the same result: 1. On the main preview we see the results.
Figure three shows the opposite test. This time, any part of the torus that faces left will show as +1, and anything pointing right as -1. Figure 4 shows how we have achieved that result.
To invert the result of the Sign node, so that positive numbers produce -1, and negative or zero produce 1 we need to change Value_1 of the Sign function to any negative number. This will multiply our input by that negative number, swapping the sign (negative * negative = positive and negative * positive = negative, zero remains zero).
Figure 4 shows this. Here our input is multiplied by -0.1 by Value_1 and then the sign is tested. It doesn't matter how big or small you make your multiplier - the result of the sign function is always either -1 or +1.
You can further refine this test with some simple maths. If you want less of the torus to test positive, put a subtract function between the N node and the Sign function. Subtract a number between 0 and .333 to reduce the area that tests positive - the higher your number, the less will test positive. To increase the area that tests positive, use a add function instead.
Figure 5 takes this one step further. Here I have subtracted 0.3 from the test, to decrease the area that tests positive. I have also plugged a cloud node into Value_2 of the Subtract function, to give us the wavy edge to the results. Figure 6 shows the settings I have used for this particular render.