forked from blender/blender
Move the MaterialX export code into the existing shader node files #18
@ -225,6 +225,9 @@ typedef int (*NodeGPUExecFunction)(struct GPUMaterial *mat,
|
||||
struct bNodeExecData *execdata,
|
||||
struct GPUNodeStack *in,
|
||||
struct GPUNodeStack *out);
|
||||
typedef void (*NodeMaterialXExecFunction)(void *data,
|
||||
struct bNode *node,
|
||||
struct bNodeSocket *out);
|
||||
|
||||
/**
|
||||
* \brief Defines a node type.
|
||||
@ -339,6 +342,8 @@ typedef struct bNodeType {
|
||||
NodeExecFunction exec_fn;
|
||||
/* gpu */
|
||||
NodeGPUExecFunction gpu_fn;
|
||||
/* MaterialX */
|
||||
NodeMaterialXExecFunction materialx_fn;
|
||||
|
||||
/* Get an instance of this node's compositor operation. Freeing the instance is the
|
||||
* responsibility of the caller. */
|
||||
|
@ -125,4 +125,37 @@ DECLARE_SHADER_NODE_PARSER(EmissionNodeParser)
|
||||
DECLARE_SHADER_NODE_PARSER(MixShaderNodeParser)
|
||||
DECLARE_SHADER_NODE_PARSER(SubsurfaceScatteringNodeParser)
|
||||
|
||||
|
||||
struct NodeParserData {
|
||||
MaterialX::GraphElement *graph;
|
||||
const Depsgraph *depsgraph;
|
||||
const Material *material;
|
||||
NodeItem result;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
void node_shader_materialx(void *data, struct bNode *node, struct bNodeSocket *out)
|
||||
{
|
||||
materialx::NodeParserData *d = reinterpret_cast<materialx::NodeParserData *>(data);
|
||||
T parser(d->graph, d->depsgraph, d->material, node, out);
|
||||
d->result = parser.compute();
|
||||
}
|
||||
|
||||
#define NODE_SHADER_MATERIALX_BEGIN \
|
||||
class MaterialXNodeParser : public materialx::NodeParser { \
|
||||
public: \
|
||||
using materialx::NodeParser::NodeParser; \
|
||||
materialx::NodeItem compute() override \
|
||||
{ \
|
||||
using NodeItem = materialx::NodeItem;
|
||||
|
||||
#define NODE_SHADER_MATERIALX_END \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
void node_shader_materialx(void *data, struct bNode *node, struct bNodeSocket *out) \
|
||||
{ \
|
||||
materialx::node_shader_materialx<MaterialXNodeParser>(data, node, out); \
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::materialx
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "BLI_string.h"
|
||||
|
||||
#include "node_shader_util.hh"
|
||||
#include "../materialx/nodes/node_parser.h"
|
||||
|
||||
#include "UI_interface.hh"
|
||||
#include "UI_resources.hh"
|
||||
@ -253,6 +254,12 @@ static void node_shader_update_principled(bNodeTree *ntree, bNode *node)
|
||||
}
|
||||
}
|
||||
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
{
|
||||
return empty();
|
||||
}
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
||||
} // namespace blender::nodes::node_shader_bsdf_principled_cc
|
||||
|
||||
/* node type definition */
|
||||
@ -270,6 +277,7 @@ void register_node_type_sh_bsdf_principled()
|
||||
ntype.initfunc = file_ns::node_shader_init_principled;
|
||||
ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_principled;
|
||||
ntype.updatefunc = file_ns::node_shader_update_principled;
|
||||
ntype.materialx_fn = file_ns::node_shader_materialx;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "node_shader_util.hh"
|
||||
#include "../materialx/nodes/node_parser.h"
|
||||
|
||||
#include "BKE_scene.h"
|
||||
|
||||
@ -43,6 +44,33 @@ static int node_shader_gpu_output_material(GPUMaterial *mat,
|
||||
return true;
|
||||
}
|
||||
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
NodeItem surface = empty();
|
||||
if (node_) {
|
||||
NodeItem bsdf = get_input_shader("Surface", NodeItem::Type::BSDF);
|
||||
NodeItem edf = get_input_shader("Surface", NodeItem::Type::EDF);
|
||||
if (bsdf || edf) {
|
||||
surface = create_node("surface", NodeItem::Type::SurfaceShader);
|
||||
if (bsdf) {
|
||||
surface.set_input("bsdf", bsdf);
|
||||
}
|
||||
if (edf) {
|
||||
surface.set_input("edf", edf);
|
||||
}
|
||||
}
|
||||
else {
|
||||
surface = get_input_shader("Surface", NodeItem::Type::SurfaceShader);
|
||||
}
|
||||
}
|
||||
else {
|
||||
surface = create_node("standard_surface", NodeItem::Type::SurfaceShader);
|
||||
surface.set_input("base_color", val(MaterialX::Color3(1.0f, 0.0f, 1.0f)));
|
||||
}
|
||||
NodeItem res = create_node("surfacematerial", NodeItem::Type::Material);
|
||||
res.set_input("surfaceshader", surface);
|
||||
return res;
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
||||
} // namespace blender::nodes::node_shader_output_material_cc
|
||||
|
||||
/* node type definition */
|
||||
@ -56,6 +84,7 @@ void register_node_type_sh_output_material()
|
||||
ntype.declare = file_ns::node_declare;
|
||||
ntype.add_ui_poll = object_shader_nodes_poll;
|
||||
ntype.gpu_fn = file_ns::node_shader_gpu_output_material;
|
||||
ntype.materialx_fn = file_ns::node_shader_materialx;
|
||||
|
||||
ntype.no_muting = true;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user