[Bf-blender-cvs] [d54b4d2] object_nodes: Pass texture arguments and return values as dual values.
Lukas Tönne
noreply at git.blender.org
Thu May 19 19:29:29 CEST 2016
Commit: d54b4d25328eccd5804865df50af03a1b9925a58
Author: Lukas Tönne
Date: Thu May 19 11:52:48 2016 +0200
Branches: object_nodes
https://developer.blender.org/rBd54b4d25328eccd5804865df50af03a1b9925a58
Pass texture arguments and return values as dual values.
Currently only the value part is actually accessed. Using dual values
allows the node graph to handle input/output arguments are single a
single llvm::Value instance.
===================================================================
M source/blender/blenvm/BVM_api.h
M source/blender/blenvm/compile/node_graph.cc
M source/blender/blenvm/intern/bvm_api.cc
M source/blender/blenvm/util/util_math.h
M source/blender/render/intern/source/render_texture.c
===================================================================
diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index 7847404..684a9f8 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -149,8 +149,10 @@ void BVM_eval_texture_bvm(struct BVMEvalContext *context, struct BVMFunction *fn
float coord[3], float dxt[3], float dyt[3], int osatex,
short which_output, int cfra, int preview);
void BVM_eval_texture_llvm(struct BVMEvalContext *context, struct BVMFunction *fn,
- struct TexResult *target,
- float coord[3], float dxt[3], float dyt[3], int osatex,
+ struct TexResult *value,
+ struct TexResult *value_dx,
+ struct TexResult *value_dy,
+ const float coord[3], const float dxt[3], const float dyt[3], int osatex,
short which_output, int cfra, int preview);
/* ------------------------------------------------------------------------- */
diff --git a/source/blender/blenvm/compile/node_graph.cc b/source/blender/blenvm/compile/node_graph.cc
index 6a6bdb5..3c6b052 100644
--- a/source/blender/blenvm/compile/node_graph.cc
+++ b/source/blender/blenvm/compile/node_graph.cc
@@ -1221,8 +1221,7 @@ static void register_typedefs()
{
TypeSpec *float_t = TypeSpec::add_typedef("FLOAT", BVM_FLOAT);
- TypeSpec *float_dual_t = TypeSpec::add_typedef("FLOAT_DUAL", BVM_FLOAT);
- UNUSED_VARS(float_t, float_dual_t);
+ UNUSED_VARS(float_t);
TypeSpec *float3_t = TypeSpec::add_typedef("FLOAT3", BVM_FLOAT3);
UNUSED_VARS(float3_t);
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 6d5451b..586f713 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -510,10 +510,8 @@ void BVM_eval_forcefield_bvm(struct BVMEvalGlobals *globals, struct BVMEvalConte
namespace blenvm {
-typedef void (*TexNodesFunc)(float4 *r_color, float3 *r_normal,
- const float3 &co,
- const float3 &dxt, const float3 &dyt,
- int cfra, int osatex);
+typedef void (*TexNodesFunc)(Dual2<float4> *r_color, Dual2<float3> *r_normal,
+ const Dual2<float3> *co, int cfra, int osatex);
static void set_texresult(TexResult *result, const float4 &color, const float3 &normal)
{
@@ -539,8 +537,6 @@ static void init_texture_graph(blenvm::NodeGraph &graph)
using namespace blenvm;
graph.add_input("texture.co", "FLOAT3");
- graph.add_input("texture.dxt", "FLOAT3");
- graph.add_input("texture.dyt", "FLOAT3");
graph.add_input("texture.cfra", "INT");
graph.add_input("texture.osatex", "INT");
@@ -650,38 +646,40 @@ void BVM_eval_texture_bvm(struct BVMEvalContext *ctx, struct BVMFunction *fn,
}
void BVM_eval_texture_llvm(struct BVMEvalContext *UNUSED(ctx), struct BVMFunction *fn,
- struct TexResult *target,
- float coord[3], float dxt[3], float dyt[3], int osatex,
+ struct TexResult *value, struct TexResult *value_dx, struct TexResult *value_dy,
+ const float coord[3], const float dxt[3], const float dyt[3], int osatex,
short UNUSED(which_output), int cfra, int UNUSED(preview))
{
using namespace blenvm;
EvalGlobals globals;
- float4 r_color;
- float3 r_normal;
+ Dual2<float4> r_color;
+ Dual2<float3> r_normal;
UNUSED_VARS(globals);
#ifdef WITH_LLVM
TexNodesFunc fp = (TexNodesFunc)_FUNC_LLVM(fn)->ptr();
- float3 coord_v, dxt_v, dyt_v;
- copy_v3_v3(coord_v.data(), coord);
+ Dual2<float3> coord_v;
+ coord_v.set_value(float3(coord[0], coord[1], coord[2]));
if (dxt)
- copy_v3_v3(dxt_v.data(), dxt);
- else
- zero_v3(dxt_v.data());
+ coord_v.set_dx(float3(dxt[0], dxt[1], dxt[2]));
if (dyt)
- copy_v3_v3(dyt_v.data(), dyt);
- else
- zero_v3(dyt_v.data());
- fp(&r_color, &r_normal, coord_v, dxt_v, dyt_v, cfra, osatex);
+ coord_v.set_dy(float3(dyt[0], dyt[1], dyt[2]));
+
+ fp(&r_color, &r_normal, &coord_v, cfra, osatex);
#else
UNUSED_VARS(fn, coord, dxt, dyt, cfra, osatex);
- r_color = float4(0.0f, 0.0f, 0.0f, 0.0f);
- r_normal = float3(0.0f, 0.0f, 1.0f);
+ r_color = Dual2<float4>(float4(0.0f, 0.0f, 0.0f, 0.0f));
+ r_normal = Dual2<float3>(float3(0.0f, 0.0f, 1.0f));
#endif
- set_texresult(target, r_color, r_normal);
+ if (value)
+ set_texresult(value, r_color.value(), r_normal.value());
+ if (value_dx)
+ set_texresult(value_dx, r_color.dx(), r_normal.dx());
+ if (value_dy)
+ set_texresult(value_dy, r_color.dy(), r_normal.dy());
}
/* ------------------------------------------------------------------------- */
diff --git a/source/blender/blenvm/util/util_math.h b/source/blender/blenvm/util/util_math.h
index 5d88d55..2064fc1 100644
--- a/source/blender/blenvm/util/util_math.h
+++ b/source/blender/blenvm/util/util_math.h
@@ -235,6 +235,37 @@ inline static float modulo_safe(float a, float b)
return 0.0f;
}
+/* ************************************************************/
+/* Dual numbers for representing values and their derivatives */
+
+/* Dual value for functions of two variables */
+template <typename T>
+struct Dual2 {
+ Dual2()
+ {}
+
+ Dual2(const T &value) :
+ m_value(value), m_dx(T(0)), m_dy(T(0))
+ {}
+
+ Dual2(const T &value, const T &dx, const T &dy) :
+ m_value(value), m_dx(dx), m_dy(dy)
+ {}
+
+ const T &value() const { return m_value; }
+ const T &dx() const { return m_dx; }
+ const T &dy() const { return m_dy; }
+
+ void set_value(const T &value) { m_value = value; }
+ void set_dx(const T &dx) { m_dx = dx; }
+ void set_dy(const T &dy) { m_dy = dy; }
+
+private:
+ T m_value;
+ T m_dx;
+ T m_dy;
+};
+
} /* namespace blenvm */
#endif /* __BVM_UTIL_MATH_H__ */
diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c
index cb18e96..b4c5fea 100644
--- a/source/blender/render/intern/source/render_texture.c
+++ b/source/blender/render/intern/source/render_texture.c
@@ -1126,7 +1126,7 @@ static int multitex(Tex *tex,
if (fn) {
struct BVMEvalContext *context = BVM_context_create();
- BVM_eval_texture_llvm(context, fn, texres, texvec, dxt, dyt, osatex, which_output,
+ BVM_eval_texture_llvm(context, fn, texres, NULL, NULL, texvec, dxt, dyt, osatex, which_output,
R.r.cfra, texnode_preview);
retval = TEX_INT | TEX_RGB | TEX_NOR;
More information about the Bf-blender-cvs
mailing list