Code improvements + Mix node #30

Merged
Bogdan Nagirniak merged 18 commits from BogdanNagirniak/blender:matx-code-improvements into matx-export-material 2023-09-22 18:23:13 +02:00
5 changed files with 17 additions and 15 deletions
Showing only changes of commit 4ca83bc08f - Show all commits

View File

@ -379,18 +379,18 @@ NodeItem NodeItem::rotate(const NodeItem &angle, const NodeItem &axis)
BLI_assert(angle.type() == Type::Float); BLI_assert(angle.type() == Type::Float);
BLI_assert(axis.type() == Type::Vector3); BLI_assert(axis.type() == Type::Vector3);
return create_node( return create_node("rotate3d",
"rotate3d",
NodeItem::Type::Vector3, NodeItem::Type::Vector3,
{{"in", *this}, {"amount", angle * val(float(180.0f / M_PI))}, {"axis", axis}}); {{"in", *this},
{"amount", angle},
{"axis", axis}});
} }
NodeItem NodeItem::rotate(const NodeItem &angle_xyz, bool invert) NodeItem NodeItem::rotate(const NodeItem &angle_xyz, bool invert)
{ {
NodeItem angle = angle_xyz * val(float(180.0f / M_PI)); NodeItem x = angle_xyz[0];
NodeItem x = angle[0]; NodeItem y = angle_xyz[1];
NodeItem y = angle[1]; NodeItem z = angle_xyz[2];
NodeItem z = angle[2];
if (invert) { if (invert) {
return rotate(z, val(MaterialX::Vector3(0.0f, 0.0f, 1.0f))) return rotate(z, val(MaterialX::Vector3(0.0f, 0.0f, 1.0f)))
.rotate(y, val(MaterialX::Vector3(0.0f, 1.0f, 0.0f))) .rotate(y, val(MaterialX::Vector3(0.0f, 1.0f, 0.0f)))

View File

@ -92,8 +92,8 @@ class NodeItem {
NodeItem mix(const NodeItem &val1, const NodeItem &val2) const; NodeItem mix(const NodeItem &val1, const NodeItem &val2) const;
NodeItem clamp(const NodeItem &min_val, const NodeItem &max_val) const; NodeItem clamp(const NodeItem &min_val, const NodeItem &max_val) const;
NodeItem clamp(float min_val = 0.0f, float max_val = 1.0f) const; NodeItem clamp(float min_val = 0.0f, float max_val = 1.0f) const;
NodeItem rotate(const NodeItem &angle, const NodeItem &axis); NodeItem rotate(const NodeItem &angle, const NodeItem &axis); /* angle in degrees */
NodeItem rotate(const NodeItem &angle_xyz, bool invert = false); NodeItem rotate(const NodeItem &angle_xyz, bool invert = false); /* angle in degrees */
NodeItem sin() const; NodeItem sin() const;
NodeItem cos() const; NodeItem cos() const;
NodeItem tan() const; NodeItem tan() const;

View File

@ -337,7 +337,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem roughness = in["roughness"]; NodeItem roughness = in["roughness"];
NodeItem anisotropy = in["anisotropic"]; NodeItem anisotropy = in["anisotropic"];
NodeItem rotation = in["anisotropic_rotation"]; NodeItem rotation = in["anisotropic_rotation"] * val(float(180.0f / M_PI));;
NodeItem base_color = in["base_color"]; NodeItem base_color = in["base_color"];
NodeItem specular = in["specular"]; NodeItem specular = in["specular"];
NodeItem coat = in["coat"]; NodeItem coat = in["coat"];
@ -348,7 +348,8 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_main_tangent = empty(); NodeItem n_main_tangent = empty();
if (tangent && normal) { if (tangent && normal) {
NodeItem n_tangent_rotate_normalize = tangent.rotate(rotation, normal).normalize(); NodeItem n_tangent_rotate_normalize =
tangent.rotate(rotation, normal).normalize();
n_main_tangent = anisotropy.if_else( n_main_tangent = anisotropy.if_else(
NodeItem::CompareOp::Greater, val(0.0f), n_tangent_rotate_normalize, tangent); NodeItem::CompareOp::Greater, val(0.0f), n_tangent_rotate_normalize, tangent);
} }
@ -501,7 +502,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem roughness = in["roughness"]; NodeItem roughness = in["roughness"];
NodeItem base_color = in["base_color"]; NodeItem base_color = in["base_color"];
NodeItem anisotropic = in["anisotropic"]; NodeItem anisotropic = in["anisotropic"];
NodeItem rotation = in["anisotropic_rotation"]; NodeItem rotation = in["anisotropic_rotation"] * val(float(180.0f / M_PI));
res = create_node("standard_surface", res = create_node("standard_surface",
NodeItem::Type::SurfaceShader, NodeItem::Type::SurfaceShader,

View File

@ -85,7 +85,8 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem scale = get_input_value("Scale", NodeItem::Type::Vector3); NodeItem scale = get_input_value("Scale", NodeItem::Type::Vector3);
NodeItem location = get_input_value("Location", NodeItem::Type::Vector3); NodeItem location = get_input_value("Location", NodeItem::Type::Vector3);
NodeItem rotation = get_input_value("Rotation", NodeItem::Type::Vector3); NodeItem rotation = get_input_value("Rotation", NodeItem::Type::Vector3) *
val(float(180.0f / M_PI));
switch (node_->custom1) { switch (node_->custom1) {
case NODE_MAPPING_TYPE_POINT: case NODE_MAPPING_TYPE_POINT:

View File

@ -227,7 +227,7 @@ NODE_SHADER_MATERIALX_BEGIN
val(MaterialX::Vector3(1.0f, 1.0f, -1.0f)); val(MaterialX::Vector3(1.0f, 1.0f, -1.0f));
NodeItem res = vector - center; NodeItem res = vector - center;
int mode = node_->custom1; int mode = node_->custom1;
bool invert = node_->custom1; bool invert = node_->custom2;
if (mode == NODE_VECTOR_ROTATE_TYPE_EULER_XYZ) { if (mode == NODE_VECTOR_ROTATE_TYPE_EULER_XYZ) {
angle = get_input_value("Rotation", NodeItem::Type::Vector3); angle = get_input_value("Rotation", NodeItem::Type::Vector3);