forked from blender/blender
Code improvements + Mix node #30
@ -379,11 +379,8 @@ 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("rotate3d",
|
return create_node(
|
||||||
NodeItem::Type::Vector3,
|
"rotate3d", NodeItem::Type::Vector3, {{"in", *this}, {"amount", angle}, {"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)
|
||||||
|
@ -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(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,8 +348,7 @@ 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 =
|
NodeItem n_tangent_rotate_normalize = tangent.rotate(rotation, normal).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);
|
||||||
}
|
}
|
||||||
|
@ -77,34 +77,31 @@ static void node_shader_update_mapping(bNodeTree *ntree, bNode *node)
|
|||||||
NODE_SHADER_MATERIALX_BEGIN
|
NODE_SHADER_MATERIALX_BEGIN
|
||||||
#ifdef WITH_MATERIALX
|
#ifdef WITH_MATERIALX
|
||||||
{
|
{
|
||||||
NodeItem res = empty();
|
NodeItem vector = get_input_value("Vector", NodeItem::Type::Vector3);
|
||||||
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector3);
|
|
||||||
if (!vector) {
|
|
||||||
return empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 rotation = get_input_value("Rotation", NodeItem::Type::Vector3) *
|
NodeItem rotation = get_input_value("Rotation", NodeItem::Type::Vector3) *
|
||||||
val(float(180.0f / M_PI));
|
val(float(180.0f / M_PI));
|
||||||
|
|
||||||
switch (node_->custom1) {
|
int type = node_->custom1;
|
||||||
case NODE_MAPPING_TYPE_POINT:
|
switch (type) {
|
||||||
|
case NODE_MAPPING_TYPE_POINT: {
|
||||||
|
NodeItem location = get_input_value("Location", NodeItem::Type::Vector3);
|
||||||
return (vector * scale).rotate(rotation) + location;
|
return (vector * scale).rotate(rotation) + location;
|
||||||
break;
|
}
|
||||||
case NODE_MAPPING_TYPE_TEXTURE:
|
case NODE_MAPPING_TYPE_TEXTURE: {
|
||||||
res = (vector - location).rotate(rotation, true) / scale;
|
NodeItem location = get_input_value("Location", NodeItem::Type::Vector3);
|
||||||
break;
|
return (vector - location).rotate(rotation, true) / scale;
|
||||||
case NODE_MAPPING_TYPE_VECTOR:
|
}
|
||||||
res = (vector * scale).rotate(rotation * val(MaterialX::Vector3(1.0f, 1.0f, -1.0f)));
|
case NODE_MAPPING_TYPE_VECTOR: {
|
||||||
break;
|
return (vector * scale).rotate(rotation * val(MaterialX::Vector3(1.0f, 1.0f, -1.0f)));
|
||||||
case NODE_MAPPING_TYPE_NORMAL:
|
}
|
||||||
res = (vector / scale).rotate(rotation).normalize();
|
case NODE_MAPPING_TYPE_NORMAL: {
|
||||||
break;
|
return (vector / scale).rotate(rotation).normalize();
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
BLI_assert_unreachable();
|
BLI_assert_unreachable();
|
||||||
}
|
}
|
||||||
return res;
|
return empty();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
NODE_SHADER_MATERIALX_END
|
NODE_SHADER_MATERIALX_END
|
||||||
|
@ -215,61 +215,45 @@ 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
|
||||||
{
|
{
|
||||||
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector3);
|
/* 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));
|
||||||
|
|
||||||
if (!vector) {
|
|
||||||
return empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
NodeItem angle = empty();
|
|
||||||
NodeItem axis = empty();
|
|
||||||
NodeItem center = get_input_value("Center", NodeItem::Type::Vector3) *
|
|
||||||
val(MaterialX::Vector3(1.0f, 1.0f, -1.0f));
|
|
||||||
NodeItem res = vector - center;
|
|
||||||
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 center = get_input_value("Center", NodeItem::Type::Vector3) * (X + Y + Z);
|
||||||
|
|
||||||
|
vector = vector - center;
|
||||||
|
|
||||||
if (mode == NODE_VECTOR_ROTATE_TYPE_EULER_XYZ) {
|
if (mode == NODE_VECTOR_ROTATE_TYPE_EULER_XYZ) {
|
||||||
angle = get_input_value("Rotation", NodeItem::Type::Vector3);
|
NodeItem rotation = get_input_value("Rotation", NodeItem::Type::Vector3) *
|
||||||
angle = angle * val(MaterialX::Vector3(1.0f, 1.0f, -1.0f));
|
val(float(180.0f / M_PI)) * (X + Y + Z);
|
||||||
}
|
|
||||||
else {
|
|
||||||
angle = get_input_value("Angle", NodeItem::Type::Float);
|
|
||||||
}
|
|
||||||
|
|
||||||
angle = invert ? angle * val(-1.0f) : angle;
|
|
||||||
|
|
||||||
|
return vector.rotate(invert ? -rotation : rotation, invert) + center;
|
||||||
|
}
|
||||||
|
NodeItem angle = get_input_value("Angle", NodeItem::Type::Float) * val(float(180.0f / M_PI));
|
||||||
|
NodeItem axis = empty();
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case NODE_VECTOR_ROTATE_TYPE_EULER_XYZ: {
|
case NODE_VECTOR_ROTATE_TYPE_AXIS:
|
||||||
return res.rotate(angle, invert) + center;
|
axis = get_input_value("Axis", NodeItem::Type::Vector3) * (X + Y + Z);
|
||||||
}
|
|
||||||
case NODE_VECTOR_ROTATE_TYPE_AXIS: {
|
|
||||||
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();
|
||||||
return vector;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return create_node("rotate3d",
|
return vector.rotate(invert ? -angle : angle, axis) + center;
|
||||||
NodeItem::Type::Vector3,
|
|
||||||
{{"in", res}, {"amount", angle}, {"axis", axis}}) +
|
|
||||||
center;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
NODE_SHADER_MATERIALX_END
|
NODE_SHADER_MATERIALX_END
|
||||||
|
Loading…
Reference in New Issue
Block a user