forked from blender/blender
Add basic supported nodes #1
@ -141,11 +141,13 @@ if(WITH_MATERIALX)
|
|||||||
materialx/nodes/node.cc
|
materialx/nodes/node.cc
|
||||||
materialx/nodes/material_output.cc
|
materialx/nodes/material_output.cc
|
||||||
materialx/nodes/principled_bsdf.cc
|
materialx/nodes/principled_bsdf.cc
|
||||||
|
materialx/nodes/image.cc
|
||||||
|
|
||||||
materialx/material.h
|
materialx/material.h
|
||||||
materialx/nodes/node.h
|
materialx/nodes/node.h
|
||||||
materialx/nodes/material_output.h
|
materialx/nodes/material_output.h
|
||||||
materialx/nodes/principled_bsdf.h
|
materialx/nodes/principled_bsdf.h
|
||||||
|
materialx/nodes/image.h
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
static void export_nodegraph(MaterialX::DocumentPtr doc, Material *material)
|
static void export_nodegraph(MaterialX::DocumentPtr doc, Depsgraph *depsgraph, Material *material)
|
||||||
{
|
{
|
||||||
material->nodetree->ensure_topology_cache();
|
material->nodetree->ensure_topology_cache();
|
||||||
|
|
||||||
bNode *output_node = ntreeShaderOutputNode(material->nodetree, SHD_OUTPUT_ALL);
|
bNode *output_node = ntreeShaderOutputNode(material->nodetree, SHD_OUTPUT_ALL);
|
||||||
MaterialXMaterialOutputNode material_node(doc, material, output_node);
|
MaterialXMaterialOutputNode material_node(doc, depsgraph, material, output_node);
|
||||||
material_node.convert();
|
material_node.convert();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,11 +35,11 @@ static void create_standard_surface(MaterialX::DocumentPtr doc, Material *materi
|
|||||||
->setNodeName(standard_surface->getName());
|
->setNodeName(standard_surface->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialX::DocumentPtr export_to_materialx(Material *material)
|
MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *material)
|
||||||
{
|
{
|
||||||
MaterialX::DocumentPtr doc = MaterialX::createDocument();
|
MaterialX::DocumentPtr doc = MaterialX::createDocument();
|
||||||
if (material->use_nodes) {
|
if (material->use_nodes) {
|
||||||
export_nodegraph(doc, material);
|
export_nodegraph(doc, depsgraph, material);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
create_standard_surface(doc, material);
|
create_standard_surface(doc, material);
|
||||||
|
@ -6,10 +6,11 @@
|
|||||||
|
|
||||||
#include <MaterialXCore/Document.h>
|
#include <MaterialXCore/Document.h>
|
||||||
|
|
||||||
|
#include "DEG_depsgraph.h"
|
||||||
#include "DNA_material_types.h"
|
#include "DNA_material_types.h"
|
||||||
|
|
||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
MaterialX::DocumentPtr export_to_materialx(Material *material);
|
MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *material);
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
41
source/blender/nodes/shader/materialx/nodes/image.cc
Normal file
41
source/blender/nodes/shader/materialx/nodes/image.cc
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
|
||||||
|
#include "node.h"
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
|
#include "DEG_depsgraph_query.h"
|
||||||
|
|
||||||
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
|
const MaterialX::Color3 MaterialXTexImageNode::texture_error_color_{1.0, 0.0, 1.0};
|
||||||
|
|
||||||
|
MaterialXTexImageNode::MaterialXTexImageNode(MaterialX::DocumentPtr doc,
|
||||||
|
const Depsgraph *depsgraph,
|
||||||
|
const Material *material,
|
||||||
|
const bNode *node)
|
||||||
|
: MaterialXNode(doc, depsgraph, material, node)
|
||||||
|
{
|
||||||
|
matx_node = doc->addNode("image", node->name, "color3");
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialX::NodePtr MaterialXTexImageNode::convert()
|
||||||
|
{
|
||||||
|
const Image *image = (Image *)node->id;
|
||||||
|
const NodeTexImage *tex = static_cast<NodeTexImage *>(node->storage);
|
||||||
|
Scene *scene = DEG_get_input_scene(depsgraph);
|
||||||
|
Main *bmain = DEG_get_bmain(depsgraph);
|
||||||
|
std::string image_path;
|
||||||
|
#ifdef WITH_HYDRA
|
||||||
|
image_path = cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
||||||
|
#endif
|
||||||
|
MaterialX::NodePtr uv_node = doc->addNode("texcoord", MaterialX::EMPTY_STRING, "vector2");
|
||||||
|
|
||||||
|
matx_node->addInput("file", "filename")->setValue(image_path);
|
||||||
|
matx_node->addInput("texcoord", "vector2")->setNodeName(uv_node->getName());
|
||||||
|
|
||||||
|
return matx_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace blender::nodes::materialx
|
24
source/blender/nodes/shader/materialx/nodes/image.h
Normal file
24
source/blender/nodes/shader/materialx/nodes/image.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
|
class MaterialXTexImageNode : public MaterialXNode {
|
||||||
|
protected:
|
||||||
|
/* Following Cycles color for wrong Texture nodes. */
|
||||||
|
static const MaterialX::Color3 texture_error_color_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MaterialXTexImageNode(MaterialX::DocumentPtr doc,
|
||||||
|
const Depsgraph *depsgraph,
|
||||||
|
const Material *material,
|
||||||
|
const bNode *node);
|
||||||
|
MaterialX::NodePtr convert() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace blender::nodes::materialx
|
@ -8,9 +8,10 @@
|
|||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
MaterialXMaterialOutputNode::MaterialXMaterialOutputNode(MaterialX::DocumentPtr doc,
|
MaterialXMaterialOutputNode::MaterialXMaterialOutputNode(MaterialX::DocumentPtr doc,
|
||||||
|
const Depsgraph *depsgraph,
|
||||||
const Material *material,
|
const Material *material,
|
||||||
const bNode *node)
|
const bNode *node)
|
||||||
: MaterialXNode(doc, material, node)
|
: MaterialXNode(doc, depsgraph, material, node)
|
||||||
{
|
{
|
||||||
matx_node = doc->addNode("surfacematerial", node->name, "material");
|
matx_node = doc->addNode("surfacematerial", node->name, "material");
|
||||||
}
|
}
|
||||||
@ -23,7 +24,7 @@ MaterialX::NodePtr MaterialXMaterialOutputNode::convert()
|
|||||||
}
|
}
|
||||||
if (STREQ(sock->name, "Surface")) {
|
if (STREQ(sock->name, "Surface")) {
|
||||||
const bNode *inode = sock->link->fromnode;
|
const bNode *inode = sock->link->fromnode;
|
||||||
MaterialXPrincipledBSDFNode surface_node(doc, material, inode);
|
MaterialXPrincipledBSDFNode surface_node(doc, depsgraph, material, inode);
|
||||||
surface_node.convert();
|
surface_node.convert();
|
||||||
matx_node->addInput("surfaceshader", "surfaceshader")->setNodeName(inode->name);
|
matx_node->addInput("surfaceshader", "surfaceshader")->setNodeName(inode->name);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ namespace blender::nodes::materialx {
|
|||||||
class MaterialXMaterialOutputNode : public MaterialXNode {
|
class MaterialXMaterialOutputNode : public MaterialXNode {
|
||||||
public:
|
public:
|
||||||
MaterialXMaterialOutputNode(MaterialX::DocumentPtr doc,
|
MaterialXMaterialOutputNode(MaterialX::DocumentPtr doc,
|
||||||
|
const Depsgraph *depsgraph,
|
||||||
const Material *material,
|
const Material *material,
|
||||||
const bNode *node);
|
const bNode *node);
|
||||||
MaterialX::NodePtr convert() override;
|
MaterialX::NodePtr convert() override;
|
||||||
|
@ -7,9 +7,10 @@
|
|||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
MaterialXNode::MaterialXNode(MaterialX::DocumentPtr doc,
|
MaterialXNode::MaterialXNode(MaterialX::DocumentPtr doc,
|
||||||
|
const Depsgraph *depsgraph,
|
||||||
const Material *material,
|
const Material *material,
|
||||||
const bNode *node)
|
const bNode *node)
|
||||||
: material(material), node(node), doc(doc)
|
: depsgraph(depsgraph), material(material), node(node), doc(doc)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <MaterialXCore/Document.h>
|
#include <MaterialXCore/Document.h>
|
||||||
|
|
||||||
|
#include "DEG_depsgraph.h"
|
||||||
#include "DNA_material_types.h"
|
#include "DNA_material_types.h"
|
||||||
#include "DNA_node_types.h"
|
#include "DNA_node_types.h"
|
||||||
|
|
||||||
@ -13,13 +14,17 @@ namespace blender::nodes::materialx {
|
|||||||
|
|
||||||
class MaterialXNode {
|
class MaterialXNode {
|
||||||
public:
|
public:
|
||||||
const Material *material;
|
const Depsgraph *depsgraph = nullptr;
|
||||||
const bNode *node;
|
const Material *material = nullptr;
|
||||||
|
const bNode *node = nullptr;
|
||||||
MaterialX::NodePtr matx_node;
|
MaterialX::NodePtr matx_node;
|
||||||
MaterialX::DocumentPtr doc;
|
MaterialX::DocumentPtr doc;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MaterialXNode(MaterialX::DocumentPtr doc, const Material *material, const bNode *node);
|
MaterialXNode(MaterialX::DocumentPtr doc,
|
||||||
|
const Depsgraph *depsgraph,
|
||||||
|
const Material *material,
|
||||||
|
const bNode *node);
|
||||||
virtual ~MaterialXNode() = default;
|
virtual ~MaterialXNode() = default;
|
||||||
|
|
||||||
virtual MaterialX::NodePtr convert() = 0;
|
virtual MaterialX::NodePtr convert() = 0;
|
||||||
|
@ -8,17 +8,19 @@
|
|||||||
|
|
||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
|
const MaterialX::Color3 MaterialXPrincipledBSDFNode::default_white_color_{1.0, 1.0, 1.0};
|
||||||
|
|
||||||
MaterialXPrincipledBSDFNode::MaterialXPrincipledBSDFNode(MaterialX::DocumentPtr doc,
|
MaterialXPrincipledBSDFNode::MaterialXPrincipledBSDFNode(MaterialX::DocumentPtr doc,
|
||||||
|
const Depsgraph *depsgraph,
|
||||||
const Material *material,
|
const Material *material,
|
||||||
const bNode *node)
|
const bNode *node)
|
||||||
: MaterialXNode(doc, material, node)
|
: MaterialXNode(doc, depsgraph, material, node)
|
||||||
{
|
{
|
||||||
matx_node = doc->addNode("standard_surface", node->name, "surfaceshader");
|
matx_node = doc->addNode("standard_surface", node->name, "surfaceshader");
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialX::NodePtr MaterialXPrincipledBSDFNode::convert()
|
MaterialX::NodePtr MaterialXPrincipledBSDFNode::convert()
|
||||||
{
|
{
|
||||||
MaterialX::Color3 default_white_color = MaterialX::Color3(1.0, 1.0, 1.0);
|
|
||||||
#pragma region get inputs
|
#pragma region get inputs
|
||||||
const float *base_color =
|
const float *base_color =
|
||||||
node->input_by_identifier("Base Color").default_value_typed<bNodeSocketValueRGBA>()->value;
|
node->input_by_identifier("Base Color").default_value_typed<bNodeSocketValueRGBA>()->value;
|
||||||
@ -81,14 +83,14 @@ MaterialX::NodePtr MaterialXPrincipledBSDFNode::convert()
|
|||||||
matx_node->addInput("metalness", "float")->setValue(metallic);
|
matx_node->addInput("metalness", "float")->setValue(metallic);
|
||||||
|
|
||||||
matx_node->addInput("specular", "float")->setValue(specular);
|
matx_node->addInput("specular", "float")->setValue(specular);
|
||||||
matx_node->addInput("specular_color", "color3")->setValue(default_white_color);
|
matx_node->addInput("specular_color", "color3")->setValue(default_white_color_);
|
||||||
matx_node->addInput("specular_roughness", "float")->setValue(roughness);
|
matx_node->addInput("specular_roughness", "float")->setValue(roughness);
|
||||||
matx_node->addInput("specular_IOR", "float")->setValue(IOR);
|
matx_node->addInput("specular_IOR", "float")->setValue(IOR);
|
||||||
matx_node->addInput("specular_anisotropy", "float")->setValue(anisotropic);
|
matx_node->addInput("specular_anisotropy", "float")->setValue(anisotropic);
|
||||||
matx_node->addInput("specular_rotation", "float")->setValue(anisotropic_rot);
|
matx_node->addInput("specular_rotation", "float")->setValue(anisotropic_rot);
|
||||||
|
|
||||||
matx_node->addInput("transmission", "float")->setValue(transmission);
|
matx_node->addInput("transmission", "float")->setValue(transmission);
|
||||||
matx_node->addInput("transmission_color", "color3")->setValue(default_white_color);
|
matx_node->addInput("transmission_color", "color3")->setValue(default_white_color_);
|
||||||
matx_node->addInput("transmission_extra_roughness", "float")->setValue(roughness);
|
matx_node->addInput("transmission_extra_roughness", "float")->setValue(roughness);
|
||||||
|
|
||||||
matx_node->addInput("subsurface", "float")->setValue(subsurface);
|
matx_node->addInput("subsurface", "float")->setValue(subsurface);
|
||||||
@ -100,11 +102,11 @@ MaterialX::NodePtr MaterialXPrincipledBSDFNode::convert()
|
|||||||
matx_node->addInput("subsurface_anisotropy", "float")->setValue(anisotropic);
|
matx_node->addInput("subsurface_anisotropy", "float")->setValue(anisotropic);
|
||||||
|
|
||||||
matx_node->addInput("sheen", "float")->setValue(sheen);
|
matx_node->addInput("sheen", "float")->setValue(sheen);
|
||||||
matx_node->addInput("sheen_color", "color3")->setValue(default_white_color);
|
matx_node->addInput("sheen_color", "color3")->setValue(default_white_color_);
|
||||||
matx_node->addInput("sheen_roughness", "float")->setValue(roughness);
|
matx_node->addInput("sheen_roughness", "float")->setValue(roughness);
|
||||||
|
|
||||||
matx_node->addInput("coat", "float")->setValue(clearcoat);
|
matx_node->addInput("coat", "float")->setValue(clearcoat);
|
||||||
matx_node->addInput("coat_color", "color3")->setValue(default_white_color);
|
matx_node->addInput("coat_color", "color3")->setValue(default_white_color_);
|
||||||
matx_node->addInput("coat_roughness", "float")->setValue(clearcoat_roughness);
|
matx_node->addInput("coat_roughness", "float")->setValue(clearcoat_roughness);
|
||||||
matx_node->addInput("coat_IOR", "float")->setValue(IOR);
|
matx_node->addInput("coat_IOR", "float")->setValue(IOR);
|
||||||
matx_node->addInput("coat_anisotropy", "float")->setValue(anisotropic);
|
matx_node->addInput("coat_anisotropy", "float")->setValue(anisotropic);
|
||||||
|
@ -9,8 +9,12 @@
|
|||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
class MaterialXPrincipledBSDFNode : public MaterialXNode {
|
class MaterialXPrincipledBSDFNode : public MaterialXNode {
|
||||||
|
protected:
|
||||||
|
static const MaterialX::Color3 default_white_color_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MaterialXPrincipledBSDFNode(MaterialX::DocumentPtr doc,
|
MaterialXPrincipledBSDFNode(MaterialX::DocumentPtr doc,
|
||||||
|
const Depsgraph *depsgraph,
|
||||||
const Material *material,
|
const Material *material,
|
||||||
const bNode *node);
|
const bNode *node);
|
||||||
MaterialX::NodePtr convert() override;
|
MaterialX::NodePtr convert() override;
|
||||||
|
Loading…
Reference in New Issue
Block a user