[Bf-blender-cvs] [b030959] object_nodes: Added clouds noise pattern node.

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


Commit: b03095919a45dc463cdb7ceaab2ea7e7ec18df48
Author: Lukas Tönne
Date:   Fri Nov 6 17:04:41 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBb03095919a45dc463cdb7ceaab2ea7e7ec18df48

Added clouds noise pattern node.

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

M	source/blender/blenvm/bvm/bvm_eval.cc
M	source/blender/blenvm/bvm/bvm_eval_texture.h
M	source/blender/blenvm/compile/bvm_nodegraph.cc
M	source/blender/blenvm/intern/bvm_api.cc

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

diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index 4e57a9d..18187fd 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -824,6 +824,21 @@ void EvalContext::eval_instructions(const EvalGlobals *globals, const EvalData *
 				                         oIntensity, oColor, oNormal);
 				break;
 			}
+			case OP_TEX_PROC_CLOUDS: {
+				StackIndex iPos = expr->read_stack_index(&instr);
+				StackIndex iNabla = expr->read_stack_index(&instr);
+				StackIndex iSize = expr->read_stack_index(&instr);
+				int iDepth = expr->read_int(&instr);
+				int iNoiseBasis = expr->read_int(&instr);
+				int iNoiseHard = expr->read_int(&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_clouds(stack, iPos, iNabla, iSize,
+				                        iDepth, iNoiseBasis, iNoiseHard,
+				                        oIntensity, oColor, oNormal);
+				break;
+			}
 			
 			case OP_EFFECTOR_OBJECT: {
 				StackIndex offset = expr->read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_eval_texture.h b/source/blender/blenvm/bvm/bvm_eval_texture.h
index 504339a..f83c95d 100644
--- a/source/blender/blenvm/bvm/bvm_eval_texture.h
+++ b/source/blender/blenvm/bvm/bvm_eval_texture.h
@@ -69,8 +69,9 @@ inline void eval_op_tex_proc_voronoi(float *stack, int distance_metric, int colo
 	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;
+	float3 normal;
+	
 	if (color_type == 0) {
 		color = float4(intensity, intensity, intensity, 1.0f);
 	}
@@ -116,15 +117,51 @@ inline void eval_op_tex_proc_voronoi(float *stack, int distance_metric, int colo
 		color = float4(r, g, b, 1.0f);
 	}
 
-	float offs = nabla / noisesize;	/* also scaling of texvec */
 	/* calculate bumpnormal */
+	{
+		float offs = nabla / noisesize;	/* also scaling of texvec */
+		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);
+		normal.y = sc * fabsf(w1*da[0] + w2*da[1] + w3*da[2] + w4*da[3]);
+		voronoi(texvec.x, texvec.y, texvec.z + offs, da, pa, mexp,  distance_metric);
+		normal.z = sc * fabsf(w1*da[0] + w2*da[1] + w3*da[2] + w4*da[3]);
+	}
+	
+	stack_store_float(stack, oIntensity, intensity);
+	stack_store_float4(stack, oColor, color);
+	stack_store_float3(stack, oNormal, normal);
+}
+
+inline void eval_op_tex_proc_clouds(float *stack,
+                                    StackIndex iPos, StackIndex iNabla, StackIndex iSize,
+                                    int depth, int noise_basis, int noise_hard,
+                                    StackIndex oIntensity, StackIndex oColor, StackIndex oNormal)
+{
+	float3 texvec = stack_load_float3(stack, iPos);
+	float size = stack_load_float(stack, iSize);
+	float nabla = stack_load_float(stack, iNabla);
+	
+	float intensity = BLI_gTurbulence(size, texvec.x, texvec.y, texvec.z, depth, noise_hard, noise_basis);
+	float4 color;
 	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);
-	normal.y = sc * fabsf(w1*da[0] + w2*da[1] + w3*da[2] + w4*da[3]);
-	voronoi(texvec.x, texvec.y, texvec.z + offs, da, pa, mexp,  distance_metric);
-	normal.z = sc * fabsf(w1*da[0] + w2*da[1] + w3*da[2] + w4*da[3]);
+
+	/* calculate bumpnormal */
+	{
+		float x = BLI_gTurbulence(size, texvec.x + nabla, texvec.y, texvec.z, depth, noise_hard, noise_basis);
+		float y = BLI_gTurbulence(size, texvec.x, texvec.y + nabla, texvec.z, depth, noise_hard, noise_basis);
+		float z = BLI_gTurbulence(size, texvec.x, texvec.y, texvec.z + nabla, depth, noise_hard, noise_basis);
+		normal = float3(x, y, z);
+	}
+
+	{
+		/* in this case, int. value should really be computed from color,
+		 * and bumpnormal from that, would be too slow, looks ok as is */
+		float r = intensity;
+		float g = BLI_gTurbulence(size, texvec.y, texvec.x, texvec.z, depth, noise_hard, noise_basis);
+		float b = BLI_gTurbulence(size, texvec.y, texvec.z, texvec.x, depth, noise_hard, noise_basis);
+		color = float4(r, g, b, 1.0f);
+	}
 	
 	stack_store_float(stack, oIntensity, intensity);
 	stack_store_float4(stack, oColor, color);
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 03bd547..bf44a82 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -789,6 +789,7 @@ OpCode get_opcode_from_node_type(const string &node)
 	
 	NODETYPE(TEX_COORD);
 	NODETYPE(TEX_PROC_VORONOI);
+	NODETYPE(TEX_PROC_CLOUDS);
 	
 	NODETYPE(EFFECTOR_OBJECT);
 	NODETYPE(EFFECTOR_TRANSFORM);
@@ -976,6 +977,17 @@ void register_opcode_node_types()
 	nt->add_output("color", BVM_FLOAT4, float4(0.0f, 0.0f, 0.0f, 1.0f));
 	nt->add_output("normal", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
 	
+	nt = NodeGraph::add_node_type("TEX_PROC_CLOUDS");
+	nt->add_input("position", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+	nt->add_input("nabla", BVM_FLOAT, 0.05f);
+	nt->add_input("size", BVM_FLOAT, 1.0f);
+	nt->add_input("depth", BVM_INT, 2, true);
+	nt->add_input("noise_basis", BVM_INT, 0, true);
+	nt->add_input("noise_hard", BVM_INT, 0, true);
+	nt->add_output("intensity", BVM_FLOAT, 0.0f);
+	nt->add_output("color", BVM_FLOAT4, float4(0.0f, 0.0f, 0.0f, 1.0f));
+	nt->add_output("normal", BVM_FLOAT3, float3(0.0f, 0.0f, 0.0f));
+	
 	nt = NodeGraph::add_node_type("EFFECTOR_OBJECT");
 	nt->add_output("object", BVM_POINTER, PointerRNA_NULL);
 	
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 2e4abf1..efd9c69 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -688,6 +688,21 @@ static void convert_tex_node(bNodeCompiler *comp, PointerRNA *bnode_ptr)
 		comp->map_output_socket(0, SocketPair(node, "color"));
 		comp->map_output_socket(1, SocketPair(node, "normal"));
 	}
+	else if (type == "TextureNodeTexClouds") {
+		Tex *tex = (Tex *)bnode->storage;
+		
+		NodeInstance *node = comp->add_node("TEX_PROC_CLOUDS");
+		node->set_input_value("depth", (int)tex->noisedepth);
+		node->set_input_value("noise_basis", (int)tex->noisebasis);
+		node->set_input_value("noise_hard", (int)(tex->noisetype != TEX_NOISESOFT));
+		node->set_input_value("nabla", 0.05f);
+		
+		comp->map_input_socket(0, SocketPair(node, "position"));
+		comp->map_input_socket(3, SocketPair(node, "size"));
+		
+		comp->map_output_socket(0, SocketPair(node, "color"));
+		comp->map_output_socket(1, SocketPair(node, "normal"));
+	}
 }
 
 } /* namespace bvm */




More information about the Bf-blender-cvs mailing list