[Bf-blender-cvs] [103ecf7] object_nodes: Fix expression result use as function arguments and add RGBA color mix node.

Lukas Tönne noreply at git.blender.org
Mon Apr 11 16:52:30 CEST 2016


Commit: 103ecf7acaadca866d5444ca9913e8224af0aae1
Author: Lukas Tönne
Date:   Mon Apr 11 16:51:45 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB103ecf7acaadca866d5444ca9913e8224af0aae1

Fix expression result use as function arguments and add RGBA color mix node.

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

M	source/blender/blenvm/llvm/CMakeLists.txt
M	source/blender/blenvm/llvm/llvm_codegen.cc
A	source/blender/blenvm/modules/mod_color.h
M	source/blender/blenvm/modules/mod_math.h
D	source/blender/blenvm/modules/mod_value.cc
A	source/blender/blenvm/modules/modules.cc

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

diff --git a/source/blender/blenvm/llvm/CMakeLists.txt b/source/blender/blenvm/llvm/CMakeLists.txt
index 0944e6c..ceac79a 100644
--- a/source/blender/blenvm/llvm/CMakeLists.txt
+++ b/source/blender/blenvm/llvm/CMakeLists.txt
@@ -91,14 +91,14 @@ macro(BLENVM_LLVM_MODULE_ADD src)
 	add_custom_command(
 		OUTPUT ${llvm_ir}
 		COMMAND ${LLVM_IR_COMPILER}
-				-cc1
 				-S
 				${CMAKE_CURRENT_SOURCE_DIR}/${src}
 				-emit-llvm
+				-std=c++0x
 				-o ${CMAKE_CURRENT_BINARY_DIR}/${llvm_ir}
 				-DBLENVM_RUNTIME
 				-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
-				-std=c++0x
+				-I${CMAKE_CURRENT_SOURCE_DIR}/../../blenlib
 		DEPENDS ${LLVM_SRC} ${LLVM_HEADERS})
 
 	delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${llvm_ir}" ${LLVM_IR_INSTALL_PATH}/modules/)
@@ -107,9 +107,11 @@ endmacro()
 
 
 set(LLVM_SRC
-	../modules/mod_value.cc
+	../modules/modules.cc
 )
 set(LLVM_HEADERS
+	../modules/mod_color.h
+	../modules/mod_math.h
 	../modules/mod_value.h
 )
 
diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc b/source/blender/blenvm/llvm/llvm_codegen.cc
index 8dc94c4..724d4e5 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_codegen.cc
@@ -353,13 +353,18 @@ llvm::CallInst *LLVMCompiler::codegen_node_call(llvm::BasicBlock *block,
 				args.push_back(value);
 				break;
 			}
-			case INPUT_EXPRESSION:
-				args.push_back(output_values.at(input.link()));
+			case INPUT_EXPRESSION: {
+				Value *valuemem = output_values.at(input.link());
+				Type *arg_type = evalfunc->getFunctionType()->getParamType(args.size());
+				Value *value = builder.CreatePointerBitCastOrAddrSpaceCast(valuemem, arg_type);
+				args.push_back(value);
 				break;
-			case INPUT_VARIABLE:
+			}
+			case INPUT_VARIABLE: {
 				/* TODO */
 				BLI_assert(false && "Variable inputs not supported yet!");
 				break;
+			}
 		}
 	}
 	
@@ -526,14 +531,14 @@ FunctionLLVM *LLVMCompiler::compile_function(const string &name, const NodeGraph
 	BLI_assert(m_module->getFunction(name) && "Function not registered in module!");
 	BLI_assert(func != NULL && "codegen_node_function returned NULL!");
 	
-	optimize_function(func, 2);
-	
 	printf("=== NODE FUNCTION ===\n");
 	fflush(stdout);
 	func->dump();
 	printf("=====================\n");
 	fflush(stdout);
 	
+	optimize_function(func, 2);
+	
 	verifyFunction(*func, &outs());
 	verifyModule(*m_module, &outs());
 	
diff --git a/source/blender/blenvm/modules/mod_color.h b/source/blender/blenvm/modules/mod_color.h
new file mode 100644
index 0000000..c56f247
--- /dev/null
+++ b/source/blender/blenvm/modules/mod_color.h
@@ -0,0 +1,286 @@
+/*
+ * ***** 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 __MOD_COLOR_H__
+#define __MOD_COLOR_H__
+
+extern "C" {
+#include "BLI_math_color.h"
+}
+
+#include "mod_math.h"
+
+enum BlendMode {
+	MA_RAMP_BLEND       = 0,
+	MA_RAMP_ADD         = 1,
+	MA_RAMP_MULT        = 2,
+	MA_RAMP_SUB         = 3,
+	MA_RAMP_SCREEN      = 4,
+	MA_RAMP_DIV         = 5,
+	MA_RAMP_DIFF        = 6,
+	MA_RAMP_DARK        = 7,
+	MA_RAMP_LIGHT       = 8,
+	MA_RAMP_OVERLAY     = 9,
+	MA_RAMP_DODGE       = 10,
+	MA_RAMP_BURN        = 11,
+	MA_RAMP_HUE         = 12,
+	MA_RAMP_SAT         = 13,
+	MA_RAMP_VAL         = 14,
+	MA_RAMP_COLOR       = 15,
+	MA_RAMP_SOFT        = 16,
+	MA_RAMP_LINEAR      = 17,
+};
+
+inline void MIX_RGB3(float3 &result, const int &mode, const float &fac,
+                     const float3 &col_a, const float3 &col_b)
+{
+	float tmp, facm = 1.0f - fac;
+	
+	result = col_a;
+	
+	switch (mode) {
+		case MA_RAMP_BLEND:
+			result[0] = facm * (result[0]) + fac * col_b[0];
+			result[1] = facm * (result[1]) + fac * col_b[1];
+			result[2] = facm * (result[2]) + fac * col_b[2];
+			break;
+		case MA_RAMP_ADD:
+			result[0] += fac * col_b[0];
+			result[1] += fac * col_b[1];
+			result[2] += fac * col_b[2];
+			break;
+		case MA_RAMP_MULT:
+			result[0] *= (facm + fac * col_b[0]);
+			result[1] *= (facm + fac * col_b[1]);
+			result[2] *= (facm + fac * col_b[2]);
+			break;
+		case MA_RAMP_SCREEN:
+			result[0] = 1.0f - (facm + fac * (1.0f - col_b[0])) * (1.0f - result[0]);
+			result[1] = 1.0f - (facm + fac * (1.0f - col_b[1])) * (1.0f - result[1]);
+			result[2] = 1.0f - (facm + fac * (1.0f - col_b[2])) * (1.0f - result[2]);
+			break;
+		case MA_RAMP_OVERLAY:
+			if (result[0] < 0.5f)
+				result[0] *= (facm + 2.0f * fac * col_b[0]);
+			else
+				result[0] = 1.0f - (facm + 2.0f * fac * (1.0f - col_b[0])) * (1.0f - result[0]);
+			if (result[1] < 0.5f)
+				result[1] *= (facm + 2.0f * fac * col_b[1]);
+			else
+				result[1] = 1.0f - (facm + 2.0f * fac * (1.0f - col_b[1])) * (1.0f - result[1]);
+			if (result[2] < 0.5f)
+				result[2] *= (facm + 2.0f * fac * col_b[2]);
+			else
+				result[2] = 1.0f - (facm + 2.0f * fac * (1.0f - col_b[2])) * (1.0f - result[2]);
+			break;
+		case MA_RAMP_SUB:
+			result[0] -= fac * col_b[0];
+			result[1] -= fac * col_b[1];
+			result[2] -= fac * col_b[2];
+			break;
+		case MA_RAMP_DIV:
+			if (col_b[0] != 0.0f)
+				result[0] = facm * (result[0]) + fac * (result[0]) / col_b[0];
+			if (col_b[1] != 0.0f)
+				result[1] = facm * (result[1]) + fac * (result[1]) / col_b[1];
+			if (col_b[2] != 0.0f)
+				result[2] = facm * (result[2]) + fac * (result[2]) / col_b[2];
+			break;
+		case MA_RAMP_DIFF:
+			result[0] = facm * (result[0]) + fac * fabsf(result[0] - col_b[0]);
+			result[1] = facm * (result[1]) + fac * fabsf(result[1] - col_b[1]);
+			result[2] = facm * (result[2]) + fac * fabsf(result[2] - col_b[2]);
+			break;
+		case MA_RAMP_DARK:
+			result[0] = min_ff(result[0], col_b[0]) * fac + result[0] * facm;
+			result[1] = min_ff(result[1], col_b[1]) * fac + result[1] * facm;
+			result[2] = min_ff(result[2], col_b[2]) * fac + result[2] * facm;
+			break;
+		case MA_RAMP_LIGHT:
+			tmp = fac * col_b[0];
+			if (tmp > result[0]) result[0] = tmp;
+			tmp = fac * col_b[1];
+			if (tmp > result[1]) result[1] = tmp;
+			tmp = fac * col_b[2];
+			if (tmp > result[2]) result[2] = tmp;
+			break;
+		case MA_RAMP_DODGE:
+			if (result[0] != 0.0f) {
+				tmp = 1.0f - fac * col_b[0];
+				if (tmp <= 0.0f)
+					result[0] = 1.0f;
+				else if ((tmp = (result[0]) / tmp) > 1.0f)
+					result[0] = 1.0f;
+				else
+					result[0] = tmp;
+			}
+			if (result[1] != 0.0f) {
+				tmp = 1.0f - fac * col_b[1];
+				if (tmp <= 0.0f)
+					result[1] = 1.0f;
+				else if ((tmp = (result[1]) / tmp) > 1.0f)
+					result[1] = 1.0f;
+				else
+					result[1] = tmp;
+			}
+			if (result[2] != 0.0f) {
+				tmp = 1.0f - fac * col_b[2];
+				if (tmp <= 0.0f)
+					result[2] = 1.0f;
+				else if ((tmp = (result[2]) / tmp) > 1.0f)
+					result[2] = 1.0f;
+				else
+					result[2] = tmp;
+			}
+			break;
+		case MA_RAMP_BURN:
+			tmp = facm + fac * col_b[0];
+			
+			if (tmp <= 0.0f)
+				result[0] = 0.0f;
+			else if ((tmp = (1.0f - (1.0f - (result[0])) / tmp)) < 0.0f)
+				result[0] = 0.0f;
+			else if (tmp > 1.0f)
+				result[0] = 1.0f;
+			else
+				result[0] = tmp;
+			
+			tmp = facm + fac * col_b[1];
+			if (tmp <= 0.0f)
+				result[1] = 0.0f;
+			else if ((tmp = (1.0f - (1.0f - (result[1])) / tmp)) < 0.0f)
+				result[1] = 0.0f;
+			else if (tmp > 1.0f)
+				result[1] = 1.0f;
+			else
+				result[1] = tmp;
+			
+			tmp = facm + fac * col_b[2];
+			if (tmp <= 0.0f)
+				result[2] = 0.0f;
+			else if ((tmp = (1.0f - (1.0f - (result[2])) / tmp)) < 0.0f)
+				result[2] = 0.0f;
+			else if (tmp > 1.0f)
+				result[2] = 1.0f;
+			else
+				result[2] = tmp;
+			break;
+		case MA_RAMP_HUE:
+		{
+			float rH, rS, rV;
+			float colH, colS, colV;
+			float tmpr, tmpg, tmpb;
+			rgb_to_hsv(col_b[0], col_b[1], col_b[2], &colH, &colS, &colV);
+			if (colS != 0) {
+				rgb_to_hsv(result[0], result[1], result[2], &rH, &rS, &rV);
+				hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb);
+				result[0] = facm * (result[0]) + fac * tmpr;
+				result[1] = facm * (result[1]) + fac * tmpg;
+				result[2] = facm * (result[2]) + fac * tmpb;
+			}
+			break;
+		}
+		case MA_RAMP_SAT:
+		{
+			float rH, rS, rV;
+			float colH, colS, colV;
+			rgb_to_hsv(result[0], result[1], result[2], &rH, &rS, &rV);
+			if (rS != 0) {
+				rgb_to_hsv(col_b[0], col_b[1], col_b[2], &colH, &colS, &colV);
+				hsv_to_rgb(rH, (facm * rS + fac * colS), rV, &result[0], &result[1], &result[2]);
+			}
+			break;
+		}
+		case MA_RAMP_VAL:
+		{
+			float rH, rS, rV;
+			float colH, colS, colV;
+			rgb_to_hsv(result[0], result[1], result[2], &rH, &rS, &rV);
+			rgb_to_hsv(col_b[0], col_b[1], col_b[2], &colH, &colS, &colV);
+			hsv_to_rgb(rH, rS, (facm * rV + fac * colV), &result[0], &result[1], &result[2]);
+			break;
+		}
+		case MA_RAMP_COLOR:
+		{
+			float rH, rS, rV;
+			float colH, colS, colV;
+			float tmpr, tmpg, tmpb;
+			rgb_to_hsv(col_b[0], col_b[1], col_b[2], &colH, &colS, &colV);
+			if (colS != 0) {
+				rgb_to_hsv(result[0], result[1], result[2], &rH, &rS, &rV);
+				hsv_to_rgb(colH, colS, rV, &tmpr, &tmpg, &tmpb);
+				result[0] = facm * (result[0]) + fac * tmpr;
+				result[1] = facm * (result[1]) + fac * tmpg;
+				result[2] = facm * (result[2]) + fac * tmpb;
+			}
+			break;
+		}
+		case MA_RAMP_SOFT:
+		{
+			float scr, scg, scb;
+			
+			/* first calculate non-fac based Screen mix */
+			scr = 1.0f - (1.0f - col_b[0]) * (1.0f - result[0]);
+			scg = 1.0f - (1.0f - col_b[1]) 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list