[Bf-blender-cvs] [19ad6a4] strand_nodes: Implementation of basic math functions for GLSL code generation from nodes.

Lukas Tönne noreply at git.blender.org
Sat Jul 23 09:24:07 CEST 2016


Commit: 19ad6a4570dfc86329278729324846b0fab63a8d
Author: Lukas Tönne
Date:   Fri Jul 22 17:26:19 2016 +0200
Branches: strand_nodes
https://developer.blender.org/rB19ad6a4570dfc86329278729324846b0fab63a8d

Implementation of basic math functions for GLSL code generation from nodes.

===================================================================

M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenvm/glsl/glsl_codegen.cc
M	source/blender/blenvm/intern/bvm_api.cc
M	source/blender/blenvm/modules/mod_math.h
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_strands.h
A	source/blender/gpu/intern/gpu_bvm_nodes.c
A	source/blender/gpu/intern/gpu_bvm_nodes.h
M	source/blender/gpu/intern/gpu_init_exit.c
M	source/blender/gpu/intern/gpu_shader.c
M	source/blender/gpu/intern/gpu_strands_shader.c
A	source/blender/gpu/shaders/gpu_shader_bvm_nodes_base.glsl
A	source/blender/gpu/shaders/gpu_shader_bvm_nodes_math.glsl
M	source/blender/gpu/shaders/gpu_shader_strand_debug_vert.glsl
D	source/blender/gpu/shaders/gpu_shader_strand_nodes.glsl
M	source/blender/gpu/shaders/gpu_shader_strand_util.glsl
M	source/blender/gpu/shaders/gpu_shader_strand_vert.glsl

===================================================================

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index c18f466..a30ca26 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1832,15 +1832,12 @@ static void mesh_calc_modifiers(
 		if (geotree) {
 			node_dm = mesh_calc_modifier_nodes(scene, ob, geotree);
 			DM_ensure_normals(node_dm);
+			
+			*r_final = node_dm;
+			if (r_deform)
+				*r_deform = CDDM_copy(node_dm);
+			return;
 		}
-		else {
-			node_dm = CDDM_from_mesh(me);
-		}
-		
-		*r_final = node_dm;
-		if (r_deform)
-			*r_deform = CDDM_copy(node_dm);
-		return;
 	}
 
 	if (!skipVirtualArmature) {
diff --git a/source/blender/blenvm/glsl/glsl_codegen.cc b/source/blender/blenvm/glsl/glsl_codegen.cc
index 059d362..6874e9b 100644
--- a/source/blender/blenvm/glsl/glsl_codegen.cc
+++ b/source/blender/blenvm/glsl/glsl_codegen.cc
@@ -305,6 +305,10 @@ void GLSLCodeGenerator::eval_node(const NodeType *nodetype,
 		}
 	}
 	
+	/* Count number of outputs with derivatives
+	 * to test if they are needed at all.
+	 */
+	int num_dual_outputs = 0;
 	for (int i = 0; i < nodetype->num_outputs(); ++i) {
 		const NodeOutput *output = nodetype->find_output(i);
 		const TypeSpec *typespec = output->typedesc.get_typespec();
@@ -315,12 +319,15 @@ void GLSLCodeGenerator::eval_node(const NodeType *nodetype,
 		if (bvm_glsl_type_has_dual_value(typespec)) {
 			args_dx << sep << dval.dx()->name();
 			args_dy << sep << dval.dy()->name();
+			++num_dual_outputs;
 		}
 	}
 	
 	m_code << "V_" << nodetype->name() << "(" << args_value.str() << ");\n";
-	m_code << "D_" << nodetype->name() << "(" << args_dx.str() << ");\n";
-	m_code << "D_" << nodetype->name() << "(" << args_dy.str() << ");\n";
+	if (num_dual_outputs > 0) {
+		m_code << "D_" << nodetype->name() << "(" << args_dx.str() << ");\n";
+		m_code << "D_" << nodetype->name() << "(" << args_dy.str() << ");\n";
+	}
 }
 
 } /* namespace blenvm */
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 37eac4c..d551b5a 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -126,6 +126,7 @@ static void register_graph_types()
 	
 	hair_deform_inputs.push_back(NodeInputParam("location", "FLOAT3"));
 	hair_deform_inputs.push_back(NodeInputParam("parameter", "FLOAT"));
+	hair_deform_inputs.push_back(NodeInputParam("curve_length", "FLOAT"));
 	hair_deform_inputs.push_back(NodeInputParam("target", "MATRIX44"));
 	hair_deform_outputs.push_back(NodeOutputParam("offset", "FLOAT3", zerovec));
 }
diff --git a/source/blender/blenvm/modules/mod_math.h b/source/blender/blenvm/modules/mod_math.h
index b2b0d80..bb7529f 100644
--- a/source/blender/blenvm/modules/mod_math.h
+++ b/source/blender/blenvm/modules/mod_math.h
@@ -310,7 +310,7 @@ bvm_extern void V__SQRT(float &r, float f)
 bvm_extern void D__SQRT(float &dr, float f, float df)
 {
 	if (f > 0.0f)
-		dr = df / sqrt_safe(f);
+		dr = df * 0.5f / sqrt_safe(f);
 	else
 		dr = 0.0f;
 }
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 6bec940..db0dbf3 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -49,6 +49,7 @@ set(INC_SYS
 set(SRC
 	intern/gpu_basic_shader.c
 	intern/gpu_buffers.c
+	intern/gpu_bvm_nodes.c
 	intern/gpu_codegen.c
 	intern/gpu_compositing.c
 	intern/gpu_debug.c
@@ -101,6 +102,7 @@ set(SRC
 	GPU_shader.h
 	GPU_strands.h
 	GPU_texture.h
+	intern/gpu_bvm_nodes.h
 	intern/gpu_codegen.h
 	intern/gpu_private.h
 )
@@ -133,8 +135,9 @@ data_to_c_simple(shaders/gpu_shader_strand_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_strand_debug_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_strand_debug_geom.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_strand_debug_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_strand_nodes.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_strand_util.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_bvm_nodes_base.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_bvm_nodes_math.glsl SRC)
 
 if(WITH_GAMEENGINE)
 	add_definitions(-DWITH_GAMEENGINE)
diff --git a/source/blender/gpu/GPU_strands.h b/source/blender/gpu/GPU_strands.h
index af81a52..f936f00 100644
--- a/source/blender/gpu/GPU_strands.h
+++ b/source/blender/gpu/GPU_strands.h
@@ -140,4 +140,4 @@ void GPU_strands_buffer_free(struct GPUDrawStrands *gpu_buffer);
 }
 #endif
 
-#endif /*__GPU_MATERIAL_H__*/
+#endif /*__GPU_STRANDS_H__*/
diff --git a/source/blender/gpu/intern/gpu_bvm_nodes.c b/source/blender/gpu/intern/gpu_bvm_nodes.c
new file mode 100644
index 0000000..2345b8c
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_bvm_nodes.c
@@ -0,0 +1,80 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/gpu/intern/gpu_bvm_nodes.c
+ *  \ingroup gpu
+ */
+
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_string.h"
+
+#include "intern/gpu_bvm_nodes.h"
+
+extern char datatoc_gpu_shader_bvm_nodes_base_glsl[];
+extern char datatoc_gpu_shader_bvm_nodes_math_glsl[];
+
+char *glsl_bvm_nodes_library = NULL;
+
+static char *codegen_libcode(void)
+{
+#define NUMPARTS 2
+	const char *parts[NUMPARTS] = {
+	    datatoc_gpu_shader_bvm_nodes_base_glsl,
+	    datatoc_gpu_shader_bvm_nodes_math_glsl,
+	};
+	size_t len[NUMPARTS];
+	size_t totlen = 1; /* includes terminator char */
+	for (int i = 0; i < NUMPARTS; ++i) {
+		len[i] = strlen(parts[i]);
+		totlen += len[i];
+	}
+	
+	char *buf = MEM_mallocN(sizeof(char) * totlen, "strand shader libcode");
+	char *s = buf;
+	for (int i = 0; i < NUMPARTS; ++i) {
+		strcpy(s, parts[i]);
+		s += len[i];
+	}
+	
+	return buf;
+#undef NUMPARTS
+}
+
+void gpu_bvm_nodes_init(void)
+{
+	glsl_bvm_nodes_library = codegen_libcode();
+}
+
+void gpu_bvm_nodes_exit(void)
+{
+	if (glsl_bvm_nodes_library)
+		MEM_freeN(glsl_bvm_nodes_library);
+}
diff --git a/source/blender/gpu/intern/gpu_bvm_nodes.h b/source/blender/gpu/intern/gpu_bvm_nodes.h
new file mode 100644
index 0000000..2467c50
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_bvm_nodes.h
@@ -0,0 +1,48 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file GPU_bvm_nodes.h
+ *  \ingroup gpu
+ */
+
+#ifndef __GPU_BVM_NODES_H__
+#define __GPU_BVM_NODES_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char *glsl_bvm_nodes_library;
+
+void gpu_bvm_nodes_init(void);
+void gpu_bvm_nodes_exit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*__GPU_BVM_NODES_H__*/
diff --git a/source/blender/gpu/intern/gpu_init_exit.c b/source/blender/gpu/intern/gpu_init_exit.c
index c72c83b..0f2c25e 100644
--- a/source/blender/gpu/intern/gpu_init_exit.c
+++ b/source/blender/gpu/intern/gpu_init_exit.c
@@ -34,6 +34,7 @@
 
 #include "BKE_global.h"
 
+#include "intern/gpu_bvm_nodes.h"
 #include "intern/gpu_codegen.h"
 #include "intern/gpu_private.h"
 
@@ -55,6 +56,7 @@ void GPU_init(void)
 	gpu_extensions_init(); /* must come first */
 
 	gpu_codegen_init();
+	gpu_bvm_nodes_init();
 
 	if (G.debug & G_DEBUG_GPU)
 		gpu_debug_init();
@@ -68,6 +70,7 @@ void GPU_exit(void)
 	if (G.debug & G_DEBUG_GPU)
 		gpu_debug_exit();
 	gpu_codegen_exit();
+	gpu_bvm_nodes_exit();
 
 	gpu_extensions_exit(); /* must come last */
 
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 5a1b38e..99cd7bb 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -313,7 +313,7 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
 	gpu_shader_standard_extensions(standard_extensions, geocode != NULL);
 
 	if (vertexcode) {
-		const char *source[5];
+		const char *source[6];
 		/* custom limit, may be too small, beware */
 		int num_source = 0;
 
@@ -322,6 +322,7 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
 		source[num_source++] = standard_defines;
 
 		if (defines) source[num_source++] = defines;
+		if (libcode) source[num_source++] = libcode;
 		source[num_source++] = vertexcode;
 
 		glAttachShader(shader->program, shader->vertex);
@@ -379,7 +380,7 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
 	}
 
 	if (geocode) {
-		const char *source[6];
+		const char *source[7];
 		int num_source = 0;
 
 		source[num_source++] = gpu_shader_version();
@@ -387,6 +388,7 @@ GPUSh

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list