Move the MaterialX export code into the existing shader node files #18

Merged
Bogdan Nagirniak merged 14 commits from BogdanNagirniak/blender:matx-move-code into matx-export-material 2023-09-12 13:55:27 +02:00
3 changed files with 17 additions and 94 deletions
Showing only changes of commit c5e5867934 - Show all commits

View File

@ -147,21 +147,6 @@ set(LIB
if(WITH_MATERIALX)
list(APPEND SRC
materialx/material.cc
materialx/nodes/add_shader.cc
materialx/nodes/blackbody.cc
materialx/nodes/brightness.cc
materialx/nodes/bsdf_diffuse.cc
materialx/nodes/bsdf_glass.cc
materialx/nodes/bsdf_glossy.cc
materialx/nodes/bsdf_principled.cc
materialx/nodes/bsdf_refraction.cc
materialx/nodes/bsdf_sheen.cc
materialx/nodes/bsdf_toon.cc
materialx/nodes/bsdf_translucent.cc
materialx/nodes/bsdf_transparent.cc
materialx/nodes/clamp.cc
materialx/nodes/color_ramp.cc
materialx/nodes/curves.cc
materialx/nodes/gamma.cc
materialx/nodes/emission.cc
materialx/nodes/huesatval.cc
@ -180,9 +165,7 @@ if(WITH_MATERIALX)
materialx/nodes/sepcomb_color.cc
materialx/nodes/sepcomb_xyz.cc
materialx/nodes/subsurface_scattering.cc
materialx/nodes/tex_checker.cc
materialx/nodes/tex_environment.cc
materialx/nodes/tex_image.cc
materialx/nodes/tex_noise.cc
materialx/nodes/vector_math.cc
materialx/nodes/wavelength.cc

View File

@ -146,11 +146,9 @@ NodeItem NodeParser::get_input_default(const bNodeSocket &socket, NodeItem::Type
NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to_type)
{
NodeItem res = empty();
const bNodeLink *link = socket.link;
if (!(link && link->is_used())) {
return res;
return empty();
}
const bNode *from_node = link->fromnode;
@ -159,80 +157,22 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to
while (from_node->type == NODE_REROUTE) {
link = from_node->input_socket(0).link;
if (!(link && link->is_used())) {
return res;
return empty();
}
from_node = link->fromnode;
}
if (from_node->typeinfo->materialx_fn) {
NodeParserData data = {graph_, depsgraph_, material_, to_type, empty()};
from_node->typeinfo->materialx_fn(&data, const_cast<bNode *>(from_node), link->fromsock);
return data.result;
}
/* Creating required NodeParser object */
std::unique_ptr<NodeParser> parser;
#define CASE_NODE_TYPE(type, T) \
case type: \
parser = std::make_unique<T>( \
graph_, depsgraph_, material_, from_node, link->fromsock, to_type); \
break;
switch (from_node->typeinfo->type) {
CASE_NODE_TYPE(SH_NODE_BLACKBODY, BlackbodyNodeParser)
CASE_NODE_TYPE(SH_NODE_BRIGHTCONTRAST, BrightContrastNodeParser)
CASE_NODE_TYPE(SH_NODE_CLAMP, ClampNodeParser)
CASE_NODE_TYPE(SH_NODE_VALTORGB, ColorRampNodeParser)
CASE_NODE_TYPE(SH_NODE_CURVE_FLOAT, CurvesFloatNodeParser)
CASE_NODE_TYPE(SH_NODE_CURVE_RGB, CurvesRGBNodeParser)
CASE_NODE_TYPE(SH_NODE_GAMMA, GammaNodeParser)
CASE_NODE_TYPE(SH_NODE_COMBINE_COLOR, CombineColorNodeParser)
CASE_NODE_TYPE(SH_NODE_COMBXYZ, CombineXYZNodeParser)
CASE_NODE_TYPE(SH_NODE_HUE_SAT, HueSatValNodeParser)
CASE_NODE_TYPE(SH_NODE_INVERT, InvertNodeParser)
CASE_NODE_TYPE(SH_NODE_LIGHT_FALLOFF, LightFalloffNodeParser)
CASE_NODE_TYPE(SH_NODE_LIGHT_PATH, LightPathNodeParser)
CASE_NODE_TYPE(SH_NODE_MAP_RANGE, MapRangeNodeParser)
CASE_NODE_TYPE(SH_NODE_MATH, MathNodeParser)
CASE_NODE_TYPE(SH_NODE_MIX_RGB_LEGACY, MixRGBNodeParser)
CASE_NODE_TYPE(SH_NODE_NORMAL_MAP, NormalMapNodeParser)
CASE_NODE_TYPE(SH_NODE_RGBTOBW, RGBToBWNodeParser)
CASE_NODE_TYPE(SH_NODE_SEPARATE_COLOR, SeparateColorNodeParser)
CASE_NODE_TYPE(SH_NODE_SEPXYZ, SeparateXYZNodeParser)
CASE_NODE_TYPE(SH_NODE_TEX_CHECKER, TexCheckerNodeParser)
CASE_NODE_TYPE(SH_NODE_TEX_ENVIRONMENT, TexEnvironmentNodeParser)
CASE_NODE_TYPE(SH_NODE_TEX_IMAGE, TexImageNodeParser)
CASE_NODE_TYPE(SH_NODE_TEX_NOISE, TexNoiseNodeParser)
CASE_NODE_TYPE(SH_NODE_VECTOR_MATH, VectorMathNodeParser)
CASE_NODE_TYPE(SH_NODE_WAVELENGTH, WavelengthNodeParser)
CASE_NODE_TYPE(SH_NODE_ADD_SHADER, AddShaderNodeParser)
CASE_NODE_TYPE(SH_NODE_BSDF_DIFFUSE, BSDFDiffuseNodeParser)
// CASE_SHADER_NODE_TYPE(SH_NODE_BSDF_GLASS, BSDFGlassNodeParser)
// CASE_SHADER_NODE_TYPE(SH_NODE_BSDF_GLOSSY, BSDFGlossyNodeParser)
CASE_NODE_TYPE(SH_NODE_BSDF_PRINCIPLED, BSDFPrincipledNodeParser)
// CASE_SHADER_NODE_TYPE(SH_NODE_BSDF_REFRACTION, BSDFRefractionNodeParser)
// CASE_SHADER_NODE_TYPE(SH_NODE_BSDF_SHEEN, BSDFSheenNodeParser)
// CASE_SHADER_NODE_TYPE(SH_NODE_BSDF_TOON, BSDFToonNodeParser)
// CASE_SHADER_NODE_TYPE(SH_NODE_BSDF_TRANSLUCENT, BSDFTranslucentNodeParser)
// CASE_SHADER_NODE_TYPE(SH_NODE_BSDF_TRANSPARENT, BSDFTransparentNodeParser)
CASE_NODE_TYPE(SH_NODE_EMISSION, EmissionNodeParser)
CASE_NODE_TYPE(SH_NODE_MIX_SHADER, MixShaderNodeParser)
// CASE_SHADER_NODE_TYPE(SH_NODE_SUBSURFACE_SCATTERING, SubsurfaceScatteringNodeParser)
default:
CLOG_WARN(LOG_MATERIALX_SHADER,
"Unsupported node: %s [%d]",
from_node->name,
from_node->typeinfo->type);
}
if (!parser) {
return res;
if (!from_node->typeinfo->materialx_fn) {
CLOG_WARN(LOG_MATERIALX_SHADER,
"Unsupported node: %s [%d]",
from_node->name,
from_node->typeinfo->type);
return empty();
}
/* Computing */
res = parser->compute_full();
return res;
NodeParserData data = {graph_, depsgraph_, material_, to_type, empty()};
from_node->typeinfo->materialx_fn(&data, const_cast<bNode *>(from_node), link->fromsock);
return data.result;
}
NodeItem NodeParser::get_input_value(const bNodeSocket &socket, NodeItem::Type to_type)

View File

@ -111,8 +111,8 @@ static void sh_node_curve_vec_build_multi_function(NodeMultiFunctionBuilder &bui
NODE_SHADER_MATERIALX_BEGIN
{
/* TODO: Implement */
return empty();
/* TODO: implement */
return get_input_value("Value", NodeItem::Type::Vector3);
}
NODE_SHADER_MATERIALX_END
@ -261,8 +261,8 @@ static void sh_node_curve_rgb_build_multi_function(NodeMultiFunctionBuilder &bui
NODE_SHADER_MATERIALX_BEGIN
{
/* TODO: Implement */
return empty();
/* TODO: implement */
return get_input_value("Color", NodeItem::Type::Color4);
}
NODE_SHADER_MATERIALX_END
@ -387,8 +387,8 @@ static void sh_node_curve_float_build_multi_function(NodeMultiFunctionBuilder &b
NODE_SHADER_MATERIALX_BEGIN
{
/* TODO: Implement */
return empty();
/* TODO: implement */
return get_input_value("Value", NodeItem::Type::Float);
}
NODE_SHADER_MATERIALX_END