[Bf-blender-cvs] [d86fae6] object_nodes: Start of a texture node replacement using the bvm system.
Lukas Tönne
noreply at git.blender.org
Tue Nov 24 09:43:37 CET 2015
Commit: d86fae6d847ead88f9381f08945ecfcb7e3099ef
Author: Lukas Tönne
Date: Thu Oct 29 11:19:44 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBd86fae6d847ead88f9381f08945ecfcb7e3099ef
Start of a texture node replacement using the bvm system.
===================================================================
M source/blender/blenkernel/BKE_node.h
M source/blender/blenvm/BVM_api.h
M source/blender/blenvm/CMakeLists.txt
M source/blender/blenvm/bvm/bvm_eval.cc
M source/blender/blenvm/bvm/bvm_eval.h
M source/blender/blenvm/bvm/bvm_opcode.h
M source/blender/blenvm/compile/bvm_nodegraph.cc
M source/blender/blenvm/intern/bvm_api.cc
A source/blender/blenvm/util/bvm_util_thread.h
M source/blender/blenvm/util/bvm_util_typedesc.h
M source/blender/nodes/texture/node_texture_tree.c
M source/blender/render/CMakeLists.txt
M source/blender/render/intern/source/render_texture.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index a7b488c..268cc66 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1051,9 +1051,6 @@ void ntreeTexCheckCyclics(struct bNodeTree *ntree);
struct bNodeTreeExec *ntreeTexBeginExecTree(struct bNodeTree *ntree);
void ntreeTexEndExecTree(struct bNodeTreeExec *exec);
-int ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target,
- float coord[3], float dxt[3], float dyt[3], int osatex, const short thread,
- struct Tex *tex, short which_output, int cfra, int preview, struct ShadeInput *shi, struct MTex *mtex);
/** \} */
void init_nodesystem(void);
diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index 0fe77d2..8fafc67 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -92,7 +92,22 @@ void BVM_eval_forcefield(struct BVMEvalGlobals *globals, struct BVMEvalContext *
/* ------------------------------------------------------------------------- */
+struct Tex;
+struct TexResult;
+struct BVMExpression *BVM_gen_texture_expression(const struct BVMEvalGlobals *globals, struct Tex *tex, struct bNodeTree *btree);
+
+void BVM_eval_texture(struct BVMEvalContext *context, struct BVMExpression *expr,
+ struct TexResult *target,
+ float coord[3], float dxt[3], float dyt[3], int osatex,
+ short which_output, int cfra, int preview);
+
+struct BVMExpression *BVM_texture_cache_acquire(Tex *tex);
+void BVM_texture_cache_release(Tex *tex);
+void BVM_texture_cache_invalidate(Tex *tex);
+void BVM_texture_cache_clear(void);
+
+/* ------------------------------------------------------------------------- */
#ifdef __cplusplus
}
diff --git a/source/blender/blenvm/CMakeLists.txt b/source/blender/blenvm/CMakeLists.txt
index 05f180c..c1aba2b 100644
--- a/source/blender/blenvm/CMakeLists.txt
+++ b/source/blender/blenvm/CMakeLists.txt
@@ -35,6 +35,7 @@ set(INC
../blenlib
../makesdna
../makesrna
+ ../render/extern/include
../../../intern/guardedalloc
)
@@ -53,6 +54,7 @@ set(SRC
util/bvm_util_hash.h
util/bvm_util_map.h
util/bvm_util_string.h
+ util/bvm_util_thread.h
util/bvm_util_typedesc.h
BVM_api.h
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index f104db3..988a1a2 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -142,6 +142,12 @@ static void eval_op_pass_float3(float *stack, StackIndex offset_from, StackIndex
stack_store_float3(stack, offset_to, f);
}
+static void eval_op_pass_float4(float *stack, StackIndex offset_from, StackIndex offset_to)
+{
+ float4 f = stack_load_float4(stack, offset_from);
+ stack_store_float4(stack, offset_to, f);
+}
+
static void eval_op_set_float3(float *stack, StackIndex offset_x, StackIndex offset_y, StackIndex offset_z, StackIndex offset_to)
{
float x = stack_load_float(stack, offset_x);
@@ -363,8 +369,7 @@ static void eval_op_normalize_float3(float *stack, StackIndex offset, StackIndex
static void eval_op_effector_transform(const EvalGlobals *globals, float *stack, int object_index, StackIndex offset_tfm)
{
Object *ob = globals->objects[object_index];
- matrix44 m;
- m.from_data(&ob->obmat[0][0], matrix44::COL_MAJOR);
+ matrix44 m = matrix44::from_data(&ob->obmat[0][0], matrix44::COL_MAJOR);
stack_store_matrix44(stack, offset_tfm, m);
}
@@ -400,6 +405,8 @@ static void eval_op_effector_closest_point(const EvalGlobals *globals, float *st
stack_store_float3(stack, offset_position, pos);
stack_store_float3(stack, offset_normal, nor);
+ // TODO
+ stack_store_float3(stack, offset_tangent, float3(0.0f, 0.0f, 0.0f));
}
}
@@ -455,6 +462,12 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
eval_op_pass_float3(stack, offset_from, offset_to);
break;
}
+ case OP_PASS_FLOAT4: {
+ StackIndex offset_from = expr->read_stack_index(&instr);
+ StackIndex offset_to = expr->read_stack_index(&instr);
+ eval_op_pass_float4(stack, offset_from, offset_to);
+ break;
+ }
case OP_SET_FLOAT3: {
StackIndex offset_x = expr->read_stack_index(&instr);
StackIndex offset_y = expr->read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_eval.h b/source/blender/blenvm/bvm/bvm_eval.h
index c435a36..d049a58 100644
--- a/source/blender/blenvm/bvm/bvm_eval.h
+++ b/source/blender/blenvm/bvm/bvm_eval.h
@@ -82,11 +82,19 @@ struct EffectorEvalData {
float3 velocity;
};
+struct TextureEvalData {
+ float3 co;
+ float3 dxt, dyt;
+ int cfra;
+ int osatex;
+};
+
struct EvalData {
EvalData()
{}
EffectorEvalData effector;
+ TextureEvalData texture;
};
struct EvalContext {
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h b/source/blender/blenvm/bvm/bvm_opcode.h
index 423f2d8..62f6957 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -43,6 +43,7 @@ enum OpCode {
OP_VALUE_MATRIX44,
OP_PASS_FLOAT,
OP_PASS_FLOAT3,
+ OP_PASS_FLOAT4,
OP_SET_FLOAT3,
OP_GET_ELEM_FLOAT3,
OP_SET_FLOAT4,
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 2315477..44697a0 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -556,6 +556,7 @@ OpCode get_opcode_from_node_type(const string &node)
NODETYPE(PASS_FLOAT);
NODETYPE(PASS_FLOAT3);
+ NODETYPE(PASS_FLOAT4);
NODETYPE(SET_FLOAT3);
NODETYPE(GET_ELEM_FLOAT3);
@@ -611,6 +612,10 @@ void register_opcode_node_types()
nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
nt->add_output("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+ nt = NodeGraph::add_node_type("PASS_FLOAT4");
+ nt->add_input("value", BVM_FLOAT4, float4(0.0f, 0.0f, 0.0f, 0.0f));
+ nt->add_output("value", BVM_FLOAT4, float4(0.0f, 0.0f, 0.0f, 0.0f));
+
nt = NodeGraph::add_node_type("GET_ELEM_FLOAT3");
nt->add_input("index", BVM_INT, 0, true);
nt->add_input("value", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index f2a5bff..9cfaa74 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -43,6 +43,8 @@ extern "C" {
#include "BKE_effect.h"
#include "BKE_node.h"
+#include "RE_shader_ext.h"
+
#include "BVM_api.h"
#include "RNA_access.h"
@@ -55,6 +57,7 @@ extern "C" {
#include "bvm_module.h"
#include "bvm_nodegraph.h"
#include "bvm_util_map.h"
+#include "bvm_util_thread.h"
void BVM_init(void)
{
@@ -63,6 +66,7 @@ void BVM_init(void)
void BVM_free(void)
{
+ BVM_texture_cache_clear();
}
/* ------------------------------------------------------------------------- */
@@ -167,6 +171,16 @@ struct bNodeCompiler {
node->set_input_value(name, bvm::float3(bvalue->value[0], bvalue->value[1], bvalue->value[2]));
break;
}
+ case SOCK_INT: {
+ bNodeSocketValueInt *bvalue = (bNodeSocketValueInt *)binput->default_value;
+ node->set_input_value(name, bvalue->value);
+ break;
+ }
+ case SOCK_RGBA: {
+ bNodeSocketValueRGBA *bvalue = (bNodeSocketValueRGBA *)binput->default_value;
+ node->set_input_value(name, bvm::float4(bvalue->value[0], bvalue->value[1], bvalue->value[2], bvalue->value[3]));
+ break;
+ }
}
}
@@ -476,14 +490,50 @@ void BVM_eval_forcefield(struct BVMEvalGlobals *globals, struct BVMEvalContext *
_CTX(ctx)->eval_expression(_GLOBALS(globals), &data, _EXPR(expr), results);
}
-{
+/* ------------------------------------------------------------------------- */
+
+struct TextureNodeParser : public bNodeParser {
+ TextureNodeParser(const bvm::EvalGlobals */*globals*/)
+ {
}
-}
+
+ void parse(bNodeCompiler *comp, PointerRNA *bnode_ptr) const
+ {
+ bNode *bnode = (bNode *)bnode_ptr->data;
+ bvm::string type = bvm::string(bnode->typeinfo->idname);
+ if (type == "TextureNodeOutput") {
+ {
+ bvm::NodeInstance *node = comp->add_node("PASS_FLOAT4", "RET_COLOR_" + bvm::string(bnode->name));
+ comp->map_input_socket(bnode, 0, node, "value");
+ comp->map_output_socket(bnode, 0, node, "value");
+
+ comp->set_graph_output("color", node, "value");
+ }
+
+ {
+ bvm::NodeInstance *node = comp->add_node("PASS_FLOAT3", "RET_NORMAL_" + bvm::string(bnode->name));
+ comp->map_input_socket(bnode, 1, node, "value");
+ comp->map_output_socket(bnode, 0, node, "value");
+
+ comp->set_graph_output("normal", node, "value");
+ }
+ }
+ }
+};
+struct BVMExpression *BVM_gen_texture_expression(const struct BVMEvalGlobals *globals, struct Tex *tex, bNodeTree *btree)
{
using namespace bvm;
NodeGraph graph;
+ {
+ float C[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ float N[3] = {0.0f, 0.0f, 0.0f};
+ graph.add_output("color", BVM_FLOAT4, C);
+ graph.add_output("normal", BVM_FLOAT3, N);
+ }
+ TextureNodeParser parser(_GLOBALS(globals));
+ gen_nodegraph(btree, graph, parser);
BVMCompiler compiler;
Expression *expr = compiler.codegen_expression(graph);
@@ -491,6 +541,105 @@ void BVM_eval_forcefield(struct BVMEvalGlobals *globals, struct BVMEvalContext *
return (BVMExpression *)expr;
}
+void BVM_eval_texture(struct BVMEvalContext *ctx, struct BVMExpression *expr,
+ struct TexResult *target,
+ float coord[3], float dxt[3], float dyt[3], int osatex,
+ short which_output, int cfra, int UNUSED(preview))
+{
+ using namespace bvm;
+
+ EvalGlobals globals;
+
+ EvalData data;
+ TextureEvalData &texdata = data.texture;
+ texdata.co = float3::from_data(coord);
+ texdata.dxt = dxt ? float3::from_data(dxt) : float3(0.0f, 0.0f, 0.0f);
+ texdata.dyt = dyt ? float3::from_data(dyt) : float3(0.0f, 0.0f, 0.0f);
+ texdata.cfra = cfra;
+ texdata.osatex = osatex;
+
+ float4 color;
+ float3 normal;
+ void *results[] = { &color.x, &normal.x };
+
+ _CTX(ctx)->eval_expression(&globals, &data, _EXPR(expr), results);
+
+ target->tr = color.x;
+ target->tg =
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list