blender/intern/cycles/kernel/osl/shaders/node_boolean_math.osl
Jacques Lucke 6c74e82ecb Shader Nodes: support Boolean Math node in EEVEE and Cycles
This adds the Boolean Math node to shader nodes. It's the same node that
can already be used in Geometry Nodes and the Compositor.

This also fixes the conversion from other types to boolean values so that
it it consistent across different node tree types. Cycles doesn't have
native support for booleans currently (it encodes them in integers), so
for now this conversion is entirely handled in the inliner.

The MaterialX implementation is omitted for now because it seems to need
more work to properly integrate booleans (right now it appears to ignore
all links going from a float to a boolean socket for example).

Pull Request: https://projects.blender.org/blender/blender/pulls/162798
2026-09-12 14:43:16 +02:00

35 lines
863 B
Text

/* SPDX-FileCopyrightText: 2026 Blender Authors
*
* SPDX-License-Identifier: Apache-2.0 */
#include "stdcycles.h"
shader node_boolean_math(string math_type = "and",
int Boolean1 = 0,
int Boolean2 = 0,
output int Boolean = 0)
{
int a = Boolean1 > 0;
int b = Boolean2 > 0;
if (math_type == "and")
Boolean = a && b;
else if (math_type == "or")
Boolean = a || b;
else if (math_type == "not")
Boolean = !a;
else if (math_type == "nand")
Boolean = !(a && b);
else if (math_type == "nor")
Boolean = !(a || b);
else if (math_type == "xnor")
Boolean = a == b;
else if (math_type == "xor")
Boolean = a != b;
else if (math_type == "imply")
Boolean = !a || b;
else if (math_type == "nimply")
Boolean = a && !b;
else
Boolean = 0;
}