[Bf-blender-cvs] [1591616] object_nodes: Added first procedural texture node (voronoi).

Lukas Tönne noreply at git.blender.org
Tue Nov 24 09:43:42 CET 2015


Commit: 1591616e37b46be67548b348aa9dec9fb4f726a1
Author: Lukas Tönne
Date:   Fri Oct 30 10:23:32 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB1591616e37b46be67548b348aa9dec9fb4f726a1

Added first procedural texture node (voronoi).

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

M	source/blender/blenvm/bvm/CMakeLists.txt
M	source/blender/blenvm/bvm/bvm_eval.cc
A	source/blender/blenvm/bvm/bvm_eval_common.h
A	source/blender/blenvm/bvm/bvm_eval_texture.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

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

diff --git a/source/blender/blenvm/bvm/CMakeLists.txt b/source/blender/blenvm/bvm/CMakeLists.txt
index c9c481e..5c63fe5 100644
--- a/source/blender/blenvm/bvm/CMakeLists.txt
+++ b/source/blender/blenvm/bvm/CMakeLists.txt
@@ -40,6 +40,8 @@ set(INC_SYS
 set(SRC
 	bvm_eval.cc
 	bvm_eval.h
+	bvm_eval_common.h
+	bvm_eval_texture.h
 	bvm_expression.cc
 	bvm_expression.h
 	bvm_opcode.h
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index 6a0b4dd..a5ca337 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -41,7 +41,8 @@ extern "C" {
 }
 
 #include "bvm_eval.h"
-#include "bvm_expression.h"
+#include "bvm_eval_common.h"
+#include "bvm_eval_texture.h"
 
 namespace bvm {
 
@@ -53,56 +54,6 @@ EvalContext::~EvalContext()
 {
 }
 
-inline static float stack_load_float(float *stack, StackIndex offset)
-{
-	return *(float *)(&stack[offset]);
-}
-
-inline static float3 stack_load_float3(float *stack, StackIndex offset)
-{
-	return *(float3 *)(&stack[offset]);
-}
-
-inline static float4 stack_load_float4(float *stack, StackIndex offset)
-{
-	return *(float4 *)(&stack[offset]);
-}
-
-inline static int stack_load_int(float *stack, StackIndex offset)
-{
-	return *(int *)(&stack[offset]);
-}
-
-inline static matrix44 stack_load_matrix44(float *stack, StackIndex offset)
-{
-	return *(matrix44 *)(&stack[offset]);
-}
-
-inline static void stack_store_float(float *stack, StackIndex offset, float f)
-{
-	*(float *)(&stack[offset]) = f;
-}
-
-inline static void stack_store_float3(float *stack, StackIndex offset, float3 f)
-{
-	*(float3 *)(&stack[offset]) = f;
-}
-
-inline static void stack_store_float4(float *stack, StackIndex offset, float4 f)
-{
-	*(float4 *)(&stack[offset]) = f;
-}
-
-inline static void stack_store_int(float *stack, StackIndex offset, int i)
-{
-	*(int *)(&stack[offset]) = i;
-}
-
-inline static void stack_store_matrix44(float *stack, StackIndex offset, matrix44 m)
-{
-	*(matrix44 *)(&stack[offset]) = m;
-}
-
 /* ------------------------------------------------------------------------- */
 
 static void eval_op_value_float(float *stack, float value, StackIndex offset)
@@ -693,6 +644,27 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
 				eval_op_tex_coord(data, stack, offset);
 				break;
 			}
+			case OP_TEX_PROC_VORONOI: {
+				int distance_metric = expr->read_int(&instr);
+				int color_type = expr->read_int(&instr);
+				StackIndex iMinkowskiExponent = expr->read_stack_index(&instr);
+				StackIndex iScale = expr->read_stack_index(&instr);
+				StackIndex iNoiseSize = expr->read_stack_index(&instr);
+				StackIndex iNabla = expr->read_stack_index(&instr);
+				StackIndex iW1 = expr->read_stack_index(&instr);
+				StackIndex iW2 = expr->read_stack_index(&instr);
+				StackIndex iW3 = expr->read_stack_index(&instr);
+				StackIndex iW4 = expr->read_stack_index(&instr);
+				StackIndex iPos = expr->read_stack_index(&instr);
+				StackIndex oIntensity = expr->read_stack_index(&instr);
+				StackIndex oColor = expr->read_stack_index(&instr);
+				StackIndex oNormal = expr->read_stack_index(&instr);
+				eval_op_tex_proc_voronoi(stack, distance_metric, color_type,
+				                         iMinkowskiExponent, iScale, iNoiseSize, iNabla,
+				                         iW1, iW2, iW3, iW4, iPos,
+				                         oIntensity, oColor, oNormal);
+				break;
+			}
 			
 			case OP_EFFECTOR_TRANSFORM: {
 				int object_index = expr->read_int(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_eval_common.h b/source/blender/blenvm/bvm/bvm_eval_common.h
new file mode 100644
index 0000000..98f8aef
--- /dev/null
+++ b/source/blender/blenvm/bvm/bvm_eval_common.h
@@ -0,0 +1,92 @@
+/*
+ * ***** 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 *****
+ */
+
+#ifndef __BVM_EVAL_COMMON_H__
+#define __BVM_EVAL_COMMON_H__
+
+/** \file bvm_eval_common.h
+ *  \ingroup bvm
+ */
+
+#include "bvm_eval.h"
+#include "bvm_expression.h"
+
+namespace bvm {
+
+inline static float stack_load_float(float *stack, StackIndex offset)
+{
+	return *(float *)(&stack[offset]);
+}
+
+inline static float3 stack_load_float3(float *stack, StackIndex offset)
+{
+	return *(float3 *)(&stack[offset]);
+}
+
+inline static float4 stack_load_float4(float *stack, StackIndex offset)
+{
+	return *(float4 *)(&stack[offset]);
+}
+
+inline static int stack_load_int(float *stack, StackIndex offset)
+{
+	return *(int *)(&stack[offset]);
+}
+
+inline static matrix44 stack_load_matrix44(float *stack, StackIndex offset)
+{
+	return *(matrix44 *)(&stack[offset]);
+}
+
+inline static void stack_store_float(float *stack, StackIndex offset, float f)
+{
+	*(float *)(&stack[offset]) = f;
+}
+
+inline static void stack_store_float3(float *stack, StackIndex offset, float3 f)
+{
+	*(float3 *)(&stack[offset]) = f;
+}
+
+inline static void stack_store_float4(float *stack, StackIndex offset, float4 f)
+{
+	*(float4 *)(&stack[offset]) = f;
+}
+
+inline static void stack_store_int(float *stack, StackIndex offset, int i)
+{
+	*(int *)(&stack[offset]) = i;
+}
+
+inline static void stack_store_matrix44(float *stack, StackIndex offset, matrix44 m)
+{
+	*(matrix44 *)(&stack[offset]) = m;
+}
+
+} /* namespace bvm */
+
+#endif /* __BVM_EVAL_COMMON_H__ */
diff --git a/source/blender/blenvm/bvm/bvm_eval_texture.h b/source/blender/blenvm/bvm/bvm_eval_texture.h
new file mode 100644
index 0000000..504339a
--- /dev/null
+++ b/source/blender/blenvm/bvm/bvm_eval_texture.h
@@ -0,0 +1,136 @@
+/*
+ * ***** 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 *****
+ */
+
+#ifndef __BVM_EVAL_TEXTURE_H__
+#define __BVM_EVAL_TEXTURE_H__
+
+/** \file bvm_eval_texture.h
+ *  \ingroup bvm
+ */
+
+extern "C" {
+#include "BLI_noise.h"
+}
+
+#include "bvm_eval_common.h"
+
+namespace bvm {
+
+inline void eval_op_tex_proc_voronoi(float *stack, int distance_metric, int color_type,
+                                     StackIndex iMinkowskiExponent, StackIndex iScale,
+                                     StackIndex iNoiseSize, StackIndex iNabla,
+                                     StackIndex iW1, StackIndex iW2, StackIndex iW3, StackIndex iW4,
+                                     StackIndex iPos,
+                                     StackIndex oIntensity, StackIndex oColor, StackIndex oNormal)
+{
+	float3 texvec = stack_load_float3(stack, iPos);
+	float mexp = stack_load_float(stack, iMinkowskiExponent);
+	float noisesize = stack_load_float(stack, iNoiseSize);
+	float nabla = stack_load_float(stack, iNabla);
+	
+	float w1 = stack_load_float(stack, iW1);
+	float w2 = stack_load_float(stack, iW2);
+	float w3 = stack_load_float(stack, iW3);
+	float w4 = stack_load_float(stack, iW4);
+	float aw1 = fabsf(w1);
+	float aw2 = fabsf(w2);
+	float aw3 = fabsf(w3);
+	float aw4 = fabsf(w4);
+	float sc = (aw1 + aw2 + aw3 + aw4);
+	if (sc != 0.0f)
+		sc = stack_load_float(stack, iScale) / sc;
+	
+	float da[4], pa[12];	/* distance and point coordinate arrays of 4 nearest neighbors */
+
+	voronoi(texvec.x, texvec.y, texvec.z, da, pa, mexp, distance_metric);
+	
+	float intensity = sc * fabsf(w1*da[0] + w2*da[1] + w3*da[2] + w4*da[3]);
+
+	float4 color;
+	if (color_type == 0) {
+		color = float4(intensity, intensity, intensity, 1.0f);
+	}
+	else {
+		float ca[3];	/* cell color */
+		float r, g, b;
+		cellNoiseV(pa[0], pa[1], pa[2], ca);
+		r = aw1*ca[0];
+		g = aw1*ca[1];
+		b = aw1*ca[2];
+		cellNoiseV(pa[3], pa[4], pa[5], ca);
+		r += aw2*ca[0];
+		g += aw2*ca[1];
+		b += aw2*ca[2];
+		cellNoiseV(pa[6], pa[7], pa[8], ca);
+		r += aw3*ca[0];
+		g += aw3*ca[1];
+		b += aw3*ca[2];
+		cellNoiseV(pa[9], pa[10], pa[11], ca);
+		r += aw4*ca[0];
+		g += aw4*ca[1];
+		b += aw4*ca[2];
+		
+		if (color_type > 1) {
+			float t1 = (da[1] - da[0]) * 10;
+			if (t1 > 1.0f)
+				t1 = 1.0f;
+			if (color_type > 2)
+				t1 *= intensity;
+			else
+				t1 *= sc;
+			
+			r *= t1;
+			g *= t1;
+			b *= t1;
+		}
+		else {
+			r *= sc;
+			g *= sc;
+			b *= sc;
+		}
+		
+		color = float4(r, g, b, 1.0f);
+	}
+
+	float offs = nabla / noisesize;	/* also scaling of texvec */
+	/* calculate bumpnormal */
+	float3 normal;
+	voronoi(texvec.x + offs, texvec.y, texvec.z, da, pa, mexp,  distance_metric);
+	normal.x = sc * fabsf(w1*da[0] + w2*da[1] + w3*da[2] + w4*da[3]);
+	voronoi(texvec.x, texvec.y + offs, texvec.z, da, pa, mexp,  distance_metric);
+	norm

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list