MaterialX: add color nodes #17

Merged
Bogdan Nagirniak merged 10 commits from matx-add-color-nodes into matx-export-material 2023-09-11 18:57:06 +02:00
9 changed files with 130 additions and 0 deletions

View File

@ -160,9 +160,14 @@ if(WITH_MATERIALX)
materialx/nodes/bsdf_translucent.cc materialx/nodes/bsdf_translucent.cc
materialx/nodes/bsdf_transparent.cc materialx/nodes/bsdf_transparent.cc
materialx/nodes/clamp.cc materialx/nodes/clamp.cc
materialx/nodes/color_ramp.cc
materialx/nodes/curves.cc
materialx/nodes/gamma.cc
materialx/nodes/emission.cc materialx/nodes/emission.cc
materialx/nodes/huesatval.cc materialx/nodes/huesatval.cc
materialx/nodes/invert.cc materialx/nodes/invert.cc
materialx/nodes/light_falloff.cc
materialx/nodes/light_path.cc
materialx/nodes/map_range.cc materialx/nodes/map_range.cc
materialx/nodes/math.cc materialx/nodes/math.cc
materialx/nodes/mix_rgb.cc materialx/nodes/mix_rgb.cc
@ -180,6 +185,7 @@ if(WITH_MATERIALX)
materialx/nodes/tex_image.cc materialx/nodes/tex_image.cc
materialx/nodes/tex_noise.cc materialx/nodes/tex_noise.cc
materialx/nodes/vector_math.cc materialx/nodes/vector_math.cc
materialx/nodes/wavelength.cc
materialx/material.h materialx/material.h
materialx/nodes/node_item.h materialx/nodes/node_item.h

View File

@ -0,0 +1,15 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h"
namespace blender::nodes::materialx {
NodeItem ColorRampNodeParser::compute()
{
/* TODO: implement */
return empty();
}
} // namespace blender::nodes::materialx

View File

@ -0,0 +1,21 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h"
namespace blender::nodes::materialx {
NodeItem CurvesRGBNodeParser::compute()
{
/* TODO: implement */
return get_input_value("Color", NodeItem::Type::Color4);
}
NodeItem CurvesFloatNodeParser::compute()
{
/* TODO: implement */
return get_input_value("Value", NodeItem::Type::Float);
}
} // namespace blender::nodes::materialx

View File

@ -0,0 +1,17 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h"
namespace blender::nodes::materialx {
NodeItem GammaNodeParser::compute()
{
NodeItem color = get_input_value("Color", NodeItem::Type::Color4);
NodeItem gamma = get_input_value("Gamma", NodeItem::Type::Float);
return color ^ gamma;
}
Review

color ^ gamma

color ^ gamma
} // namespace blender::nodes::materialx

View File

@ -0,0 +1,21 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h"
namespace blender::nodes::materialx {
NodeItem LightFalloffNodeParser::compute()
{
NodeItem strength = get_input_value("Strength", NodeItem::Type::Float);
NodeItem smooth = get_input_value("Smooth", NodeItem::Type::Float);
/* This node isn't supported by MaterialX. This formula was given from OSL shader code in Cycles
* node_light_falloff.osl. Considered ray_length=1.0f. */
strength = strength * val(1.0f) / (smooth + val(1.0f));
return strength;
}
} // namespace blender::nodes::materialx

View File

@ -0,0 +1,21 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h"
namespace blender::nodes::materialx {
NodeItem LightPathNodeParser::compute()
{
/* This node isn't supported by MaterialX. Only default values returned. */
if (STREQ(socket_out_->name, "Is Camera Ray")) {
return val(1.0f);
}
if (STREQ(socket_out_->name, "Ray Length")) {
return val(1.0f);
}
return val(0.0f);
}
} // namespace blender::nodes::materialx

View File

@ -152,10 +152,16 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to
CASE_NODE_TYPE(SH_NODE_BLACKBODY, BlackbodyNodeParser) CASE_NODE_TYPE(SH_NODE_BLACKBODY, BlackbodyNodeParser)
CASE_NODE_TYPE(SH_NODE_BRIGHTCONTRAST, BrightContrastNodeParser) CASE_NODE_TYPE(SH_NODE_BRIGHTCONTRAST, BrightContrastNodeParser)
CASE_NODE_TYPE(SH_NODE_CLAMP, ClampNodeParser) 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_COMBINE_COLOR, CombineColorNodeParser)
CASE_NODE_TYPE(SH_NODE_COMBXYZ, CombineXYZNodeParser) CASE_NODE_TYPE(SH_NODE_COMBXYZ, CombineXYZNodeParser)
CASE_NODE_TYPE(SH_NODE_HUE_SAT, HueSatValNodeParser) CASE_NODE_TYPE(SH_NODE_HUE_SAT, HueSatValNodeParser)
CASE_NODE_TYPE(SH_NODE_INVERT, InvertNodeParser) 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_MAP_RANGE, MapRangeNodeParser)
CASE_NODE_TYPE(SH_NODE_MATH, MathNodeParser) CASE_NODE_TYPE(SH_NODE_MATH, MathNodeParser)
CASE_NODE_TYPE(SH_NODE_MIX_RGB_LEGACY, MixRGBNodeParser) CASE_NODE_TYPE(SH_NODE_MIX_RGB_LEGACY, MixRGBNodeParser)
@ -168,6 +174,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to
CASE_NODE_TYPE(SH_NODE_TEX_IMAGE, TexImageNodeParser) CASE_NODE_TYPE(SH_NODE_TEX_IMAGE, TexImageNodeParser)
CASE_NODE_TYPE(SH_NODE_TEX_NOISE, TexNoiseNodeParser) CASE_NODE_TYPE(SH_NODE_TEX_NOISE, TexNoiseNodeParser)
CASE_NODE_TYPE(SH_NODE_VECTOR_MATH, VectorMathNodeParser) CASE_NODE_TYPE(SH_NODE_VECTOR_MATH, VectorMathNodeParser)
CASE_NODE_TYPE(SH_NODE_WAVELENGTH, WavelengthNodeParser)
default: default:
CLOG_WARN(LOG_MATERIALX_SHADER, CLOG_WARN(LOG_MATERIALX_SHADER,

View File

@ -94,10 +94,16 @@ template<class T> NodeItem NodeParser::val(const T &data) const
DECLARE_NODE_PARSER(BlackbodyNodeParser) DECLARE_NODE_PARSER(BlackbodyNodeParser)
DECLARE_NODE_PARSER(BrightContrastNodeParser) DECLARE_NODE_PARSER(BrightContrastNodeParser)
DECLARE_NODE_PARSER(ClampNodeParser) DECLARE_NODE_PARSER(ClampNodeParser)
DECLARE_NODE_PARSER(ColorRampNodeParser)
DECLARE_NODE_PARSER(CurvesFloatNodeParser)
DECLARE_NODE_PARSER(CurvesRGBNodeParser)
DECLARE_NODE_PARSER(CombineColorNodeParser) DECLARE_NODE_PARSER(CombineColorNodeParser)
DECLARE_NODE_PARSER(CombineXYZNodeParser) DECLARE_NODE_PARSER(CombineXYZNodeParser)
DECLARE_NODE_PARSER(GammaNodeParser)
DECLARE_NODE_PARSER(HueSatValNodeParser) DECLARE_NODE_PARSER(HueSatValNodeParser)
DECLARE_NODE_PARSER(InvertNodeParser) DECLARE_NODE_PARSER(InvertNodeParser)
DECLARE_NODE_PARSER(LightFalloffNodeParser)
DECLARE_NODE_PARSER(LightPathNodeParser)
DECLARE_NODE_PARSER(MapRangeNodeParser) DECLARE_NODE_PARSER(MapRangeNodeParser)
DECLARE_NODE_PARSER(MathNodeParser) DECLARE_NODE_PARSER(MathNodeParser)
DECLARE_NODE_PARSER(MixRGBNodeParser) DECLARE_NODE_PARSER(MixRGBNodeParser)
@ -110,6 +116,7 @@ DECLARE_NODE_PARSER(TexEnvironmentNodeParser)
DECLARE_NODE_PARSER(TexImageNodeParser) DECLARE_NODE_PARSER(TexImageNodeParser)
DECLARE_NODE_PARSER(TexNoiseNodeParser) DECLARE_NODE_PARSER(TexNoiseNodeParser)
DECLARE_NODE_PARSER(VectorMathNodeParser) DECLARE_NODE_PARSER(VectorMathNodeParser)
DECLARE_NODE_PARSER(WavelengthNodeParser)
DECLARE_SHADER_NODE_PARSER(AddShaderNodeParser) DECLARE_SHADER_NODE_PARSER(AddShaderNodeParser)
DECLARE_SHADER_NODE_PARSER(BSDFDiffuseNodeParser) DECLARE_SHADER_NODE_PARSER(BSDFDiffuseNodeParser)

View File

@ -0,0 +1,15 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h"
namespace blender::nodes::materialx {
NodeItem WavelengthNodeParser::compute()
{
/* TODO: implement */
return empty();
}
} // namespace blender::nodes::materialx