forked from blender/blender
Fix creating 2 <image> nodes in TexImage when Color and Output are connected #24
@ -100,7 +100,7 @@ NodeItem GroupOutputNodeParser::compute_full()
|
|||||||
res = compute();
|
res = compute();
|
||||||
return res;
|
return res;
|
||||||
#else
|
#else
|
||||||
return NodeParser::compute_full();
|
return compute();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ NodeItem GroupInputNodeParser::compute_full()
|
|||||||
res = compute();
|
res = compute();
|
||||||
return res;
|
return res;
|
||||||
#else
|
#else
|
||||||
return NodeParser::compute_full();
|
return compute();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
#include "IMB_colormanagement.h"
|
#include "IMB_colormanagement.h"
|
||||||
|
|
||||||
|
#include "hydra/image.h"
|
||||||
|
|
||||||
|
#include "DEG_depsgraph_query.h"
|
||||||
|
|
||||||
namespace blender::nodes::node_shader_tex_environment_cc {
|
namespace blender::nodes::node_shader_tex_environment_cc {
|
||||||
|
|
||||||
static void node_declare(NodeDeclarationBuilder &b)
|
static void node_declare(NodeDeclarationBuilder &b)
|
||||||
@ -130,8 +134,50 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat,
|
|||||||
NODE_SHADER_MATERIALX_BEGIN
|
NODE_SHADER_MATERIALX_BEGIN
|
||||||
#ifdef WITH_MATERIALX
|
#ifdef WITH_MATERIALX
|
||||||
{
|
{
|
||||||
/* TODO: Implement */
|
NodeItem res = val(MaterialX::Color4(1.0f, 0.0f, 1.0f, 1.0f));
|
||||||
return empty();
|
|
||||||
|
Image *image = (Image *)node_->id;
|
||||||
|
if (!image) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_env->iuser);
|
||||||
|
|
||||||
|
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector2);
|
||||||
|
if (!vector) {
|
||||||
|
vector = texcoord_node();
|
||||||
|
}
|
||||||
|
/* 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::Color4);
|
||||||
|
res.set_input("file", image_path, NodeItem::Type::Filename);
|
||||||
|
res.set_input("texcoord", vector);
|
||||||
|
res.set_input("filtertype", val(filtertype));
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
NODE_SHADER_MATERIALX_END
|
NODE_SHADER_MATERIALX_END
|
||||||
|
@ -179,64 +179,72 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat,
|
|||||||
NODE_SHADER_MATERIALX_BEGIN
|
NODE_SHADER_MATERIALX_BEGIN
|
||||||
#ifdef WITH_MATERIALX
|
#ifdef WITH_MATERIALX
|
||||||
{
|
{
|
||||||
NodeItem res = val(MaterialX::Color4(1.0f, 0.0f, 1.0f, 1.0f));
|
/* Getting node name for Color output. This name will be used for <image> node. */
|
||||||
|
std::string image_node_name = node_name();
|
||||||
|
image_node_name = image_node_name.substr(0, image_node_name.rfind('_')) + "_Color";
|
||||||
|
|
||||||
Image *image = (Image *)node_->id;
|
NodeItem res = empty();
|
||||||
if (image) {
|
res.node = graph_->getNode(image_node_name);
|
||||||
NodeTexImage *tex_image = static_cast<NodeTexImage *>(node_->storage);
|
if (!res.node) {
|
||||||
Scene *scene = DEG_get_input_scene(depsgraph_);
|
res = val(MaterialX::Color4(1.0f, 0.0f, 1.0f, 1.0f));
|
||||||
Main *bmain = DEG_get_bmain(depsgraph_);
|
|
||||||
|
|
||||||
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
|
Image *image = (Image *)node_->id;
|
||||||
* pretty general code, so could be moved from bf_usd project. */
|
if (image) {
|
||||||
std::string image_path = io::hydra::cache_or_get_image_file(
|
NodeTexImage *tex_image = static_cast<NodeTexImage *>(node_->storage);
|
||||||
bmain, scene, image, &tex_image->iuser);
|
Scene *scene = DEG_get_input_scene(depsgraph_);
|
||||||
|
Main *bmain = DEG_get_bmain(depsgraph_);
|
||||||
|
|
||||||
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector2);
|
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file
|
||||||
if (!vector) {
|
* contains pretty general code, so could be moved from bf_usd project. */
|
||||||
vector = texcoord_node();
|
std::string image_path = io::hydra::cache_or_get_image_file(
|
||||||
|
bmain, scene, image, &tex_image->iuser);
|
||||||
|
|
||||||
|
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", vector);
|
||||||
|
res.set_input("filtertype", val(filtertype));
|
||||||
|
res.set_input("uaddressmode", val(addressmode));
|
||||||
|
res.set_input("vaddressmode", val(addressmode));
|
||||||
}
|
}
|
||||||
/* 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", 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")) {
|
if (STREQ(socket_out_->name, "Alpha")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user