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 40 additions and 0 deletions
Showing only changes of commit 56f7e2d280 - Show all commits

View File

@ -185,6 +185,45 @@ static void sh_node_noise_build_multi_function(NodeMultiFunctionBuilder &builder
builder.construct_and_set_matching_fn<WhiteNoiseFunction>(int(node.custom1));
}
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
NodeItem noise = empty();
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector3);
NodeItem w = get_input_value("W", NodeItem::Type::Float);
switch (node_->custom1) {
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
case 1:
DagerD marked this conversation as resolved Outdated

Are there existing constants?

Are there existing constants?
noise = create_node("cellnoise2d",
NodeItem::Type::Float,
DagerD marked this conversation as resolved Outdated

Optimize getting values, only w is used here

Optimize getting values, only w is used here
{{"texcoord", w.convert(NodeItem::Type::Vector2)}});
break;
case 2:
noise = create_node("cellnoise2d",
NodeItem::Type::Float,
{{"texcoord", vector.convert(NodeItem::Type::Vector2)}});
break;
case 3:
noise = create_node("cellnoise3d", NodeItem::Type::Float, {{"position", vector}});
break;
case 4:
noise = create_node("cellnoise3d", NodeItem::Type::Float, {{"position", vector + w}});
break;
default:
BLI_assert_unreachable();
break;
}
if (STREQ(socket_out_->name, "Value")) {
return noise;
}
NodeItem combine = create_node(
"combine3", NodeItem::Type::Color3, {{"in1", noise}, {"in2", val(1.0f)}, {"in3", val(0.5f)}});
DagerD marked this conversation as resolved Outdated

Add comment what we are doing here

Add comment what we are doing here
return create_node("hsvtorgb", NodeItem::Type::Color3, {{"in", combine}});
}
#endif
NODE_SHADER_MATERIALX_END
} // namespace blender::nodes::node_shader_tex_white_noise_cc
void register_node_type_sh_tex_white_noise()
@ -200,6 +239,7 @@ void register_node_type_sh_tex_white_noise()
ntype.gpu_fn = file_ns::gpu_shader_tex_white_noise;
ntype.updatefunc = file_ns::node_shader_update_tex_white_noise;
ntype.build_multi_function = file_ns::sh_node_noise_build_multi_function;
ntype.materialx_fn = file_ns::node_shader_materialx;
nodeRegisterType(&ntype);
}