forked from blender/blender
Export other channels and parameters from texture nodes #16
@ -10,11 +10,13 @@ namespace blender::nodes::materialx {
|
|||||||
NodeItem MathNodeParser::compute()
|
NodeItem MathNodeParser::compute()
|
||||||
{
|
{
|
||||||
/* TODO: finish some math operations */
|
/* TODO: finish some math operations */
|
||||||
auto op = node_->custom1;
|
NodeMathOperation op = NodeMathOperation(node_->custom1);
|
||||||
NodeItem res = empty();
|
NodeItem res = empty();
|
||||||
|
|
||||||
/* Single operand operations */
|
/* Single operand operations */
|
||||||
NodeItem x = get_input_value(0, NodeItem::Type::Any);
|
NodeItem x = get_input_value(0, NodeItem::Type::Float);
|
||||||
|
/* TODO: Seems we have to use average if Vector or Color are added */
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case NODE_MATH_SINE:
|
case NODE_MATH_SINE:
|
||||||
res = x.sin();
|
res = x.sin();
|
||||||
@ -82,7 +84,7 @@ NodeItem MathNodeParser::compute()
|
|||||||
|
|
||||||
default: {
|
default: {
|
||||||
/* 2-operand operations */
|
/* 2-operand operations */
|
||||||
NodeItem y = get_input_value(1, NodeItem::Type::Any);
|
NodeItem y = get_input_value(1, NodeItem::Type::Float);
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case NODE_MATH_ADD:
|
case NODE_MATH_ADD:
|
||||||
res = x + y;
|
res = x + y;
|
||||||
@ -132,7 +134,7 @@ NodeItem MathNodeParser::compute()
|
|||||||
|
|
||||||
default: {
|
default: {
|
||||||
/* 3-operand operations */
|
/* 3-operand operations */
|
||||||
NodeItem z = get_input_value(2, NodeItem::Type::Any);
|
NodeItem z = get_input_value(2, NodeItem::Type::Float);
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case NODE_MATH_WRAP:
|
case NODE_MATH_WRAP:
|
||||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||||
|
@ -9,21 +9,20 @@ namespace blender::nodes::materialx {
|
|||||||
NodeItem TexCheckerNodeParser::compute()
|
NodeItem TexCheckerNodeParser::compute()
|
||||||
{
|
{
|
||||||
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector2);
|
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector2);
|
||||||
NodeItem color1 = get_input_value("Color1", NodeItem::Type::Color3);
|
|
||||||
NodeItem color2 = get_input_value("Color2", NodeItem::Type::Color3);
|
|
||||||
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
|
|
||||||
|
|
||||||
if (!vector) {
|
if (!vector) {
|
||||||
vector = texcoord_node();
|
vector = texcoord_node();
|
||||||
}
|
}
|
||||||
|
NodeItem value1 = val(1.0f);
|
||||||
|
NodeItem value2 = val(0.0f);
|
||||||
|
if (STREQ(socket_out_->name, "Color")) {
|
||||||
|
value1 = get_input_value("Color1", NodeItem::Type::Color3);
|
||||||
|
value2 = get_input_value("Color2", NodeItem::Type::Color3);
|
||||||
|
}
|
||||||
|
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
|
||||||
|
|
||||||
vector = (vector * scale) % val(2.0f);
|
vector = (vector * scale) % val(2.0f);
|
||||||
NodeItem mix = (vector.extract(0).floor() + vector.extract(1).floor())
|
return (vector.extract(0).floor() + vector.extract(1).floor())
|
||||||
.if_else(NodeItem::CompareOp::Eq, val(1.0f), val(1.0f), val(0.0f));
|
.if_else(NodeItem::CompareOp::Eq, val(1.0f), value1, value2);
|
||||||
NodeItem res = create_node("mix", NodeItem::Type::Color3);
|
|
||||||
res.set_input("fg", color1);
|
|
||||||
res.set_input("bg", color2);
|
|
||||||
res.set_input("mix", mix);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::nodes::materialx
|
} // namespace blender::nodes::materialx
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
#include "node_parser.h"
|
#include "node_parser.h"
|
||||||
|
|
||||||
#ifdef WITH_HYDRA
|
|
||||||
#include "hydra/image.h"
|
#include "hydra/image.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "DEG_depsgraph_query.h"
|
#include "DEG_depsgraph_query.h"
|
||||||
|
|
||||||
@ -14,22 +12,32 @@ namespace blender::nodes::materialx {
|
|||||||
|
|
||||||
NodeItem TexEnvironmentNodeParser::compute()
|
NodeItem TexEnvironmentNodeParser::compute()
|
||||||
{
|
{
|
||||||
|
NodeItem res = val(MaterialX::Color4(1.0f, 0.0f, 1.0f, 1.0f));
|
||||||
|
|
||||||
Image *image = (Image *)node_->id;
|
Image *image = (Image *)node_->id;
|
||||||
|
if (!image) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
NodeTexEnvironment *tex = static_cast<NodeTexEnvironment *>(node_->storage);
|
NodeTexEnvironment *tex = static_cast<NodeTexEnvironment *>(node_->storage);
|
||||||
Scene *scene = DEG_get_input_scene(depsgraph_);
|
Scene *scene = DEG_get_input_scene(depsgraph_);
|
||||||
Main *bmain = DEG_get_bmain(depsgraph_);
|
Main *bmain = DEG_get_bmain(depsgraph_);
|
||||||
std::string image_path;
|
|
||||||
|
|
||||||
#ifdef WITH_HYDRA
|
|
||||||
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
|
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
|
||||||
* pretty general code, so could be moved from bf_usd project. */
|
* pretty general code, so could be moved from bf_usd project. */
|
||||||
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
std::string image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
||||||
#endif
|
|
||||||
|
|
||||||
NodeItem texcoord = texcoord_node();
|
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector2);
|
||||||
NodeItem res = create_node("image", NodeItem::Type::Color3);
|
if (!vector) {
|
||||||
|
vector = texcoord_node();
|
||||||
|
}
|
||||||
|
/* TODO: fix texcoord of environment texture, some math should be applied */
|
||||||
|
|
||||||
|
res = create_node("image", NodeItem::Type::Color3);
|
||||||
res.set_input("file", image_path, NodeItem::Type::Filename);
|
res.set_input("file", image_path, NodeItem::Type::Filename);
|
||||||
res.set_input("texcoord", texcoord);
|
res.set_input("texcoord", vector);
|
||||||
|
/* TODO: get other Tex environment node parameters */
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
#include "node_parser.h"
|
#include "node_parser.h"
|
||||||
|
|
||||||
#ifdef WITH_HYDRA
|
#include "hydra/image.h"
|
||||||
# include "hydra/image.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "DEG_depsgraph_query.h"
|
#include "DEG_depsgraph_query.h"
|
||||||
|
|
||||||
@ -14,22 +12,33 @@ namespace blender::nodes::materialx {
|
|||||||
|
|
||||||
NodeItem TexImageNodeParser::compute()
|
NodeItem TexImageNodeParser::compute()
|
||||||
{
|
{
|
||||||
|
NodeItem res = val(MaterialX::Color4(1.0f, 0.0f, 1.0f, 1.0f));
|
||||||
|
|
||||||
Image *image = (Image *)node_->id;
|
Image *image = (Image *)node_->id;
|
||||||
NodeTexImage *tex = static_cast<NodeTexImage *>(node_->storage);
|
if (image) {
|
||||||
Scene *scene = DEG_get_input_scene(depsgraph_);
|
NodeTexImage *tex_image = static_cast<NodeTexImage *>(node_->storage);
|
||||||
Main *bmain = DEG_get_bmain(depsgraph_);
|
Scene *scene = DEG_get_input_scene(depsgraph_);
|
||||||
std::string image_path;
|
Main *bmain = DEG_get_bmain(depsgraph_);
|
||||||
|
|
||||||
#ifdef WITH_HYDRA
|
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
|
||||||
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
|
* pretty general code, so could be moved from bf_usd project. */
|
||||||
* pretty general code, so could be moved from bf_usd project. */
|
std::string image_path = io::hydra::cache_or_get_image_file(
|
||||||
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
|
bmain, scene, image, &tex_image->iuser);
|
||||||
#endif
|
|
||||||
|
|
||||||
NodeItem texcoord = texcoord_node();
|
NodeItem texcoord = get_input_link("Vector", NodeItem::Type::Vector2);
|
||||||
NodeItem res = create_node("image", NodeItem::Type::Color3);
|
if (!texcoord) {
|
||||||
res.set_input("file", image_path, NodeItem::Type::Filename);
|
texcoord = texcoord_node();
|
||||||
res.set_input("texcoord", texcoord);
|
}
|
||||||
|
|
||||||
|
res = create_node("image", NodeItem::Type::Color4);
|
||||||
|
res.set_input("file", image_path, NodeItem::Type::Filename);
|
||||||
|
res.set_input("texcoord", texcoord);
|
||||||
|
/* TODO: get other Tex image node parameters */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STREQ(socket_out_->name, "Alpha")) {
|
||||||
|
res = res.extract(3);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user