Hello, sometimes you might feel that your materials should be more clever, to have them “make decisions” based on various circumstances and redirect flow in according to your needs.
You might have tried already that with some Math nodes, but the procedure is always “hackish” and complex. On the other hand using a simple Boolean Node is much easier and makes sense instantly. For months I was wondering why Blender is missing this feature, until today I got into it and to my amazement it was was much easier than expected.
I read about the OSL specification:
https://github.com/imageworks/OpenShadingLanguage/blob/master/src/doc/osl-languagespec.pdf
I visited the wiki:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL
Also I had a peek at some examples at the official repository:
For the time, I don’t have any other use cases or ideas about it except for what exactly it does. Hopefully you might find this thing interesting, to create your stuff and modify even further. Also I would be interested to see this script or something similar in the trunk, just as an extension to the Math node, if any developer plays with the source could act accordingly.
Thanks for the interest, have a good time.
shader boolean_node
(
float ValueA = 0,
float ValueB = 0,
string Operator = "",
float TrueValue = 1,
float FalseValue = 0,
output float Result = 0
)
{
if (Operator == "!=") Result = (ValueA != ValueB) ? FalseValue : TrueValue;
if (Operator == "||") Result = (ValueA != ValueB) ? TrueValue : FalseValue;
if (Operator == "==") Result = (ValueA == ValueB) ? TrueValue : FalseValue;
if (Operator == ">") Result = (ValueA > ValueB) ? TrueValue : FalseValue;
if (Operator == "<") Result = (ValueA < ValueB) ? TrueValue : FalseValue;
}
Attachments
cycles boolean node.zip (920 KB)