MaterialX: Implement White Noise node #113495

Merged
Brecht Van Lommel merged 7 commits from DagerD/blender:matx-add-white-noise-node into main 2023-10-23 17:31:51 +02:00
1 changed files with 19 additions and 14 deletions
Showing only changes of commit c1ddea10ad - Show all commits

View File

@ -188,38 +188,42 @@ static void sh_node_noise_build_multi_function(NodeMultiFunctionBuilder &builder
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
/* MaterialX cellnoise node rounds float value of texture coordinate.
* Therefore it changes at different integer coordinates.
* The simple trick would be to multiply the texture coordinate by a large number. */
const float LARGE_NUMBER = 10000.0f;
DagerD marked this conversation as resolved Outdated

Add variable which name this node option: int <option name> = node_->custom1.
See example https://projects.blender.org/blender/blender/src/branch/main/source/blender/nodes/shader/nodes/node_shader_math.cc#L186

Add variable which name this node option: `int <option name> = node_->custom1`. See example https://projects.blender.org/blender/blender/src/branch/main/source/blender/nodes/shader/nodes/node_shader_math.cc#L186
DagerD marked this conversation as resolved Outdated

Are there existing constants?

Are there existing constants?
NodeItem noise = empty();
NodeItem vector = empty();
DagerD marked this conversation as resolved Outdated

Optimize getting values, only w is used here

Optimize getting values, only w is used here
NodeItem w = empty();
int dimension = node_->custom1;
switch (dimension) {
case 1:
w = get_input_value("W", NodeItem::Type::Vector2);
noise = create_node("cellnoise2d",
NodeItem::Type::Float,
{{"texcoord", w}});
noise = create_node(
"cellnoise2d", NodeItem::Type::Float, {{"texcoord", w * val(LARGE_NUMBER)}});
break;
case 2:
vector = get_input_link("Vector", NodeItem::Type::Vector2);
noise = create_node("cellnoise2d",
NodeItem::Type::Float, {{"texcoord", vector}});
noise = create_node(
"cellnoise2d", NodeItem::Type::Float, {{"texcoord", vector * val(LARGE_NUMBER)}});
break;
case 3:
vector = get_input_link("Vector", NodeItem::Type::Vector3);
noise = create_node("cellnoise3d",
NodeItem::Type::Float, {{"position", vector}});
noise = create_node(
"cellnoise3d", NodeItem::Type::Float, {{"position", vector * val(LARGE_NUMBER)}});
break;
case 4:
vector = get_input_link("Vector", NodeItem::Type::Vector3);
w = get_input_value("W", NodeItem::Type::Float);
noise = create_node("cellnoise3d",
NodeItem::Type::Float,
{{"position", vector + w}});
w = get_input_value("W", NodeItem::Type::Float);
noise = create_node(
"cellnoise3d", NodeItem::Type::Float, {{"position", (vector + w) * val(LARGE_NUMBER)}});
DagerD marked this conversation as resolved Outdated

Add comment what we are doing here

Add comment what we are doing here
break;
default:
BLI_assert_unreachable();
break;
}
}
if (STREQ(socket_out_->name, "Value")) {
return noise;
@ -227,8 +231,9 @@ NODE_SHADER_MATERIALX_BEGIN
/* NOTE: cellnoise node doesn't have colored output, so we create hsvtorgb node and put
* noise in first (Hue) channel to generate color. */
NodeItem combine = create_node(
"combine3", NodeItem::Type::Color3, {{"in1", noise}, {"in2", val(1.0f)}, {"in3", val(0.5f)}});
NodeItem combine = create_node("combine3",
NodeItem::Type::Color3,
{{"in1", noise}, {"in2", val(1.0f)}, {"in3", val(0.5f)}});
return create_node("hsvtorgb", NodeItem::Type::Color3, {{"in", combine}});
}
#endif