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
2 changed files with 10 additions and 14 deletions
Showing only changes of commit 3ea023ba4a - Show all commits

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"] * val(float(180.0f / M_PI)); NodeItem rotation = in["anisotropic_rotation"] * val(360.0f);
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"];
@ -501,7 +501,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"] * val(float(180.0f / M_PI)); NodeItem rotation = in["anisotropic_rotation"];
res = create_node("standard_surface", res = create_node("standard_surface",
NodeItem::Type::SurfaceShader, NodeItem::Type::SurfaceShader,

View File

@ -215,39 +215,35 @@ static void node_shader_update_vector_rotate(bNodeTree *ntree, bNode *node)
NODE_SHADER_MATERIALX_BEGIN NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX #ifdef WITH_MATERIALX
{ {
/* Axes */
const NodeItem X = val(MaterialX::Vector3(1.0f, 0.0f, 0.0f));
const NodeItem Y = val(MaterialX::Vector3(0.0f, 1.0f, 0.0f));
const NodeItem Z = val(MaterialX::Vector3(0.0f, 0.0f, -1.0f));
int mode = node_->custom1; int mode = node_->custom1;
bool invert = node_->custom2; bool invert = node_->custom2;
NodeItem vector = get_input_value("Vector", NodeItem::Type::Vector3); NodeItem vector = get_input_value("Vector", NodeItem::Type::Vector3);
NodeItem center = get_input_value("Center", NodeItem::Type::Vector3) * (X + Y + Z); NodeItem center = get_input_value("Center", NodeItem::Type::Vector3);
BogdanNagirniak marked this conversation as resolved Outdated

To perform the same result as Blender it requires invert Z.
NodeItem center = get_input_value("Center", NodeItem::Type::Vector3) * val(MaterialX::Vector3(1.0f, 1.0f, -1.0f))

To perform the same result as Blender it requires invert Z. `NodeItem center = get_input_value("Center", NodeItem::Type::Vector3) * val(MaterialX::Vector3(1.0f, 1.0f, -1.0f))`
vector = vector - center; vector = vector - center;
if (mode == NODE_VECTOR_ROTATE_TYPE_EULER_XYZ) { if (mode == NODE_VECTOR_ROTATE_TYPE_EULER_XYZ) {
NodeItem rotation = get_input_value("Rotation", NodeItem::Type::Vector3) * NodeItem rotation = get_input_value("Rotation", NodeItem::Type::Vector3) *
val(float(180.0f / M_PI)) * (X + Y + Z); val(MaterialX::Vector3(1.0f, 1.0f, -1.0f) * 180.0f / M_PI);
return vector.rotate(invert ? -rotation : rotation, invert) + center; return vector.rotate(invert ? -rotation : rotation, invert) + center;
} }
NodeItem angle = get_input_value("Angle", NodeItem::Type::Float) * val(float(180.0f / M_PI)); NodeItem angle = get_input_value("Angle", NodeItem::Type::Float) * val(float(180.0f / M_PI));
NodeItem axis = empty(); NodeItem axis = empty();
switch (mode) { switch (mode) {
case NODE_VECTOR_ROTATE_TYPE_AXIS: case NODE_VECTOR_ROTATE_TYPE_AXIS:
axis = get_input_value("Axis", NodeItem::Type::Vector3) * (X + Y + Z); axis = get_input_value("Axis", NodeItem::Type::Vector3) *
val(MaterialX::Vector3(1.0f, 1.0f, -1.0f));
break; break;
case NODE_VECTOR_ROTATE_TYPE_AXIS_X: case NODE_VECTOR_ROTATE_TYPE_AXIS_X:
axis = X; axis = val(MaterialX::Vector3(1.0f, 0.0f, 0.0f));
break; break;
case NODE_VECTOR_ROTATE_TYPE_AXIS_Y: case NODE_VECTOR_ROTATE_TYPE_AXIS_Y:
axis = Y; axis = val(MaterialX::Vector3(0.0f, 1.0f, 0.0f));
break; break;
case NODE_VECTOR_ROTATE_TYPE_AXIS_Z: case NODE_VECTOR_ROTATE_TYPE_AXIS_Z:
axis = Z; axis = val(MaterialX::Vector3(0.0f, 0.0f, -1.0f));
break; break;
default: default:
BLI_assert_unreachable(); BLI_assert_unreachable();