[Bf-blender-cvs] [9514191] openvdb: Cycles: add support for transforming the grid (pos, rot, scale).
Kévin Dietrich
noreply at git.blender.org
Fri Jun 5 14:07:09 CEST 2015
Commit: 9514191b0cd63457f6f15d3eb7362651a57f1fec
Author: Kévin Dietrich
Date: Tue May 19 14:29:48 2015 +0200
Branches: openvdb
https://developer.blender.org/rB9514191b0cd63457f6f15d3eb7362651a57f1fec
Cycles: add support for transforming the grid (pos, rot, scale).
This makes it easier to incorporate external VDB files in the Cycles
scene (at least in Blender).
===================================================================
M intern/cycles/kernel/svm/svm.h
M intern/cycles/kernel/svm/svm_openvdb.h
M intern/cycles/render/nodes.cpp
M intern/cycles/render/nodes.h
M source/blender/nodes/shader/nodes/node_shader_openvdb.c
===================================================================
diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h
index 864cd05..4a49154 100644
--- a/intern/cycles/kernel/svm/svm.h
+++ b/intern/cycles/kernel/svm/svm.h
@@ -438,7 +438,7 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, Shade
break;
#ifdef __OPENVDB__
case NODE_OPENVDB:
- svm_node_openvdb(kg, sd, stack, node);
+ svm_node_openvdb(kg, sd, stack, node, &offset);
break;
#endif
case NODE_END:
diff --git a/intern/cycles/kernel/svm/svm_openvdb.h b/intern/cycles/kernel/svm/svm_openvdb.h
index c82bcb7..ee41eb9 100644
--- a/intern/cycles/kernel/svm/svm_openvdb.h
+++ b/intern/cycles/kernel/svm/svm_openvdb.h
@@ -18,11 +18,20 @@ CCL_NAMESPACE_BEGIN
#ifdef __OPENVDB__
-ccl_device void svm_node_openvdb(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
+ccl_device void svm_node_openvdb(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
{
- float3 co = ccl_fetch(sd, P);
- uint type, out_offset, sampling, slot;
- decode_node_uchar4(node.y, &slot, &type, &out_offset, &sampling);
+ uint slot = node.y;
+ uint type, out_offset, sampling, co_offset;
+ decode_node_uchar4(node.z, &type, &co_offset, &out_offset, &sampling);
+
+ float3 co = stack_load_float3(stack, co_offset);
+
+ Transform tfm;
+ tfm.x = read_node_float(kg, offset);
+ tfm.y = read_node_float(kg, offset);
+ tfm.z = read_node_float(kg, offset);
+ tfm.w = read_node_float(kg, offset);
+ co = transform_point(&tfm, co);
#ifdef __KERNEL_GPU__
float3 out = make_float3(0.0f, 0.0f, 0.0f);
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 627cc2b..5b7b08b 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -4376,17 +4376,27 @@ OpenVDBNode::OpenVDBNode()
#else
sampling = 0;
#endif
+
+ tfm = transform_identity();
+
+ add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::POSITION);
}
void OpenVDBNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
+ if(shader->has_volume)
+ attributes->add(ATTR_STD_GENERATED_TRANSFORM);
+
ShaderNode::attributes(shader, attributes);
}
void OpenVDBNode::compile(SVMCompiler &compiler)
{
+ ShaderInput *vector_in = input("Vector");
vdb_manager = compiler.vdb_manager;
+ compiler.stack_assign(vector_in);
+
for(size_t i = 0; i < outputs.size(); ++i) {
ShaderOutput *out = outputs[i];
@@ -4400,12 +4410,23 @@ void OpenVDBNode::compile(SVMCompiler &compiler)
type = NODE_VDB_VEC3S;
}
- grid_slot = vdb_manager->add_volume(filename.string(), output_names[i].string(), sampling, type);
+ grid_slot = vdb_manager->add_volume(filename.string(),
+ output_names[i].string(),
+ sampling, type);
compiler.stack_assign(out);
compiler.add_node(NODE_OPENVDB,
- compiler.encode_uchar4(grid_slot, type, out->stack_offset, sampling));
+ grid_slot,
+ compiler.encode_uchar4(type,
+ vector_in->stack_offset,
+ out->stack_offset,
+ sampling));
+
+ compiler.add_node(tfm.x);
+ compiler.add_node(tfm.y);
+ compiler.add_node(tfm.z);
+ compiler.add_node(tfm.w);
}
}
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 250ade9..22fd898 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -677,6 +677,9 @@ public:
int grid_slot;
int sampling;
vector<ustring> output_names;
+
+ Transform tfm;
+ TextureMapping tex_mapping;
};
CCL_NAMESPACE_END
diff --git a/source/blender/nodes/shader/nodes/node_shader_openvdb.c b/source/blender/nodes/shader/nodes/node_shader_openvdb.c
index b24258a..23379a2 100644
--- a/source/blender/nodes/shader/nodes/node_shader_openvdb.c
+++ b/source/blender/nodes/shader/nodes/node_shader_openvdb.c
@@ -29,6 +29,11 @@
#include "openvdb_capi.h"
+static bNodeSocketTemplate sh_node_openvdb_in[] = {
+ {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
+ {-1, 0, ""}
+};
+
static void node_shader_init_openvdb(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeShaderOpenVDB *vdb = MEM_callocN(sizeof(NodeShaderOpenVDB), "NodeShaderOpenVDB");
@@ -59,6 +64,7 @@ void register_node_type_sh_openvdb(void)
sh_node_type_base(&ntype, SH_NODE_OPENVDB, "OpenVDB Volume", NODE_CLASS_INPUT, 0);
node_type_compatibility(&ntype, NODE_NEW_SHADING);
node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
+ node_type_socket_templates(&ntype, sh_node_openvdb_in, NULL);
node_type_init(&ntype, node_shader_init_openvdb);
node_type_storage(&ntype, "NodeShaderOpenVDB", node_free_standard_storage, node_copy_standard_storage);
More information about the Bf-blender-cvs
mailing list