[Bf-blender-cvs] [b044546] strand_nodes: Node API for generating hair deformation GLSL code.
Lukas Tönne
noreply at git.blender.org
Thu Jul 21 17:41:09 CEST 2016
Commit: b044546587f049eaf39dd672217ac701bd828fac
Author: Lukas Tönne
Date: Wed Jul 20 12:15:54 2016 +0200
Branches: strand_nodes
https://developer.blender.org/rBb044546587f049eaf39dd672217ac701bd828fac
Node API for generating hair deformation GLSL code.
This is just a stub atm. The BVM system will use nodes to generate
a GLSL function, which can then be inserted into and compiled with
a framework shader. The deformation function itself is just a simple
expression (with autodiff for tangents), so it doesn't need to know
about the topology of index buffers and the like.
===================================================================
M release/scripts/nodes/bvm_debug.py
M source/blender/blenvm/BVM_api.h
M source/blender/blenvm/intern/bvm_api.cc
M source/blender/editors/space_view3d/drawstrands.c
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_strands.h
M source/blender/gpu/intern/gpu_strands_shader.c
M source/blender/makesrna/intern/rna_nodetree.c
===================================================================
diff --git a/release/scripts/nodes/bvm_debug.py b/release/scripts/nodes/bvm_debug.py
index 3063501..b3f890c 100644
--- a/release/scripts/nodes/bvm_debug.py
+++ b/release/scripts/nodes/bvm_debug.py
@@ -75,6 +75,8 @@ def draw_depshow_op(layout, ntree):
funtype = 'TEXTURE'
elif isinstance(ntree, bpy.types.ForceFieldNodeTree):
funtype = 'FORCEFIELD'
+ elif isinstance(ntree, bpy.types.HairNodeTree):
+ funtype = 'HAIR_DEFORM'
else:
return
diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index 74cfe90..d9cb19a 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -201,6 +201,11 @@ void BVM_eval_dupli_bvm(struct BVMEvalGlobals *globals,
struct Object *object,
struct DupliContainer *duplicont);
+/* ------------------------------------------------------------------------- */
+
+char *BVM_gen_hair_deform_function_glsl(struct bNodeTree *btree);
+void BVM_debug_hair_deform_nodes(struct bNodeTree *btree, FILE *debug_file, const char *label, BVMDebugMode mode);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 2a9b493..af88eef 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -96,6 +96,8 @@ static std::vector<NodeInputParam> modifier_inputs;
static std::vector<NodeOutputParam> modifier_outputs;
static std::vector<NodeInputParam> dupli_inputs;
static std::vector<NodeOutputParam> dupli_outputs;
+static std::vector<NodeInputParam> hair_deform_inputs;
+static std::vector<NodeOutputParam> hair_deform_outputs;
static void register_graph_types()
{
@@ -121,6 +123,11 @@ static void register_graph_types()
dupli_inputs.push_back(NodeInputParam("dupli.object", "RNAPOINTER"));
dupli_outputs.push_back(NodeOutputParam("dupli.result", "DUPLIS", __empty_duplilist__));
+
+ hair_deform_inputs.push_back(NodeInputParam("location", "FLOAT3"));
+ hair_deform_inputs.push_back(NodeInputParam("parameter", "FLOAT"));
+ hair_deform_inputs.push_back(NodeInputParam("target", "MATRIX44"));
+ hair_deform_outputs.push_back(NodeOutputParam("offset", "FLOAT3", zerovec));
}
}
@@ -909,3 +916,17 @@ void BVM_eval_dupli_bvm(struct BVMEvalGlobals *globals,
}
result.reset();
}
+
+/* ------------------------------------------------------------------------- */
+
+char *BVM_gen_hair_deform_function_glsl(bNodeTree *btree)
+{
+ using namespace blenvm;
+ return gen_function_glsl(btree, hair_deform_inputs, hair_deform_outputs);
+}
+
+void BVM_debug_hair_deform_nodes(bNodeTree *btree, FILE *debug_file, const char *label, BVMDebugMode mode)
+{
+ using namespace blenvm;
+ debug_nodes(btree, debug_file, label, mode, hair_deform_inputs, hair_deform_outputs);
+}
diff --git a/source/blender/editors/space_view3d/drawstrands.c b/source/blender/editors/space_view3d/drawstrands.c
index 78ca113..3dfe049 100644
--- a/source/blender/editors/space_view3d/drawstrands.c
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -32,6 +32,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_modifier_types.h"
+#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
@@ -146,6 +147,21 @@ void draw_strands(Scene *scene, View3D *UNUSED(v3d), RegionView3D *rv3d,
shader_params.use_geomshader = use_geomshader;
shader_params.shader_model = get_shader_model(smd->shader_model);
+ /* XXX TODO not nice, we can potentially have multiple hair
+ * subtrees and it's not clear yet how these would be combined.
+ * For the time being just select the first and expect it to be the only one ...
+ */
+ shader_params.nodes = NULL;
+ if (ob->nodetree) {
+ bNode *node;
+ for (node = ob->nodetree->nodes.first; node; node = node->next) {
+ if (STREQ(node->idname, "HairNode")) {
+ shader_params.nodes = (bNodeTree *)node->id;
+ break;
+ }
+ }
+ }
+
strands->gpu_shader = GPU_strand_shader_create(&shader_params);
}
GPUStrandsShader *shader = strands->gpu_shader;
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index e0ac32e..054abca 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -27,6 +27,7 @@ set(INC
.
../blenkernel
../blenlib
+ ../blenvm
../bmesh
../imbuf
../makesdna
diff --git a/source/blender/gpu/GPU_strands.h b/source/blender/gpu/GPU_strands.h
index 0038bee..af81a52 100644
--- a/source/blender/gpu/GPU_strands.h
+++ b/source/blender/gpu/GPU_strands.h
@@ -66,6 +66,7 @@ typedef struct GPUStrandsShaderParams {
int effects;
bool use_geomshader;
GPUStrands_ShaderModel shader_model;
+ struct bNodeTree *nodes;
} GPUStrandsShaderParams;
GPUStrandsShader *GPU_strand_shader_create(struct GPUStrandsShaderParams *params);
diff --git a/source/blender/gpu/intern/gpu_strands_shader.c b/source/blender/gpu/intern/gpu_strands_shader.c
index 38a7c55..9d13e33 100644
--- a/source/blender/gpu/intern/gpu_strands_shader.c
+++ b/source/blender/gpu/intern/gpu_strands_shader.c
@@ -43,6 +43,8 @@
#include "BKE_DerivedMesh.h" /* XXX just because GPU_buffers.h needs a type from here */
#include "BKE_strands.h"
+#include "BVM_api.h"
+
#include "GPU_buffers.h" /* XXX just for GPUAttrib, can that type be moved? */
#include "GPU_extensions.h"
#include "GPU_strands.h"
@@ -209,6 +211,7 @@ GPUStrandsShader *GPU_strand_shader_create(GPUStrandsShaderParams *params)
{
bool use_geometry_shader = params->use_geomshader;
+ BVM_gen_hair_deform_function_glsl(params->nodes);
GPUStrandsShader *gpu_shader = MEM_callocN(sizeof(GPUStrandsShader), "GPUStrands");
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 3314854..a14422a 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -80,6 +80,7 @@ typedef enum BVMFunctionType {
BVM_FUNTYPE_INSTANCING,
BVM_FUNTYPE_TEXTURE,
BVM_FUNTYPE_FORCEFIELD,
+ BVM_FUNTYPE_HAIR_DEFORM,
} BVMFunctionType;
#ifndef RNA_RUNTIME
@@ -1067,6 +1068,9 @@ static void rna_NodeTree_bvm_debug_graphviz(struct bNodeTree *ntree, const char
case BVM_FUNTYPE_FORCEFIELD:
BVM_debug_forcefield_nodes(ntree, f, label, mode);
break;
+ case BVM_FUNTYPE_HAIR_DEFORM:
+ BVM_debug_hair_deform_nodes(ntree, f, label, mode);
+ break;
}
fclose(f);
@@ -8150,6 +8154,7 @@ static void rna_def_nodetree(BlenderRNA *brna)
{BVM_FUNTYPE_INSTANCING, "INSTANCING", 0, "Instancing", ""},
{BVM_FUNTYPE_TEXTURE, "TEXTURE", 0, "Texture", ""},
{BVM_FUNTYPE_FORCEFIELD, "FORCEFIELD", 0, "Forcefield", ""},
+ {BVM_FUNTYPE_HAIR_DEFORM, "HAIR_DEFORM", 0, "Hair Deform", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -8159,6 +8164,7 @@ static void rna_def_nodetree(BlenderRNA *brna)
{BVM_DEBUG_BVM_CODE, "BVM_CODE", 0, "Generated BVM Code", ""},
{BVM_DEBUG_LLVM_CODE, "LLVM_CODE", 0, "Generated LLVM Code", ""},
{BVM_DEBUG_LLVM_CODE_UNOPTIMIZED, "LLVM_CODE_UNOPTIMIZED", 0, "Generated LLVM Code (unoptimized)", ""},
+ {BVM_DEBUG_GLSL_CODE, "GLSL_CODE", 0, "Generated GLSL Code", ""},
{0, NULL, 0, NULL, NULL}
};
More information about the Bf-blender-cvs
mailing list