forked from blender/blender
Move the MaterialX export code into the existing shader node files #18
@ -38,7 +38,7 @@ NodeItem NodeParser::compute_full()
|
||||
|
||||
CLOG_INFO(LOG_MATERIALX_SHADER,
|
||||
1,
|
||||
"%s [%d] - %s",
|
||||
"%s [%d] => %s",
|
||||
node_->name,
|
||||
node_->typeinfo->type,
|
||||
NodeItem::type(to_type_).c_str());
|
||||
@ -184,14 +184,4 @@ NodeItem NodeParser::get_input_value(const bNodeSocket &socket, NodeItem::Type t
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem NodeParser::get_input_shader(const std::string &name, NodeItem::Type to_type)
|
||||
{
|
||||
return get_input_link(node_->input_by_identifier(name), to_type);
|
||||
}
|
||||
|
||||
NodeItem NodeParser::get_input_shader(int index, NodeItem::Type to_type)
|
||||
{
|
||||
return get_input_link(node_->input_socket(index), to_type);
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::materialx
|
||||
|
@ -46,8 +46,6 @@ class NodeParser {
|
||||
NodeItem get_input_link(int index, NodeItem::Type to_type);
|
||||
NodeItem get_input_value(const std::string &name, NodeItem::Type to_type);
|
||||
NodeItem get_input_value(int index, NodeItem::Type to_type);
|
||||
NodeItem get_input_shader(const std::string &name, NodeItem::Type to_type);
|
||||
NodeItem get_input_shader(int index, NodeItem::Type to_type);
|
||||
NodeItem empty() const;
|
||||
template<class T> NodeItem val(const T &data) const;
|
||||
NodeItem texcoord_node();
|
||||
|
@ -17,8 +17,8 @@ NodeItem OutputMaterialNodeParser::compute()
|
||||
{
|
||||
NodeItem surface = empty();
|
||||
if (node_) {
|
||||
NodeItem bsdf = get_input_shader("Surface", NodeItem::Type::BSDF);
|
||||
NodeItem edf = get_input_shader("Surface", NodeItem::Type::EDF);
|
||||
NodeItem bsdf = get_input_link("Surface", NodeItem::Type::BSDF);
|
||||
NodeItem edf = get_input_link("Surface", NodeItem::Type::EDF);
|
||||
if (bsdf || edf) {
|
||||
surface = create_node("surface", NodeItem::Type::SurfaceShader);
|
||||
if (bsdf) {
|
||||
@ -29,7 +29,7 @@ NodeItem OutputMaterialNodeParser::compute()
|
||||
}
|
||||
}
|
||||
else {
|
||||
surface = get_input_shader("Surface", NodeItem::Type::SurfaceShader);
|
||||
surface = get_input_link("Surface", NodeItem::Type::SurfaceShader);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -28,8 +28,8 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
switch (to_type_) {
|
||||
case NodeItem::Type::BSDF:
|
||||
case NodeItem::Type::EDF: {
|
||||
NodeItem shader1 = get_input_shader(0, to_type_);
|
||||
NodeItem shader2 = get_input_shader(1, to_type_);
|
||||
NodeItem shader1 = get_input_link(0, to_type_);
|
||||
NodeItem shader2 = get_input_link(1, to_type_);
|
||||
|
||||
if (shader1 && !shader2) {
|
||||
res = shader1;
|
||||
@ -44,9 +44,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
}
|
||||
case NodeItem::Type::SurfaceShader: {
|
||||
/* SurfaceShaders can't be added, returning the first one connected */
|
||||
res = get_input_shader(0, to_type_);
|
||||
res = get_input_link(0, to_type_);
|
||||
if (!res) {
|
||||
res = get_input_shader(1, to_type_);
|
||||
res = get_input_link(1, to_type_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
case NodeItem::Type::BSDF:
|
||||
case NodeItem::Type::EDF: {
|
||||
NodeItem fac = get_input_value(0, NodeItem::Type::Float);
|
||||
NodeItem shader1 = get_input_shader(1, to_type_);
|
||||
NodeItem shader2 = get_input_shader(2, to_type_);
|
||||
NodeItem shader1 = get_input_link(1, to_type_);
|
||||
NodeItem shader2 = get_input_link(2, to_type_);
|
||||
|
||||
if (shader1 && !shader2) {
|
||||
res = shader1 * (val(1.0f) - fac);
|
||||
@ -49,9 +49,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
}
|
||||
case NodeItem::Type::SurfaceShader: {
|
||||
/* SurfaceShaders can't be mixed, returning the first one connected */
|
||||
res = get_input_shader(1, NodeItem::Type::SurfaceShader);
|
||||
res = get_input_link(1, NodeItem::Type::SurfaceShader);
|
||||
if (!res) {
|
||||
res = get_input_shader(2, NodeItem::Type::SurfaceShader);
|
||||
res = get_input_link(2, NodeItem::Type::SurfaceShader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ static int node_shader_gpu_output_material(GPUMaterial *mat,
|
||||
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
{
|
||||
NodeItem bsdf = get_input_shader("Surface", NodeItem::Type::BSDF);
|
||||
NodeItem edf = get_input_shader("Surface", NodeItem::Type::EDF);
|
||||
NodeItem bsdf = get_input_link("Surface", NodeItem::Type::BSDF);
|
||||
NodeItem edf = get_input_link("Surface", NodeItem::Type::EDF);
|
||||
NodeItem surface = empty();
|
||||
if (bsdf || edf) {
|
||||
surface = create_node("surface", NodeItem::Type::SurfaceShader);
|
||||
@ -58,7 +58,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
}
|
||||
}
|
||||
else {
|
||||
surface = get_input_shader("Surface", NodeItem::Type::SurfaceShader);
|
||||
surface = get_input_link("Surface", NodeItem::Type::SurfaceShader);
|
||||
}
|
||||
NodeItem res = create_node("surfacematerial", NodeItem::Type::Material);
|
||||
res.set_input("surfaceshader", surface);
|
||||
|
@ -318,8 +318,116 @@ static void sh_node_vector_math_build_multi_function(NodeMultiFunctionBuilder &b
|
||||
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
{
|
||||
/* TODO: Implement */
|
||||
return empty();
|
||||
CLG_LogRef *LOG_MATERIALX_SHADER = materialx::LOG_MATERIALX_SHADER;
|
||||
|
||||
/* TODO: finish some math operations */
|
||||
auto op = node_->custom1;
|
||||
NodeItem res = empty();
|
||||
|
||||
/* Single operand operations */
|
||||
NodeItem x = get_input_value(0, NodeItem::Type::Vector3);
|
||||
switch (op) {
|
||||
case NODE_VECTOR_MATH_SINE:
|
||||
res = x.sin();
|
||||
break;
|
||||
case NODE_VECTOR_MATH_COSINE:
|
||||
res = x.cos();
|
||||
break;
|
||||
case NODE_VECTOR_MATH_TANGENT:
|
||||
res = x.tan();
|
||||
break;
|
||||
case NODE_VECTOR_MATH_ABSOLUTE:
|
||||
res = x.abs();
|
||||
break;
|
||||
case NODE_VECTOR_MATH_FLOOR:
|
||||
res = x.floor();
|
||||
break;
|
||||
case NODE_VECTOR_MATH_CEIL:
|
||||
res = x.ceil();
|
||||
break;
|
||||
case NODE_VECTOR_MATH_FRACTION:
|
||||
res = x % val(1.0f);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_LENGTH:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_NORMALIZE:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
|
||||
default: {
|
||||
/* 2-operand operations */
|
||||
NodeItem y = get_input_value(1, NodeItem::Type::Vector3);
|
||||
switch (op) {
|
||||
case NODE_VECTOR_MATH_ADD:
|
||||
res = x + y;
|
||||
break;
|
||||
case NODE_VECTOR_MATH_SUBTRACT:
|
||||
res = x - y;
|
||||
break;
|
||||
case NODE_VECTOR_MATH_MULTIPLY:
|
||||
res = x * y;
|
||||
break;
|
||||
case NODE_VECTOR_MATH_DIVIDE:
|
||||
res = x / y;
|
||||
break;
|
||||
case NODE_VECTOR_MATH_MINIMUM:
|
||||
res = x.min(y);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_MAXIMUM:
|
||||
res = x.max(y);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_MODULO:
|
||||
res = x % y;
|
||||
break;
|
||||
case NODE_VECTOR_MATH_SNAP:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_CROSS_PRODUCT:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_DOT_PRODUCT:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_PROJECT:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_REFLECT:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_DISTANCE:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_SCALE:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
|
||||
default: {
|
||||
/* 3-operand operations */
|
||||
NodeItem z = get_input_value(2, NodeItem::Type::Vector3);
|
||||
switch (op) {
|
||||
case NODE_VECTOR_MATH_MULTIPLY_ADD:
|
||||
res = x * y + z;
|
||||
break;
|
||||
case NODE_VECTOR_MATH_REFRACT:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_FACEFORWARD:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_VECTOR_MATH_WRAP:
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user