# How do I get 1 for a certain range of a value?

I want to drive a shader with a value node. If the value would be from 0.1 to 0.3, I want the output to be 1 and otherwise I want it to be 0.

I was thinking about using Greater Than and Less Than, but I can’t quite figure it out (I attach an idea I thought would work, but it doesn’t).

You can do it with a Color Ramp node. Set the interpolation to Constant, bring the black stop to the position 0.3, the white stop to 0.1 and add a black stop at 0.0.

• Very nice :). I noticed that Fac=0,1 still outputs 0. But when I set the white stop to 0,97 it works perfectly. Probably a rounding error in the ColorRamp... Jul 11 at 13:05
• @JachymMichal Hmm yes the Color ramp node is notorious for its rounding errors (and inefficiency) since it converts values to colors and then back to values afterwards... But that's a very high margin of error even for floating point precision errors... It's definitely possible to mimic the same setup with a combination of math nodes but it would take more space in the editor :) Jul 11 at 13:21

In your example, it works for the given input, that is a value 0.2 produces 1 output: value is both greater than 0.1 and lesser than 0.3, both condition nodes outputs sum up to 2 which is clamped into the 0...1 range, so becomes 1.

However let's see what happens if your value is below the 0.1...0.3 range: it passes only one condition, but since summing 0 and 1 results in 1, which is the same result as in previous case due to clamping in that previous case.

So Math > Add is an equivalent to Logical OR: if either of operands is True, the result is True. You need something different, Logical AND: if both of operands are True (both less than .3 and more than .1) the result is True, otherwise it's not True (False). In order to do that, replace your Math > Add with Math > Multiply - now if either of the comparison nodes will result with 0, the other result will be multiplied by 0, resulting, of course, with 0. So the only way to get 1 will be to have a value both lesser than .3 and greater than .1!

There's a simpler way, however, Math > Compare will result in 1 if you're not more than Epsilon away from Value (otherwise 0)

In general to output 1 if input is in range a...b, set the Math > Compare this way:

• Epsilon = (b-a)/2
• Value = a + Epsilon

so for range 0.1 ... 0.3:

• Epsilon = (0.3-0.1) / 2 = 0.2 / 2 = 0.1
• Value = 0.1 + 0.1 = 0.2

In simpler terms set the the Value to the middle of the range, and Epsilon to half of the range.

• in my opinion this should be the right answer...because it's easier to setup and hopefully more precise. Jul 11 at 13:50
• @Chris this is a tricky thing on SE, in the end the userbase decides what it likes more - with votes. :) Jul 11 at 14:17
• i know. I just wanted to express my thinking ;) Jul 11 at 14:19
• This is exactly the way I would do it. Jul 12 at 6:14
• Oh, right, completely forgot about that :) Jul 12 at 6:16