forked from blender/blender
MaterialX: add support for Vector nodes #27
@ -83,14 +83,12 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
distance = distance * val(-1.0f);
|
distance = distance * val(-1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem height_normal = create_node("heighttonormal", NodeItem::Type::Vector3);
|
NodeItem height_normal = create_node(
|
||||||
height_normal.set_input("in", height);
|
"heighttonormal", NodeItem::Type::Vector3, {{"in", height}, {"scale", strength}});
|
||||||
height_normal.set_input("scale", strength);
|
|
||||||
|
|
||||||
NodeItem res = create_node("normalmap", NodeItem::Type::Vector3);
|
NodeItem res = create_node("normalmap",
|
||||||
res.set_input("in", height_normal);
|
NodeItem::Type::Vector3,
|
||||||
res.set_input("scale", distance);
|
{{"in", height_normal}, {"scale", distance}, {"normal", normal}});
|
||||||
res.set_input("normal", normal);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -45,9 +45,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
NodeItem height = get_input_value("Height", NodeItem::Type::Float) - midlevel;
|
NodeItem height = get_input_value("Height", NodeItem::Type::Float) - midlevel;
|
||||||
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
|
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
|
||||||
|
|
||||||
NodeItem res = create_node("displacement", NodeItem::Type::Displacementshader);
|
NodeItem res = create_node("displacement",
|
||||||
res.set_input("displacement", height);
|
NodeItem::Type::Displacementshader,
|
||||||
res.set_input("scale", scale);
|
{{"displacement", height}, {"scale", scale}});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -77,32 +77,33 @@ 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 = create_node("rotate3d", NodeItem::Type::Vector3);
|
NodeItem res = empty();
|
||||||
NodeItem location = get_input_value("Location", NodeItem::Type::Vector3);
|
NodeItem location = get_input_value("Location", NodeItem::Type::Vector3);
|
||||||
NodeItem scale = get_input_value("Scale", NodeItem::Type::Vector3);
|
NodeItem scale = get_input_value("Scale", NodeItem::Type::Vector3);
|
||||||
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector3);
|
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector3);
|
||||||
NodeItem angle = (get_input_value("Rotation", NodeItem::Type::Vector3) / val(float(M_PI))) *
|
NodeItem angle = (get_input_value("Rotation", NodeItem::Type::Vector3) / val(float(M_PI))) *
|
||||||
val(180.0f);
|
val(180.0f);
|
||||||
MaterialX::Vector3 axis_vector;
|
MaterialX::Vector3 axis_vector;
|
||||||
NodeItem in = empty();
|
|
||||||
const int mode = node_->custom1;
|
const int mode = node_->custom1;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case NODE_MAPPING_TYPE_POINT:
|
case NODE_MAPPING_TYPE_POINT:
|
||||||
in = vector * scale;
|
res = vector * scale;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_MAPPING_TYPE_TEXTURE:
|
case NODE_MAPPING_TYPE_TEXTURE:
|
||||||
in = vector - location;
|
res = vector - location;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_MAPPING_TYPE_VECTOR:
|
case NODE_MAPPING_TYPE_VECTOR:
|
||||||
in = vector * scale;
|
res = vector * scale;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_MAPPING_TYPE_NORMAL:
|
case NODE_MAPPING_TYPE_NORMAL:
|
||||||
in = vector / scale;
|
res = vector / scale;
|
||||||
break;
|
break;
|
||||||
|
BLI_assert_unreachable();
|
||||||
|
return vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tex = mode == NODE_MAPPING_TYPE_TEXTURE;
|
bool tex = mode == NODE_MAPPING_TYPE_TEXTURE;
|
||||||
@ -114,12 +115,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
inv *= -1.0f;
|
inv *= -1.0f;
|
||||||
}
|
}
|
||||||
axis_vector[i] = inv;
|
axis_vector[i] = inv;
|
||||||
NodeItem res_rot = create_node("rotate3d", NodeItem::Type::Vector3);
|
res = create_node("rotate3d",
|
||||||
res_rot.set_input("in", in);
|
NodeItem::Type::Vector3,
|
||||||
res_rot.set_input("amount", angle.extract(i));
|
{{"in", res}, {"amount", angle.extract(i)}, {"axis", val(axis_vector)}});
|
||||||
res_rot.set_input("axis", val(axis_vector));
|
|
||||||
in = res_rot;
|
|
||||||
res = in;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
@ -132,9 +130,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_MAPPING_TYPE_NORMAL:
|
case NODE_MAPPING_TYPE_NORMAL:
|
||||||
NodeItem normalize = create_node("normalize", NodeItem::Type::Vector3);
|
res = create_node("normalize", NodeItem::Type::Vector3, {{"in", res}});
|
||||||
normalize.set_input("in", res);
|
|
||||||
res = normalize;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -42,9 +42,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
NodeItem in1 = get_output_default("Normal", NodeItem::Type::Vector3);
|
NodeItem in1 = get_output_default("Normal", NodeItem::Type::Vector3);
|
||||||
NodeItem in2 = get_input_value("Normal", NodeItem::Type::Vector3);
|
NodeItem in2 = get_input_value("Normal", NodeItem::Type::Vector3);
|
||||||
if (name == "Dot") {
|
if (name == "Dot") {
|
||||||
NodeItem res = create_node("dotproduct", NodeItem::Type::Float);
|
NodeItem res = create_node("dotproduct", NodeItem::Type::Float, {{"in1", in1}, {"in2", in2}});
|
||||||
res.set_input("in1", in1);
|
|
||||||
res.set_input("in2", in2);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
return in1;
|
return in1;
|
||||||
|
@ -49,9 +49,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector3);
|
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector3);
|
||||||
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
|
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
|
||||||
|
|
||||||
NodeItem res = create_node("displacement", NodeItem::Type::Displacementshader);
|
NodeItem res = create_node("displacement",
|
||||||
res.set_input("displacement", vector);
|
NodeItem::Type::Displacementshader,
|
||||||
res.set_input("scale", scale);
|
{{"displacement", vector}, {"scale", scale}});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -241,10 +241,10 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
inv *= -1.0f;
|
inv *= -1.0f;
|
||||||
}
|
}
|
||||||
axis_vector[i] = inv;
|
axis_vector[i] = inv;
|
||||||
NodeItem res_rot = create_node("rotate3d", NodeItem::Type::Vector3);
|
NodeItem res_rot = create_node(
|
||||||
res_rot.set_input("in", vector);
|
"rotate3d",
|
||||||
res_rot.set_input("amount", angle.extract(i));
|
NodeItem::Type::Vector3,
|
||||||
res_rot.set_input("axis", val(axis_vector));
|
{{"in", vector}, {"amount", angle.extract(i)}, {"axis", val(axis_vector)}});
|
||||||
vector = res_rot;
|
vector = res_rot;
|
||||||
}
|
}
|
||||||
res = vector;
|
res = vector;
|
||||||
@ -274,6 +274,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
case NODE_VECTOR_ROTATE_TYPE_AXIS_Z:
|
case NODE_VECTOR_ROTATE_TYPE_AXIS_Z:
|
||||||
axis = val(MaterialX::Vector3(0.0f, 0.0f, -1.0f));
|
axis = val(MaterialX::Vector3(0.0f, 0.0f, -1.0f));
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
BLI_assert_unreachable();
|
||||||
|
return vector;
|
||||||
}
|
}
|
||||||
res.set_input("in", vector);
|
res.set_input("in", vector);
|
||||||
res.set_input("amount", angle);
|
res.set_input("amount", angle);
|
||||||
|
@ -156,6 +156,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
break;
|
break;
|
||||||
case SHD_VECT_TRANSFORM_SPACE_CAMERA:
|
case SHD_VECT_TRANSFORM_SPACE_CAMERA:
|
||||||
return vector;
|
return vector;
|
||||||
|
default:
|
||||||
|
BLI_assert_unreachable();
|
||||||
|
return vector;
|
||||||
}
|
}
|
||||||
switch (nodeprop->convert_to) {
|
switch (nodeprop->convert_to) {
|
||||||
case SHD_VECT_TRANSFORM_SPACE_WORLD:
|
case SHD_VECT_TRANSFORM_SPACE_WORLD:
|
||||||
@ -166,6 +169,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
break;
|
break;
|
||||||
case SHD_VECT_TRANSFORM_SPACE_CAMERA:
|
case SHD_VECT_TRANSFORM_SPACE_CAMERA:
|
||||||
return vector;
|
return vector;
|
||||||
|
default:
|
||||||
|
BLI_assert_unreachable();
|
||||||
|
return vector;
|
||||||
}
|
}
|
||||||
if (fromspace == tospace) {
|
if (fromspace == tospace) {
|
||||||
return vector;
|
return vector;
|
||||||
@ -181,6 +187,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
case SHD_VECT_TRANSFORM_TYPE_VECTOR:
|
case SHD_VECT_TRANSFORM_TYPE_VECTOR:
|
||||||
res = create_node("transformvector", NodeItem::Type::Vector3);
|
res = create_node("transformvector", NodeItem::Type::Vector3);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
BLI_assert_unreachable();
|
||||||
|
return vector;
|
||||||
}
|
}
|
||||||
res.set_input("in", vector);
|
res.set_input("in", vector);
|
||||||
res.set_input("fromspace", val(fromspace));
|
res.set_input("fromspace", val(fromspace));
|
||||||
|
Loading…
Reference in New Issue
Block a user