Is there a condition node (if/else statement) for Cycles?
What I have so far:
There is an existing OSL node for it but OSL works only on CPU.
There are a comprehensive reply on this thread, but correct me if I’m wrong there is no If/Else Statement solution
There is a commercial product here which might be what I’m looking for but it requires a monthly subscription fee. I don’t mind paying but I prefer not to have monthly fees.
MixRGB set to ‘Mix’. If ‘fac’=0, output color1; if ‘fac’=1, output color2.
The same is possible for floats, using Math nodes: output = val1 * fac + val0 * (1-fac).
And shaders go with MixShaders.
I now use map range to do floating point linear interpolation (fLerp). I think it’s odd that we don’t have a simple Lerp function in the math node, with nothing of the fancy stuff map range offers.
You are right. They are. Thanks for pointing them out.
They work as expected but do you know how to use a hard “compare”
If X = 5, output 1. Or something.
Currently, it only has Greater than or Less Than.
So I can only perform either If X > 5 or if X <5.
BIS library is absolutelly free. All materiasl are available for everyone. If you don’t want to support the project, you need to pay nothing. It’s free.
In Blender, you can insert certain python expressions directly in Float property boxes, but they must result in a (constant) numerical value.
Blender parses the input expression and turns the result into a value on the fly.
The expression, however, will be gone as soon you press enter, as the property type (float, integer, etc) is the only thing that remains.
You can, for example, type sqrt(2)+4*pi or even 3.0 if 2 >= 4 else 5.0 (python for “if (2>=4){output=3.0;} else {output=5.0;}”) and it’s ok because those evaluates to a number (respectively 13.981 and 5.0)… But you cannot type something that uses a variable (only known constants are allowed).
When I wrote output = val1 * fac + val0 * (1-fac) this is what I meant:
It’s possible to use expressions with variables that are updated on scene changes, but you need to use ‘Drivers’ for that.
What is the best solution depends in what you’re looking for, exactly…
What are your conditions? what are your variables? what is the desired output?
Edited: BTW, what RickyBlender refers to ‘Compare’, it’s a new operation in the Math Node, that is only available in latest builds of Blender (prior to 07/12/2019).