MaterialX: fix review comments #19

Merged
Bogdan Nagirniak merged 10 commits from matx-fix-review-comments into matx-export-material 2023-09-14 02:01:04 +02:00
29 changed files with 73 additions and 1 deletions
Showing only changes of commit b9dcad1f86 - Show all commits

View File

@ -22,7 +22,13 @@
#include "node_shader_register.hh"
#ifdef WITH_MATERIALX
# include "materialx/node_parser.h"
#else
# define NODE_SHADER_MATERIALX_BEGIN \
void node_shader_materialx(void *data, struct bNode *node, struct bNodeSocket *out)
# define NODE_SHADER_MATERIALX_END
BogdanNagirniak marked this conversation as resolved
Review

Seems could be simpliifed to:

#  define NODE_SHADER_MATERIALX_BEGIN \
    void *node_shader_materialx = nullptr;
#  define NODE_SHADER_MATERIALX_END

Export code would be:

NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
....
}
#endif
NODE_SHADER_MATERIALX_END
Seems could be simpliifed to: ``` # define NODE_SHADER_MATERIALX_BEGIN \ void *node_shader_materialx = nullptr; # define NODE_SHADER_MATERIALX_END ``` Export code would be: ``` NODE_SHADER_MATERIALX_BEGIN #ifdef WITH_MATERIALX { .... } #endif NODE_SHADER_MATERIALX_END ```
#endif
struct bContext;
typedef struct bContext bContext;

View File

@ -24,6 +24,7 @@ static int node_shader_gpu_add_shader(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
NodeItem res = empty();
switch (to_type_) {
case NodeItem::Type::BSDF:
@ -54,6 +55,7 @@ NODE_SHADER_MATERIALX_BEGIN
BLI_assert_unreachable();
}
return res;
#endif
}
NODE_SHADER_MATERIALX_END
@ -69,6 +71,7 @@ void register_node_type_sh_add_shader()
sh_node_type_base(&ntype, SH_NODE_ADD_SHADER, "Add Shader", NODE_CLASS_SHADER);
ntype.declare = file_ns::node_declare;
ntype.gpu_fn = file_ns::node_shader_gpu_add_shader;
ntype.materialx_fn = file_ns::node_shader_materialx;
nodeRegisterType(&ntype);
}

View File

@ -33,6 +33,7 @@ static int node_shader_gpu_blackbody(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
/* TODO: This node doesn't have an implementation in MaterialX 1.38.6.
* It's added in MaterialX 1.38.8. Uncomment this code after switching to 1.38.8.
*
@ -42,6 +43,7 @@ NODE_SHADER_MATERIALX_BEGIN
* res.set_input("temperature", temperature);
* return res; */
return empty();
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -25,12 +25,14 @@ static int gpu_shader_brightcontrast(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
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 + val(1.0f)) - contrast * val(0.5f)).max(val(0.0f));
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -36,6 +36,7 @@ static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
if (to_type_ != NodeItem::Type::BSDF) {
return empty();
}
@ -51,6 +52,7 @@ NODE_SHADER_MATERIALX_BEGIN
res.set_input("normal", normal);
}
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -255,6 +255,7 @@ static void node_shader_update_principled(bNodeTree *ntree, bNode *node)
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
if (to_type_ != NodeItem::Type::SurfaceShader) {
/* TODO: implement for BSDF and EDF */
return empty();
@ -343,6 +344,7 @@ NODE_SHADER_MATERIALX_BEGIN
res.set_input("emission_color", emission);
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -72,6 +72,7 @@ static void sh_node_clamp_build_multi_function(NodeMultiFunctionBuilder &builder
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
auto type = node_->custom1;
NodeItem value = get_input_value("Value", NodeItem::Type::Float);
NodeItem min = get_input_value("Min", NodeItem::Type::Float);
@ -86,6 +87,7 @@ NODE_SHADER_MATERIALX_BEGIN
res = value.clamp(min, max);
}
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -138,8 +138,11 @@ static void sh_node_valtorgb_build_multi_function(nodes::NodeMultiFunctionBuilde
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
/* TODO: Implement */
return empty();
#endif
}
NODE_SHADER_MATERIALX_END

View File

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

View File

@ -26,6 +26,7 @@ static int node_shader_gpu_emission(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
if (to_type_ != NodeItem::Type::EDF) {
return empty();
}
@ -36,6 +37,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem res = create_node("uniform_edf", NodeItem::Type::EDF);
res.set_input("color", color * strength);
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -24,9 +24,11 @@ static int node_shader_gpu_gamma(GPUMaterial *mat,
}
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
NodeItem color = get_input_value("Color", NodeItem::Type::Color4);
NodeItem gamma = get_input_value("Gamma", NodeItem::Type::Float);
return color ^ gamma;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -32,6 +32,7 @@ static int gpu_shader_hue_sat(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
/* TODO: implement fac */
NodeItem hue = get_input_value("Hue", NodeItem::Type::Float);
NodeItem saturation = get_input_value("Saturation", NodeItem::Type::Float);
@ -51,6 +52,7 @@ NODE_SHADER_MATERIALX_BEGIN
res.set_input("in", color);
res.set_input("amount", combine);
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -28,9 +28,11 @@ static int gpu_shader_invert(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
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);
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -26,12 +26,14 @@ static int node_shader_gpu_light_falloff(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
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. */
return strength * val(1.0f) / (smooth + val(1.0f));
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -34,6 +34,7 @@ static int node_shader_gpu_light_path(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
/* This node isn't supported by MaterialX. Only default values returned. */
if (STREQ(socket_out_->name, "Is Camera Ray")) {
return val(1.0f);
@ -42,6 +43,7 @@ NODE_SHADER_MATERIALX_BEGIN
return val(1.0f);
}
return val(0.0f);
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -444,6 +444,7 @@ static void sh_node_map_range_build_multi_function(NodeMultiFunctionBuilder &bui
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
/* TODO: Implement steps */
const NodeMapRange *map_range = static_cast<NodeMapRange *>(node_->storage);
@ -482,6 +483,7 @@ NODE_SHADER_MATERIALX_BEGIN
res.set_input("outhigh", to_max);
res.set_input("doclamp", val(bool(map_range->clamp)));
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -179,6 +179,7 @@ static void sh_node_math_build_multi_function(NodeMultiFunctionBuilder &builder)
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
CLG_LogRef *LOG_MATERIALX_SHADER = materialx::LOG_MATERIALX_SHADER;
/* TODO: finish some math operations */
@ -338,6 +339,7 @@ NODE_SHADER_MATERIALX_BEGIN
}
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -152,8 +152,10 @@ static void sh_node_mix_rgb_build_multi_function(NodeMultiFunctionBuilder &build
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
/* TODO: Implement */
return empty();
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -25,6 +25,7 @@ static int node_shader_gpu_mix_shader(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
NodeItem res = empty();
switch (to_type_) {
case NodeItem::Type::BSDF:
@ -59,6 +60,7 @@ NODE_SHADER_MATERIALX_BEGIN
BLI_assert_unreachable();
}
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -124,6 +124,7 @@ static int gpu_shader_normal_map(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
NodeShaderNormalMap *normal_map_node = static_cast<NodeShaderNormalMap *>(node_->storage);
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
NodeItem strength = get_input_value("Strength", NodeItem::Type::Float);
@ -151,6 +152,7 @@ NODE_SHADER_MATERIALX_BEGIN
res.set_input("scale", strength);
res.set_input("space", val(space));
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -45,6 +45,7 @@ static int node_shader_gpu_output_material(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
NodeItem bsdf = get_input_link("Surface", NodeItem::Type::BSDF);
NodeItem edf = get_input_link("Surface", NodeItem::Type::EDF);
NodeItem surface = empty();
@ -63,6 +64,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem res = create_node("surfacematerial", NodeItem::Type::Material);
res.set_input("surfaceshader", surface);
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -29,11 +29,13 @@ static int gpu_shader_rgbtobw(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
NodeItem color = get_input_value("Color", NodeItem::Type::Color4);
NodeItem res = create_node("luminance", NodeItem::Type::Color4);
res.set_input("in", color);
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -70,6 +70,7 @@ static int gpu_shader_sepcolor(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
int mode = static_cast<NodeCombSepColor *>(node_->storage)->mode;
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
@ -90,6 +91,7 @@ NODE_SHADER_MATERIALX_BEGIN
int index = STREQ(socket_out_->name, "Red") ? 0 : STREQ(socket_out_->name, "Green") ? 1 : 2;
return convert.extract(index);
#endif
}
NODE_SHADER_MATERIALX_END
@ -164,6 +166,7 @@ static int gpu_shader_combcolor(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
int mode = static_cast<NodeCombSepColor *>(node_->storage)->mode;
NodeItem red = get_input_value("Red", NodeItem::Type::Float);
NodeItem green = get_input_value("Green", NodeItem::Type::Float);
@ -189,6 +192,7 @@ NODE_SHADER_MATERIALX_BEGIN
BLI_assert_unreachable();
}
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -92,9 +92,11 @@ static void sh_node_sepxyz_build_multi_function(NodeMultiFunctionBuilder &builde
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
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);
#endif
}
NODE_SHADER_MATERIALX_END
@ -146,6 +148,7 @@ static void sh_node_combxyz_build_multi_function(NodeMultiFunctionBuilder &build
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
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);
@ -155,6 +158,7 @@ NODE_SHADER_MATERIALX_BEGIN
res.set_input("in2", y);
res.set_input("in3", z);
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -104,6 +104,7 @@ static void sh_node_tex_checker_build_multi_function(NodeMultiFunctionBuilder &b
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector2);
if (!vector) {
vector = texcoord_node();
@ -119,6 +120,7 @@ NODE_SHADER_MATERIALX_BEGIN
vector = (vector * scale) % val(2.0f);
return (vector.extract(0).floor() + vector.extract(1).floor())
.if_else(NodeItem::CompareOp::Eq, val(1.0f), value1, value2);
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -129,8 +129,10 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
/* TODO: Implement */
return empty();
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -178,6 +178,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
NodeItem res = val(MaterialX::Color4(1.0f, 0.0f, 1.0f, 1.0f));
Image *image = (Image *)node_->id;
@ -242,6 +243,7 @@ NODE_SHADER_MATERIALX_BEGIN
res = res.extract(3);
}
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -259,6 +259,7 @@ static void sh_node_noise_build_multi_function(NodeMultiFunctionBuilder &builder
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
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);
@ -273,6 +274,7 @@ NODE_SHADER_MATERIALX_BEGIN
}
res.set_input("lacunarity", lacunarity);
return res;
#endif
}
NODE_SHADER_MATERIALX_END

View File

@ -318,6 +318,7 @@ static void sh_node_vector_math_build_multi_function(NodeMultiFunctionBuilder &b
NODE_SHADER_MATERIALX_BEGIN
{
#ifdef WITH_MATERIALX
CLG_LogRef *LOG_MATERIALX_SHADER = materialx::LOG_MATERIALX_SHADER;
/* TODO: finish some math operations */
@ -428,6 +429,7 @@ NODE_SHADER_MATERIALX_BEGIN
}
return res;
#endif
}
NODE_SHADER_MATERIALX_END