forked from blender/blender
MaterialX: Move NodeItem::Type argument from setters to getters #12
@ -8,9 +8,9 @@ namespace blender::nodes::materialx {
|
||||
|
||||
NodeItem BrightContrastNodeParser::compute()
|
||||
{
|
||||
NodeItem color = get_input_value("Color");
|
||||
NodeItem bright = get_input_value("Bright");
|
||||
NodeItem contrast = get_input_value("Contrast");
|
||||
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||
NodeItem bright = get_input_value("Bright", NodeItem::Type::Float);
|
||||
NodeItem contrast = get_input_value("Contrast", NodeItem::Type::Float);
|
||||
|
||||
/* This formula was given from OSL shader code in Cycles. */
|
||||
return (bright + color * (contrast + value(1.0f)) - contrast * value(0.5f)).max(value(0.0f));
|
||||
|
@ -8,38 +8,36 @@ namespace blender::nodes::materialx {
|
||||
|
||||
NodeItem BSDFPrincipledNodeParser::compute()
|
||||
{
|
||||
/* Getting required inputs
|
||||
* Note: if some inputs are not needed they won't be taken */
|
||||
NodeItem base_color = get_input_value("Base Color");
|
||||
NodeItem base_color = get_input_value("Base Color", NodeItem::Type::Color3);
|
||||
|
||||
NodeItem subsurface = get_input_value("Subsurface");
|
||||
NodeItem subsurface_radius = get_input_value("Subsurface Radius");
|
||||
NodeItem subsurface_color = get_input_value("Subsurface Color");
|
||||
NodeItem subsurface = get_input_value("Subsurface", NodeItem::Type::Float);
|
||||
NodeItem subsurface_radius = get_input_value("Subsurface Radius", NodeItem::Type::Color3);
|
||||
NodeItem subsurface_color = get_input_value("Subsurface Color", NodeItem::Type::Color3);
|
||||
|
||||
NodeItem metallic = get_input_value("Metallic");
|
||||
NodeItem specular = get_input_value("Specular");
|
||||
NodeItem metallic = get_input_value("Metallic", NodeItem::Type::Float);
|
||||
NodeItem specular = get_input_value("Specular", NodeItem::Type::Float);
|
||||
// NodeItem specular_tint = get_input_value("Specular Tint");
|
||||
NodeItem roughness = get_input_value("Roughness");
|
||||
NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Float);
|
||||
|
||||
/* TODO: use Specular Tint input */
|
||||
NodeItem anisotropic = get_input_value("Anisotropic");
|
||||
NodeItem anisotropic_rotation = get_input_value("Anisotropic Rotation");
|
||||
NodeItem anisotropic = get_input_value("Anisotropic", NodeItem::Type::Float);
|
||||
NodeItem anisotropic_rotation = get_input_value("Anisotropic Rotation", NodeItem::Type::Float);
|
||||
// anisotropic_rotation = 0.5 - (anisotropic_rotation % 1.0)
|
||||
|
||||
NodeItem sheen = get_input_value("Sheen");
|
||||
NodeItem sheen = get_input_value("Sheen", NodeItem::Type::Float);
|
||||
// sheen_tint = get_input_value("Sheen Tint");
|
||||
|
||||
NodeItem clearcoat = get_input_value("Clearcoat");
|
||||
NodeItem clearcoat_roughness = get_input_value("Clearcoat Roughness");
|
||||
NodeItem clearcoat = get_input_value("Clearcoat", NodeItem::Type::Float);
|
||||
NodeItem clearcoat_roughness = get_input_value("Clearcoat Roughness", NodeItem::Type::Float);
|
||||
|
||||
NodeItem ior = get_input_value("IOR");
|
||||
NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
|
||||
|
||||
NodeItem transmission = get_input_value("Transmission");
|
||||
NodeItem transmission = get_input_value("Transmission", NodeItem::Type::Float);
|
||||
|
||||
NodeItem emission = get_input_value("Emission");
|
||||
NodeItem emission_strength = get_input_value("Emission Strength");
|
||||
NodeItem emission = get_input_value("Emission", NodeItem::Type::Color3);
|
||||
NodeItem emission_strength = get_input_value("Emission Strength", NodeItem::Type::Float);
|
||||
|
||||
NodeItem alpha = get_input_value("Alpha");
|
||||
NodeItem alpha = get_input_value("Alpha", NodeItem::Type::Float);
|
||||
// transparency = 1.0 - alpha
|
||||
|
||||
NodeItem normal = get_input_link("Normal");
|
||||
@ -49,7 +47,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
|
||||
/* Creating standard_surface */
|
||||
NodeItem res = create_node("standard_surface", "surfaceshader");
|
||||
res.set_input("base", 1.0, "float");
|
||||
res.set_input("base_color", base_color, NodeItem::Type::Color3);
|
||||
res.set_input("base_color", base_color);
|
||||
res.set_input("diffuse_roughness", roughness);
|
||||
if (normal) {
|
||||
res.set_input("normal", normal);
|
||||
@ -60,27 +58,27 @@ NodeItem BSDFPrincipledNodeParser::compute()
|
||||
res.set_input("metalness", metallic);
|
||||
|
||||
res.set_input("specular", specular);
|
||||
res.set_input("specular_color", base_color, NodeItem::Type::Color3);
|
||||
res.set_input("specular_color", base_color);
|
||||
res.set_input("specular_roughness", roughness);
|
||||
res.set_input("specular_IOR", ior);
|
||||
res.set_input("specular_anisotropy", anisotropic);
|
||||
res.set_input("specular_rotation", anisotropic_rotation);
|
||||
|
||||
res.set_input("transmission", transmission);
|
||||
res.set_input("transmission_color", base_color, NodeItem::Type::Color3);
|
||||
res.set_input("transmission_color", base_color);
|
||||
res.set_input("transmission_extra_roughness", roughness);
|
||||
|
||||
res.set_input("subsurface", subsurface);
|
||||
res.set_input("subsurface_color", subsurface_color, NodeItem::Type::Color3);
|
||||
res.set_input("subsurface_radius", subsurface_radius, NodeItem::Type::Color3);
|
||||
res.set_input("subsurface_color", subsurface_color);
|
||||
res.set_input("subsurface_radius", subsurface_radius);
|
||||
res.set_input("subsurface_anisotropy", anisotropic);
|
||||
|
||||
res.set_input("sheen", sheen);
|
||||
res.set_input("sheen_color", base_color, NodeItem::Type::Color3);
|
||||
res.set_input("sheen_color", base_color);
|
||||
res.set_input("sheen_roughness", roughness);
|
||||
|
||||
res.set_input("coat", clearcoat);
|
||||
res.set_input("coat_color", base_color, NodeItem::Type::Color3);
|
||||
res.set_input("coat_color", base_color);
|
||||
res.set_input("coat_roughness", clearcoat_roughness);
|
||||
res.set_input("coat_IOR", ior);
|
||||
res.set_input("coat_anisotropy", anisotropic);
|
||||
@ -90,7 +88,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
|
||||
}
|
||||
|
||||
res.set_input("emission", emission_strength);
|
||||
res.set_input("emission_color", emission, NodeItem::Type::Color3);
|
||||
res.set_input("emission_color", emission);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ NodeItem HueSatValNodeParser::compute()
|
||||
{
|
||||
/* TODO: implement fac, see do_hue_sat_fac in
|
||||
* source\blender\nodes\texture\nodes\node_texture_hueSatVal.cc */
|
||||
NodeItem hue = get_input_value("Hue");
|
||||
NodeItem saturation = get_input_value("Saturation");
|
||||
NodeItem val = get_input_value("Value");
|
||||
NodeItem fac = get_input_value("Fac");
|
||||
NodeItem color = get_input_value("Color");
|
||||
NodeItem hue = get_input_value("Hue", NodeItem::Type::Float);
|
||||
NodeItem saturation = get_input_value("Saturation", NodeItem::Type::Float);
|
||||
NodeItem val = get_input_value("Value", NodeItem::Type::Float);
|
||||
NodeItem fac = get_input_value("Fac", NodeItem::Type::Float);
|
||||
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||
|
||||
/* Modifier to follow Cycles result */
|
||||
hue = hue - value(0.5f);
|
||||
@ -25,7 +25,7 @@ NodeItem HueSatValNodeParser::compute()
|
||||
combine.set_input("in3", val);
|
||||
|
||||
NodeItem res = create_node("hsvadjust", "color3");
|
||||
res.set_input("in", color, NodeItem::Type::Color3);
|
||||
res.set_input("in", color);
|
||||
res.set_input("amount", combine);
|
||||
return res;
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ namespace blender::nodes::materialx {
|
||||
|
||||
NodeItem InvertNodeParser::compute()
|
||||
{
|
||||
NodeItem fac = get_input_value("Fac");
|
||||
NodeItem color = get_input_value("Color");
|
||||
NodeItem fac = get_input_value("Fac", NodeItem::Type::Float);
|
||||
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||
return fac.blend(color, fac.val(1.0f) - color);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ NodeItem MathNodeParser::compute()
|
||||
NodeItem res = empty();
|
||||
|
||||
/* Single operand operations */
|
||||
NodeItem x = get_input_value(0);
|
||||
NodeItem x = get_input_value(0, NodeItem::Type::Empty);
|
||||
switch (op) {
|
||||
case NODE_MATH_SINE:
|
||||
res = x.sin();
|
||||
@ -82,7 +82,7 @@ NodeItem MathNodeParser::compute()
|
||||
|
||||
default: {
|
||||
/* 2-operand operations */
|
||||
NodeItem y = get_input_value(1);
|
||||
NodeItem y = get_input_value(1, NodeItem::Type::Empty);
|
||||
switch (op) {
|
||||
case NODE_MATH_ADD:
|
||||
res = x + y;
|
||||
@ -132,7 +132,7 @@ NodeItem MathNodeParser::compute()
|
||||
|
||||
default: {
|
||||
/* 3-operand operations */
|
||||
NodeItem z = get_input_value(2);
|
||||
NodeItem z = get_input_value(2, NodeItem::Type::Empty);
|
||||
switch (op) {
|
||||
case NODE_MATH_WRAP:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
|
@ -549,14 +549,6 @@ void NodeItem::set_input(const std::string &name,
|
||||
}
|
||||
}
|
||||
|
||||
void NodeItem::set_input(const std::string &name,
|
||||
const NodeItem &item,
|
||||
Type in_type,
|
||||
const std::string &output_name)
|
||||
{
|
||||
set_input(name, item.convert(in_type), output_name);
|
||||
}
|
||||
|
||||
void NodeItem::add_output(const std::string &name, Type out_type)
|
||||
{
|
||||
node->addOutput(name, type(out_type));
|
||||
|
@ -89,10 +89,6 @@ class NodeItem {
|
||||
void set_input(const std::string &in_name,
|
||||
const NodeItem &item,
|
||||
const std::string &out_name = "");
|
||||
void set_input(const std::string &in_name,
|
||||
const NodeItem &item,
|
||||
Type in_type,
|
||||
const std::string &out_name = "");
|
||||
void add_output(const std::string &in_name, Type out_type);
|
||||
|
||||
private:
|
||||
|
@ -56,14 +56,14 @@ NodeItem NodeParser::get_input_link(int index)
|
||||
return get_input_link(node_->input_socket(index));
|
||||
}
|
||||
|
||||
NodeItem NodeParser::get_input_value(const std::string &name)
|
||||
NodeItem NodeParser::get_input_value(const std::string &name, const NodeItem::Type type)
|
||||
{
|
||||
return get_input_value(node_->input_by_identifier(name));
|
||||
return get_input_value(node_->input_by_identifier(name), type);
|
||||
}
|
||||
|
||||
NodeItem NodeParser::get_input_value(int index)
|
||||
NodeItem NodeParser::get_input_value(int index, const NodeItem::Type type)
|
||||
{
|
||||
return get_input_value(node_->input_socket(index));
|
||||
return get_input_value(node_->input_socket(index), type);
|
||||
}
|
||||
|
||||
NodeItem NodeParser::empty() const
|
||||
@ -159,13 +159,13 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket)
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem NodeParser::get_input_value(const bNodeSocket &socket)
|
||||
NodeItem NodeParser::get_input_value(const bNodeSocket &socket, const NodeItem::Type type)
|
||||
{
|
||||
NodeItem res = get_input_link(socket);
|
||||
if (!res) {
|
||||
res = get_input_default(socket);
|
||||
}
|
||||
return res;
|
||||
return type == NodeItem::Type::Empty ? res : res.convert(type);
|
||||
}
|
||||
|
||||
NodeItem NodeParser::compute_full()
|
||||
|
@ -37,15 +37,17 @@ class NodeParser {
|
||||
NodeItem get_input_default(int index);
|
||||
NodeItem get_input_link(const std::string &name);
|
||||
NodeItem get_input_link(int index);
|
||||
NodeItem get_input_value(const std::string &name);
|
||||
NodeItem get_input_value(int index);
|
||||
NodeItem get_input_value(const std::string &name,
|
||||
const NodeItem::Type type);
|
||||
NodeItem get_input_value(int index, const NodeItem::Type type);
|
||||
NodeItem empty() const;
|
||||
template<class T> NodeItem value(const T &data) const;
|
||||
|
||||
private:
|
||||
NodeItem get_input_default(const bNodeSocket &socket);
|
||||
NodeItem get_input_link(const bNodeSocket &socket);
|
||||
NodeItem get_input_value(const bNodeSocket &socket);
|
||||
NodeItem get_input_value(const bNodeSocket &socket,
|
||||
const NodeItem::Type type);
|
||||
NodeItem compute_full();
|
||||
};
|
||||
|
||||
|
@ -11,11 +11,11 @@ NodeItem NormalMapNodeParser::compute()
|
||||
{
|
||||
std::string default_space = "object";
|
||||
NodeShaderNormalMap *normal_map_node = static_cast<NodeShaderNormalMap *>(node_->storage);
|
||||
NodeItem color = get_input_value("Color");
|
||||
NodeItem strength = get_input_value("Strength");
|
||||
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||
NodeItem strength = get_input_value("Strength", NodeItem::Type::Float);
|
||||
|
||||
NodeItem res = create_node("normalmap", "vector3");
|
||||
res.set_input("in", color, NodeItem::Type::Color3);
|
||||
res.set_input("in", color);
|
||||
res.set_input("scale", strength);
|
||||
|
||||
switch (normal_map_node->space) {
|
||||
|
@ -10,7 +10,7 @@ namespace blender::nodes::materialx {
|
||||
NodeItem SeparateColorNodeParser::compute()
|
||||
{
|
||||
int mode = static_cast<NodeCombSepColor *>(node_->storage)->mode;
|
||||
NodeItem color = get_input_value("Color");
|
||||
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||
|
||||
NodeItem convert = empty();
|
||||
|
||||
@ -39,9 +39,9 @@ NodeItem SeparateColorNodeParser::compute()
|
||||
NodeItem CombineColorNodeParser::compute()
|
||||
{
|
||||
int mode = static_cast<NodeCombSepColor *>(node_->storage)->mode;
|
||||
NodeItem red = get_input_value("Red");
|
||||
NodeItem green = get_input_value("Green");
|
||||
NodeItem blue = get_input_value("Blue");
|
||||
NodeItem red = get_input_value("Red", NodeItem::Type::Float);
|
||||
NodeItem green = get_input_value("Green", NodeItem::Type::Float);
|
||||
NodeItem blue = get_input_value("Blue", NodeItem::Type::Float);
|
||||
|
||||
NodeItem convert = empty();
|
||||
NodeItem combine = create_node("combine3", "color3");
|
||||
|
@ -8,16 +8,16 @@ namespace blender::nodes::materialx {
|
||||
|
||||
NodeItem SeparateXYZNodeParser::compute()
|
||||
{
|
||||
NodeItem vector = get_input_value("Vector");
|
||||
NodeItem vector = get_input_value("Vector", NodeItem::Type::Vector3);
|
||||
int index = STREQ(socket_out_->name, "X") ? 0 : STREQ(socket_out_->name, "Y") ? 1 : 2;
|
||||
return vector.extract(index);
|
||||
}
|
||||
|
||||
NodeItem CombineXYZNodeParser::compute()
|
||||
{
|
||||
NodeItem x = get_input_value("X");
|
||||
NodeItem y = get_input_value("Y");
|
||||
NodeItem z = get_input_value("Z");
|
||||
NodeItem x = get_input_value("X", NodeItem::Type::Float);
|
||||
NodeItem y = get_input_value("Y", NodeItem::Type::Float);
|
||||
NodeItem z = get_input_value("Z", NodeItem::Type::Float);
|
||||
NodeItem res = create_node("combine3", "vector3");
|
||||
res.set_input("in1", x);
|
||||
res.set_input("in2", y);
|
||||
|
@ -9,9 +9,9 @@ namespace blender::nodes::materialx {
|
||||
NodeItem TexCheckerNodeParser::compute()
|
||||
{
|
||||
NodeItem vector = get_input_link("Vector");
|
||||
NodeItem color1 = get_input_value("Color1");
|
||||
NodeItem color2 = get_input_value("Color2");
|
||||
NodeItem scale = get_input_value("Scale");
|
||||
NodeItem color1 = get_input_value("Color1", NodeItem::Type::Color3);
|
||||
NodeItem color2 = get_input_value("Color2", NodeItem::Type::Color3);
|
||||
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
|
||||
|
||||
if (!vector) {
|
||||
vector = create_node("texcoord", "vector2");
|
||||
@ -19,7 +19,7 @@ NodeItem TexCheckerNodeParser::compute()
|
||||
vector = vector * scale;
|
||||
|
||||
NodeItem separate = create_node("separate2", "multioutput");
|
||||
separate.set_input("in", vector, NodeItem::Type::Vector2);
|
||||
separate.set_input("in", vector);
|
||||
separate.add_output("outx", NodeItem::Type::Float);
|
||||
separate.add_output("outy", NodeItem::Type::Float);
|
||||
|
||||
@ -35,8 +35,8 @@ NodeItem TexCheckerNodeParser::compute()
|
||||
.if_else(NodeItem::CompareOp::Eq, value(1.0f), value(0.0f), value(1.0f));
|
||||
|
||||
NodeItem res = create_node("mix", "color3");
|
||||
res.set_input("bg", color1, NodeItem::Type::Color3);
|
||||
res.set_input("fg", color2, NodeItem::Type::Color3);
|
||||
res.set_input("bg", color1);
|
||||
res.set_input("fg", color2);
|
||||
res.set_input("mix", ifequal);
|
||||
return res;
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ namespace blender::nodes::materialx {
|
||||
|
||||
NodeItem TexNoiseNodeParser::compute()
|
||||
{
|
||||
NodeItem scale = get_input_value("Scale");
|
||||
NodeItem detail = get_input_value("Detail");
|
||||
NodeItem lacunarity = get_input_value("Lacunarity");
|
||||
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
|
||||
NodeItem detail = get_input_value("Detail", NodeItem::Type::Float);
|
||||
NodeItem lacunarity = get_input_value("Lacunarity", NodeItem::Type::Float);
|
||||
|
||||
if (detail.value && detail.type() == NodeItem::Type::Float) {
|
||||
detail = value(int(detail.value->asA<float>()));
|
||||
@ -20,7 +20,7 @@ NodeItem TexNoiseNodeParser::compute()
|
||||
position = position * scale;
|
||||
|
||||
NodeItem res = create_node("fractal3d", "color3");
|
||||
res.set_input("position", position, NodeItem::Type::Vector3);
|
||||
res.set_input("position", position);
|
||||
res.set_input("octaves", detail);
|
||||
res.set_input("lacunarity", lacunarity);
|
||||
return res;
|
||||
|
@ -14,7 +14,7 @@ NodeItem VectorMathNodeParser::compute()
|
||||
NodeItem res = empty();
|
||||
|
||||
/* Single operand operations */
|
||||
NodeItem x = get_input_value(0);
|
||||
NodeItem x = get_input_value(0, NodeItem::Type::Empty);
|
||||
switch (op) {
|
||||
case NODE_VECTOR_MATH_SINE:
|
||||
res = x.sin();
|
||||
@ -46,7 +46,7 @@ NodeItem VectorMathNodeParser::compute()
|
||||
|
||||
default: {
|
||||
/* 2-operand operations */
|
||||
NodeItem y = get_input_value(1);
|
||||
NodeItem y = get_input_value(1, NodeItem::Type::Empty);
|
||||
switch (op) {
|
||||
case NODE_VECTOR_MATH_ADD:
|
||||
res = x + y;
|
||||
@ -93,7 +93,7 @@ NodeItem VectorMathNodeParser::compute()
|
||||
|
||||
default: {
|
||||
/* 3-operand operations */
|
||||
NodeItem z = get_input_value(2);
|
||||
NodeItem z = get_input_value(2, NodeItem::Type::Empty);
|
||||
switch (op) {
|
||||
case NODE_VECTOR_MATH_MULTIPLY_ADD:
|
||||
res = x * y + z;
|
||||
|
Loading…
Reference in New Issue
Block a user