forked from blender/blender
Export other channels and parameters from texture nodes #16
@ -346,15 +346,6 @@ NodeItem NodeItem::exp() const
|
||||
return arithmetic("exp", [](float a) { return std::expf(a); });
|
||||
}
|
||||
|
||||
NodeItem NodeItem::extract(const int index) const
|
||||
{
|
||||
NodeItem res = empty();
|
||||
res = create_node("extract", Type::Float);
|
||||
res.set_input("in", *this);
|
||||
res.set_input("index", val(index));
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem NodeItem::convert(Type to_type) const
|
||||
{
|
||||
Type from_type = type();
|
||||
@ -600,6 +591,15 @@ NodeItem NodeItem::if_else(CompareOp op,
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem NodeItem::extract(const int index) const
|
||||
{
|
||||
NodeItem res = empty();
|
||||
res = create_node("extract", Type::Float);
|
||||
res.set_input("in", *this);
|
||||
res.set_input("index", val(index));
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem NodeItem::empty() const
|
||||
{
|
||||
return NodeItem(graph_);
|
||||
|
@ -121,4 +121,6 @@ DECLARE_SHADER_NODE_PARSER(EmissionNodeParser)
|
||||
DECLARE_SHADER_NODE_PARSER(MixShaderNodeParser)
|
||||
DECLARE_SHADER_NODE_PARSER(SubsurfaceScatteringNodeParser)
|
||||
|
||||
extern const MaterialX::Color4 TEX_ERROR_COLOR;
|
||||
|
||||
} // namespace blender::nodes::materialx
|
||||
|
@ -12,31 +12,48 @@ namespace blender::nodes::materialx {
|
||||
|
||||
NodeItem TexEnvironmentNodeParser::compute()
|
||||
{
|
||||
NodeItem res = val(MaterialX::Color4(1.0f, 0.0f, 1.0f, 1.0f));
|
||||
NodeItem res = val(TEX_ERROR_COLOR);
|
||||
|
||||
Image *image = (Image *)node_->id;
|
||||
if (!image) {
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeTexEnvironment *tex = static_cast<NodeTexEnvironment *>(node_->storage);
|
||||
NodeTexEnvironment *tex_env = static_cast<NodeTexEnvironment *>(node_->storage);
|
||||
Scene *scene = DEG_get_input_scene(depsgraph_);
|
||||
Main *bmain = DEG_get_bmain(depsgraph_);
|
||||
|
||||
/* 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. */
|
||||
std::string 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_env->iuser);
|
||||
|
||||
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector2);
|
||||
if (!vector) {
|
||||
vector = texcoord_node();
|
||||
}
|
||||
/* TODO: fix texcoord of environment texture, some math should be applied */
|
||||
/* TODO: texcoords should be translated to spherical coordinates */
|
||||
|
||||
std::string filtertype;
|
||||
switch (tex_env->interpolation) {
|
||||
case SHD_INTERP_LINEAR:
|
||||
filtertype = "linear";
|
||||
break;
|
||||
case SHD_INTERP_CLOSEST:
|
||||
filtertype = "closest";
|
||||
break;
|
||||
case SHD_INTERP_CUBIC:
|
||||
case SHD_INTERP_SMART:
|
||||
filtertype = "cubic";
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
res = create_node("image", NodeItem::Type::Color3);
|
||||
res.set_input("file", image_path, NodeItem::Type::Filename);
|
||||
res.set_input("texcoord", vector);
|
||||
/* TODO: get other Tex environment node parameters */
|
||||
res.set_input("filtertype", val(filtertype));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -10,9 +10,11 @@
|
||||
|
||||
namespace blender::nodes::materialx {
|
||||
|
||||
const MaterialX::Color4 TEX_ERROR_COLOR(1.0f, 0.0f, 1.0f, 1.0f);
|
||||
|
||||
NodeItem TexImageNodeParser::compute()
|
||||
{
|
||||
NodeItem res = val(MaterialX::Color4(1.0f, 0.0f, 1.0f, 1.0f));
|
||||
NodeItem res = val(TEX_ERROR_COLOR);
|
||||
|
||||
Image *image = (Image *)node_->id;
|
||||
if (image) {
|
||||
@ -25,15 +27,51 @@ NodeItem TexImageNodeParser::compute()
|
||||
std::string image_path = io::hydra::cache_or_get_image_file(
|
||||
bmain, scene, image, &tex_image->iuser);
|
||||
|
||||
NodeItem texcoord = get_input_link("Vector", NodeItem::Type::Vector2);
|
||||
if (!texcoord) {
|
||||
texcoord = texcoord_node();
|
||||
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector2);
|
||||
if (!vector) {
|
||||
vector = texcoord_node();
|
||||
}
|
||||
/* TODO: add math to vector depending of tex_image->projection */
|
||||
|
||||
std::string filtertype;
|
||||
switch (tex_image->interpolation) {
|
||||
case SHD_INTERP_LINEAR:
|
||||
filtertype = "linear";
|
||||
break;
|
||||
case SHD_INTERP_CLOSEST:
|
||||
filtertype = "closest";
|
||||
break;
|
||||
case SHD_INTERP_CUBIC:
|
||||
case SHD_INTERP_SMART:
|
||||
filtertype = "cubic";
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
std::string addressmode;
|
||||
switch (tex_image->extension) {
|
||||
case SHD_IMAGE_EXTENSION_REPEAT:
|
||||
addressmode = "periodic";
|
||||
break;
|
||||
case SHD_IMAGE_EXTENSION_EXTEND:
|
||||
addressmode = "clamp";
|
||||
break;
|
||||
case SHD_IMAGE_EXTENSION_CLIP:
|
||||
addressmode = "constant";
|
||||
break;
|
||||
case SHD_IMAGE_EXTENSION_MIRROR:
|
||||
addressmode = "mirror";
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
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 */
|
||||
res.set_input("texcoord", vector);
|
||||
res.set_input("filtertype", val(filtertype));
|
||||
res.set_input("uaddressmode", val(addressmode));
|
||||
res.set_input("vaddressmode", val(addressmode));
|
||||
}
|
||||
|
||||
if (STREQ(socket_out_->name, "Alpha")) {
|
||||
|
Loading…
Reference in New Issue
Block a user