forked from blender/blender
MaterialX: Implement more shader nodes #23
@ -13,6 +13,9 @@ NodeItem::NodeItem(MaterialX::GraphElement *graph) : graph_(graph) {}
|
|||||||
|
|
||||||
NodeItem::Type NodeItem::type(const std::string &type_str)
|
NodeItem::Type NodeItem::type(const std::string &type_str)
|
||||||
{
|
{
|
||||||
|
if (type_str == "multioutput") {
|
||||||
|
return Type::Multioutput;
|
||||||
|
}
|
||||||
if (type_str == "string") {
|
if (type_str == "string") {
|
||||||
return Type::String;
|
return Type::String;
|
||||||
}
|
}
|
||||||
@ -64,6 +67,8 @@ std::string NodeItem::type(Type type)
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::Any:
|
case Type::Any:
|
||||||
return "";
|
return "";
|
||||||
|
case Type::Multioutput:
|
||||||
|
return "multioutput";
|
||||||
case Type::String:
|
case Type::String:
|
||||||
return "string";
|
return "string";
|
||||||
case Type::Filename:
|
case Type::Filename:
|
||||||
|
@ -16,7 +16,7 @@ class NodeItem {
|
|||||||
enum class Type {
|
enum class Type {
|
||||||
Any = 0,
|
Any = 0,
|
||||||
Empty,
|
Empty,
|
||||||
|
Multioutput,
|
||||||
/* Value types */
|
/* Value types */
|
||||||
String,
|
String,
|
||||||
Filename,
|
Filename,
|
||||||
|
@ -42,6 +42,51 @@ static int node_shader_gpu_bsdf_glass(GPUMaterial *mat,
|
|||||||
return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_constant(&use_multi_scatter));
|
return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_constant(&use_multi_scatter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NODE_SHADER_MATERIALX_BEGIN
|
||||||
|
#ifdef WITH_MATERIALX
|
||||||
|
{
|
||||||
|
if (to_type_ != NodeItem::Type::BSDF) {
|
||||||
|
return empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||||
|
NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
|
||||||
|
NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
|
||||||
|
NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
|
||||||
|
|
||||||
|
NodeItem dielectric = create_node("dielectric_bsdf", NodeItem::Type::BSDF);
|
||||||
|
if (normal) {
|
||||||
|
dielectric.set_input("normal", normal);
|
||||||
|
}
|
||||||
|
dielectric.set_input("tint", color);
|
||||||
|
dielectric.set_input("roughness", roughness);
|
||||||
|
dielectric.set_input("ior", ior);
|
||||||
|
dielectric.set_input("scatter_mode", val(std::string("RT")));
|
||||||
|
|
||||||
|
NodeItem artistic_ior = create_node("artistic_ior", NodeItem::Type::Multioutput);
|
||||||
|
artistic_ior.add_output("ior", NodeItem::Type::Color3);
|
||||||
|
artistic_ior.add_output("extinction", NodeItem::Type::Color3);
|
||||||
|
artistic_ior.set_input("reflectivity", color);
|
||||||
|
artistic_ior.set_input("edge_color", color);
|
||||||
|
|
||||||
|
NodeItem conductor = create_node("conductor_bsdf", NodeItem::Type::BSDF);
|
||||||
|
if (normal) {
|
||||||
|
conductor.set_input("normal", normal);
|
||||||
|
}
|
||||||
|
conductor.set_input_output("ior", artistic_ior, "ior");
|
||||||
|
conductor.set_input_output("extinction", artistic_ior, "extinction");
|
||||||
|
conductor.set_input("roughness", roughness);
|
||||||
|
|
||||||
|
NodeItem res = create_node("mix", NodeItem::Type::BSDF);
|
||||||
|
|||||||
|
res.set_input("fg", dielectric);
|
||||||
|
res.set_input("bg", conductor);
|
||||||
|
res.set_input("mix", val(0.5f));
|
||||||
|
|
||||||
|
return res ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
NODE_SHADER_MATERIALX_END
|
||||||
|
|
||||||
} // namespace blender::nodes::node_shader_bsdf_glass_cc
|
} // namespace blender::nodes::node_shader_bsdf_glass_cc
|
||||||
|
|
||||||
/* node type definition */
|
/* node type definition */
|
||||||
@ -57,6 +102,7 @@ void register_node_type_sh_bsdf_glass()
|
|||||||
blender::bke::node_type_size_preset(&ntype, blender::bke::eNodeSizePreset::MIDDLE);
|
blender::bke::node_type_size_preset(&ntype, blender::bke::eNodeSizePreset::MIDDLE);
|
||||||
ntype.initfunc = file_ns::node_shader_init_glass;
|
ntype.initfunc = file_ns::node_shader_init_glass;
|
||||||
ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glass;
|
ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glass;
|
||||||
|
ntype.materialx_fn = file_ns::node_shader_materialx;
|
||||||
|
|
||||||
nodeRegisterType(&ntype);
|
nodeRegisterType(&ntype);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,41 @@ static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat,
|
|||||||
return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out, GPU_constant(&use_multi_scatter));
|
return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out, GPU_constant(&use_multi_scatter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NODE_SHADER_MATERIALX_BEGIN
|
||||||
|
#ifdef WITH_MATERIALX
|
||||||
|
{
|
||||||
|
if (to_type_ != NodeItem::Type::BSDF) {
|
||||||
|
return empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||||
|
NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
|
||||||
|
NodeItem anisotropy = get_input_value("Anisotropy", NodeItem::Type::Color3);
|
||||||
|
NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
|
||||||
|
NodeItem tangent = get_input_link("Tangent", NodeItem::Type::Vector3);
|
||||||
|
|
||||||
|
NodeItem artistic_ior = create_node("artistic_ior", NodeItem::Type::Multioutput);
|
||||||
|
artistic_ior.add_output("ior", NodeItem::Type::Color3);
|
||||||
|
artistic_ior.add_output("extinction", NodeItem::Type::Color3);
|
||||||
|
artistic_ior.set_input("reflectivity", color);
|
||||||
|
artistic_ior.set_input("edge_color", color);
|
||||||
|
|
||||||
|
NodeItem res = create_node("conductor_bsdf", NodeItem::Type::BSDF);
|
||||||
|
if (normal) {
|
||||||
|
res.set_input("normal", normal);
|
||||||
|
}
|
||||||
|
if (tangent) {
|
||||||
|
res.set_input("tangent", tangent);
|
||||||
|
}
|
||||||
|
res.set_input_output("ior", artistic_ior, "ior");
|
||||||
|
res.set_input_output("extinction", artistic_ior, "extinction");
|
||||||
|
res.set_input("roughness", roughness);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
NODE_SHADER_MATERIALX_END
|
||||||
|
|
||||||
} // namespace blender::nodes::node_shader_bsdf_glossy_cc
|
} // namespace blender::nodes::node_shader_bsdf_glossy_cc
|
||||||
|
|
||||||
/* node type definition */
|
/* node type definition */
|
||||||
@ -72,6 +107,7 @@ void register_node_type_sh_bsdf_glossy()
|
|||||||
blender::bke::node_type_size_preset(&ntype, blender::bke::eNodeSizePreset::MIDDLE);
|
blender::bke::node_type_size_preset(&ntype, blender::bke::eNodeSizePreset::MIDDLE);
|
||||||
ntype.initfunc = file_ns::node_shader_init_glossy;
|
ntype.initfunc = file_ns::node_shader_init_glossy;
|
||||||
ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glossy;
|
ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glossy;
|
||||||
|
ntype.materialx_fn = file_ns::node_shader_materialx;
|
||||||
|
|
||||||
nodeRegisterType(&ntype);
|
nodeRegisterType(&ntype);
|
||||||
|
|
||||||
|
@ -40,6 +40,32 @@ static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat,
|
|||||||
return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out);
|
return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NODE_SHADER_MATERIALX_BEGIN
|
||||||
|
#ifdef WITH_MATERIALX
|
||||||
|
{
|
||||||
|
if (to_type_ != NodeItem::Type::BSDF) {
|
||||||
|
return empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||||
|
NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
|
||||||
|
NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
|
||||||
|
NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
|
||||||
|
|
||||||
|
NodeItem res = create_node("dielectric_bsdf", NodeItem::Type::BSDF);
|
||||||
|
if (normal) {
|
||||||
|
res.set_input("normal", normal);
|
||||||
|
}
|
||||||
|
res.set_input("tint", color);
|
||||||
|
res.set_input("roughness", roughness);
|
||||||
|
res.set_input("ior", ior);
|
||||||
|
res.set_input("scatter_mode", val(std::string("T")));
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
NODE_SHADER_MATERIALX_END
|
||||||
|
|
||||||
} // namespace blender::nodes::node_shader_bsdf_refraction_cc
|
} // namespace blender::nodes::node_shader_bsdf_refraction_cc
|
||||||
|
|
||||||
/* node type definition */
|
/* node type definition */
|
||||||
@ -55,6 +81,7 @@ void register_node_type_sh_bsdf_refraction()
|
|||||||
blender::bke::node_type_size_preset(&ntype, blender::bke::eNodeSizePreset::MIDDLE);
|
blender::bke::node_type_size_preset(&ntype, blender::bke::eNodeSizePreset::MIDDLE);
|
||||||
ntype.initfunc = file_ns::node_shader_init_refraction;
|
ntype.initfunc = file_ns::node_shader_init_refraction;
|
||||||
ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_refraction;
|
ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_refraction;
|
||||||
|
ntype.materialx_fn = file_ns::node_shader_materialx;
|
||||||
|
|
||||||
nodeRegisterType(&ntype);
|
nodeRegisterType(&ntype);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user
Dielectric already has Reflection and Transmission channels (dielectric -> scatter_mode = "RT"). Do we need one more mix with the Reflection channel (conductor)?