# How to select “in between values” with Math nodes

I like to take age values of particles between 20 and 40 and change color of an object in between these values. How can I do it? Thanks

• By the way, because you give no information on which render engine you want to use and nobody mentions it: the Particle Info node that gives you the particle age only works in Cycles, not in Eevee. – Gordon Brinkmann May 16 at 21:13

Presumably, you want their age-- their lifetime is their total lifetime, determined at birth, not the current time since emission.

To map color to some particular range of ages, first map your age range to a 0,1 range, then use a color ramp:

All particles younger than 20 frames are green. All particles older than 40 frames are red. Between, we gradate (by linear RGB, as set by the color ramp.)

If you want to change the color in a specific range, you want to use two compare functions because you want to know if the particle's age is greater than 20 and also less than 40. So you need two math nodes, one for each compare:

But how do you use those results? The compare node returns a 0 if the compare fails and a 1 if the compare succeeds. Since there is no math node for logic functions, you need a way of faking the and function. Turns out multiplying the two results gives you the correct values:

If either compare returns 0, multiplying it by the other gives 0. If both return 1, then the multiplication returns 1. We can feed this into a mixRGB node:

Since the mixRGB node gives the top color when its factor is 0 and the bottom color when its factor is 1, that tree will give the bluish color if the age is out of the range and the reddish color if the age is in the range.

• Great answer! Just one little note: since these nodes don't include the minimum and maximum values, if the output was intended to be red on 20 and 40 instead of just between those frames, you'd need to set the inputs to 19 and 41 (of course that won't matter most of the time). – HISEROD May 16 at 21:35
• English is ambiguous for this usage. "between 20 and 40" can mean either inclusive or exclusive of the end points. I took the inclusive path. In math, we use the parenthesis versus the square bracket to indicate whether a range is inclusive or exclusive, by convention, of course. – Marty Fouts May 16 at 21:48
• I just added the comment to add extra info. Sometimes newbs get frustrated when something doesn't work exactly as they expect it to, so I hoped adding the comment would help such a person out should they run into that problem. Didn't mean for it to sound like you did it wrong or something.😉 – HISEROD May 16 at 22:00
• Sorry if I came off rude. I only meant to expand on your comment, which I agree with. I also forgot to thank you for the compliment. Your extra info was useful. – Marty Fouts May 16 at 22:11

First off, this solution only works in Cycles not in Eevee because the Particle Info node which is needed for the particle age doesn't work in Eevee.

Sorry for repeating parts of your answers, but since the question is open for different approaches or what exactly the outcome should look like, I thought I'd sum up and combine everything so that one can pick what suits them best. This is just an addition if you also want to indicate with another color if the particles are out of the 20 to 40 age range.

In this case, a Compare node comes in handy. To test if the age is between 20 and 40, you take the average (20+40)/2 = 30 and half the distance (40-20)/2 = 10. Plug the age in the first Value input of the Compare node, enter 30 as the second Value and 10 for Epsilon. Now this node compares if the age is 30 +/- 10 (i.e. 20 to 40). The result will be 1 if it is in this range, otherwise 0. This you can use as factor for a Mix RGB node. The first color shows when the age is out of range, in the second color you plug the Color Ramp.

The result looks like this: Particles will change from blue at age 20 to green at age 40. If they are younger or older, they are black.

But also Marty's answer with the Greater Than and Less Than can be of use, if you also want to indicate by different colors if the particles are under age 20 or over age 40. In this case you check for an age less than 20 as factor in a Mix RGB node and mix in the Color Ramp as first color for 0 (no, the age is not less than 20) and some color for 1 (red in my example).

This result goes into the first input of another Mix RGB where the factor is determined by a Greater Than node checking if the age is greater than 40. On 0 (age not greater 40), the result of the first mix node will pass through, on 1 (age greater 40) the second color (in my example black) will indicate older particles.

It looks like this, on the left there are red particles which shows they are under age 20, then comes the color range from blue to green. The particles on the right side are black which shows they are over age 40.