Implement BSDF Transparent shader #36

Merged
Bogdan Nagirniak merged 5 commits from BogdanNagirniak/blender:matx-transparent-shader into matx-export-material 2023-09-26 16:16:26 +02:00
7 changed files with 24 additions and 40 deletions
Showing only changes of commit 511510c9bf - Show all commits

View File

@ -54,7 +54,7 @@ NodeItem::Type NodeItem::type(const std::string &type_str)
return Type::EDF; return Type::EDF;
} }
if (type_str == "displacementshader") { if (type_str == "displacementshader") {
return Type::Displacementshader; return Type::DisplacementShader;
} }
if (type_str == "surfaceshader") { if (type_str == "surfaceshader") {
return Type::SurfaceShader; return Type::SurfaceShader;
@ -97,7 +97,7 @@ std::string NodeItem::type(Type type)
return "BSDF"; return "BSDF";
case Type::EDF: case Type::EDF:
return "EDF"; return "EDF";
case Type::Displacementshader: case Type::DisplacementShader:
return "displacementshader"; return "displacementshader";
case Type::SurfaceShader: case Type::SurfaceShader:
return "surfaceshader"; return "surfaceshader";
@ -388,14 +388,15 @@ NodeItem NodeItem::rotate(const NodeItem &angle_xyz, bool invert)
NodeItem x = angle_xyz[0]; NodeItem x = angle_xyz[0];
NodeItem y = angle_xyz[1]; NodeItem y = angle_xyz[1];
NodeItem z = angle_xyz[2]; NodeItem z = angle_xyz[2];
NodeItem x_axis = val(MaterialX::Vector3(1.0f, 0.0f, 0.0f));
NodeItem y_axis = val(MaterialX::Vector3(0.0f, 1.0f, 0.0f));
NodeItem z_axis = val(MaterialX::Vector3(0.0f, 0.0f, 1.0f));
if (invert) { if (invert) {
return rotate(z, val(MaterialX::Vector3(0.0f, 0.0f, 1.0f))) return rotate(z, z_axis).rotate(y, y_axis).rotate(x, x_axis);
.rotate(y, val(MaterialX::Vector3(0.0f, 1.0f, 0.0f)))
.rotate(x, val(MaterialX::Vector3(1.0f, 0.0f, 0.0f)));
} }
return rotate(x, val(MaterialX::Vector3(1.0f, 0.0f, 0.0f))) return rotate(x, x_axis).rotate(y, y_axis).rotate(z, z_axis);
.rotate(y, val(MaterialX::Vector3(0.0f, 1.0f, 0.0f)))
.rotate(z, val(MaterialX::Vector3(0.0f, 0.0f, 1.0f)));
} }
NodeItem NodeItem::sin() const NodeItem NodeItem::sin() const

View File

@ -41,7 +41,7 @@ class NodeItem {
/* Shader types. NOTE: There are only supported types */ /* Shader types. NOTE: There are only supported types */
BSDF, BSDF,
EDF, EDF,
Displacementshader, DisplacementShader,
SurfaceShader, SurfaceShader,
Material, Material,

View File

@ -54,29 +54,13 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem ior = get_input_value("IOR", NodeItem::Type::Float); NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3); NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
NodeItem dielectric = create_node("dielectric_bsdf", return create_node("dielectric_bsdf",
NodeItem::Type::BSDF, NodeItem::Type::BSDF,
{{"normal", normal}, {{"normal", normal},
{"tint", color}, {"tint", color},
{"roughness", roughness}, {"roughness", roughness},
{"ior", ior}, {"ior", ior},
{"scatter_mode", val(std::string("RT"))}}); {"scatter_mode", val(std::string("RT"))}});
NodeItem artistic_ior = create_node("artistic_ior",
NodeItem::Type::Multioutput,
{{"reflectivity", color}, {"edge_color", color}});
NodeItem ior_out = artistic_ior.add_output("ior", NodeItem::Type::Color3);
NodeItem extinction_out = artistic_ior.add_output("extinction", NodeItem::Type::Color3);
NodeItem conductor = create_node("conductor_bsdf",
NodeItem::Type::BSDF,
{{"normal", normal},
{"ior", ior_out},
{"extinction", extinction_out},
{"roughness", roughness}});
return create_node(
"mix", NodeItem::Type::BSDF, {{"fg", dielectric}, {"bg", conductor}, {"mix", val(0.5f)}});
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -58,10 +58,9 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Float); NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Float);
NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3); NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
return create_node( return create_node("sheen_bsdf",
"sheen_bsdf",
NodeItem::Type::BSDF, NodeItem::Type::BSDF,
{{"color", color}, {"weight", roughness}, {"roughness", roughness}, {"normal", normal}}); {{"color", color}, {"roughness", roughness}, {"normal", normal}});
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -46,7 +46,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float); NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
return create_node("displacement", return create_node("displacement",
NodeItem::Type::Displacementshader, NodeItem::Type::DisplacementShader,
{{"displacement", height}, {"scale", scale}}); {{"displacement", height}, {"scale", scale}});
} }
#endif #endif

View File

@ -89,8 +89,8 @@ static int node_shader_gpu_tangent(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
/* TODO: This node doesn't have an implementation in MaterialX.*/ /* TODO: implement other features */
return get_output_default(socket_out_->name, NodeItem::Type::Vector3); return create_node("tangent", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END

View File

@ -50,7 +50,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float); NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
return create_node("displacement", return create_node("displacement",
NodeItem::Type::Displacementshader, NodeItem::Type::DisplacementShader,
{{"displacement", vector}, {"scale", scale}}); {{"displacement", vector}, {"scale", scale}});
} }
#endif #endif