[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50295] trunk/blender: Added a bunch of additional particle state attributes to the Cycles particle info node :

Lukas Toenne lukas.toenne at googlemail.com
Fri Aug 31 21:39:00 CEST 2012


Revision: 50295
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50295
Author:   lukastoenne
Date:     2012-08-31 19:38:59 +0000 (Fri, 31 Aug 2012)
Log Message:
-----------
Added a bunch of additional particle state attributes to the Cycles particle info node:

* Location: Basically the same as the location from Object Info node for object instances on particles, but in principle there could be additional offsets for dupli objects, so included for completeness.
* Size: Single float scale of the particle. Also directly translates to object scale for current dupli objects, but handy to have as a single float to start with instead of a scale vector (currently not even exposed in Object Info).
* Rotation: This is a quaternion, which are not yet supported by Cycles nodes. The float4 is copied to internal Cycles data and stored in the particles texture data, but the node doesn't have a socket for it yet and the data is not yet written to the stack. Code is just commented out so could be enabled quickly if/when rotation support is added to cycles.
* Velocity: Linear velocity vector of particles.
* Angular Velocity: Angular velocity around principle axes.

The texture data is currently packed tightly into the particles texture, which saves a few bytes, but requires an additional texture lookup for some vector attributes which spread over two float4s. Could also add another float4 to particle size to avoid this.

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/blender_particles.cpp
    trunk/blender/intern/cycles/blender/blender_util.h
    trunk/blender/intern/cycles/kernel/kernel_object.h
    trunk/blender/intern/cycles/kernel/kernel_types.h
    trunk/blender/intern/cycles/kernel/svm/svm_geometry.h
    trunk/blender/intern/cycles/kernel/svm/svm_types.h
    trunk/blender/intern/cycles/render/nodes.cpp
    trunk/blender/intern/cycles/render/particles.cpp
    trunk/blender/intern/cycles/render/particles.h
    trunk/blender/source/blender/nodes/shader/nodes/node_shader_particle_info.c

Modified: trunk/blender/intern/cycles/blender/blender_particles.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_particles.cpp	2012-08-31 17:27:08 UTC (rev 50294)
+++ trunk/blender/intern/cycles/blender/blender_particles.cpp	2012-08-31 19:38:59 UTC (rev 50295)
@@ -168,6 +168,11 @@
 				pa.index = index;
 				pa.age = b_scene.frame_current() - b_pa->birth_time();
 				pa.lifetime = b_pa->lifetime();
+				pa.location = get_float3(b_pa->location());
+				pa.rotation = get_float4(b_pa->rotation());
+				pa.size = b_pa->size();
+				pa.velocity = get_float3(b_pa->velocity());
+				pa.angular_velocity = get_float3(b_pa->angular_velocity());
 				
 				psys->particles.push_back(pa);
 			}

Modified: trunk/blender/intern/cycles/blender/blender_util.h
===================================================================
--- trunk/blender/intern/cycles/blender/blender_util.h	2012-08-31 17:27:08 UTC (rev 50294)
+++ trunk/blender/intern/cycles/blender/blender_util.h	2012-08-31 19:38:59 UTC (rev 50295)
@@ -150,6 +150,11 @@
 	return make_float3(array[0], array[1], array[2]);
 }
 
+static inline float4 get_float4(BL::Array<float, 4> array)
+{
+	return make_float4(array[0], array[1], array[2], array[3]);
+}
+
 static inline int4 get_int4(BL::Array<int, 4> array)
 {
 	return make_int4(array[0], array[1], array[2], array[3]);

Modified: trunk/blender/intern/cycles/kernel/kernel_object.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_object.h	2012-08-31 17:27:08 UTC (rev 50294)
+++ trunk/blender/intern/cycles/kernel/kernel_object.h	2012-08-31 19:38:59 UTC (rev 50295)
@@ -172,24 +172,61 @@
 __device_inline float particle_index(KernelGlobals *kg, int particle)
 {
 	int offset = particle*PARTICLE_SIZE;
-	float4 f = kernel_tex_fetch(__particles, offset);
+	float4 f = kernel_tex_fetch(__particles, offset + 0);
 	return f.x;
 }
 
 __device float particle_age(KernelGlobals *kg, int particle)
 {
 	int offset = particle*PARTICLE_SIZE;
-	float4 f = kernel_tex_fetch(__particles, offset);
+	float4 f = kernel_tex_fetch(__particles, offset + 0);
 	return f.y;
 }
 
 __device float particle_lifetime(KernelGlobals *kg, int particle)
 {
 	int offset = particle*PARTICLE_SIZE;
-	float4 f = kernel_tex_fetch(__particles, offset);
+	float4 f = kernel_tex_fetch(__particles, offset + 0);
 	return f.z;
 }
 
+__device float particle_size(KernelGlobals *kg, int particle)
+{
+	int offset = particle*PARTICLE_SIZE;
+	float4 f = kernel_tex_fetch(__particles, offset + 0);
+	return f.w;
+}
 
+__device float4 particle_rotation(KernelGlobals *kg, int particle)
+{
+	int offset = particle*PARTICLE_SIZE;
+	float4 f = kernel_tex_fetch(__particles, offset + 1);
+	return f;
+}
+
+__device float3 particle_location(KernelGlobals *kg, int particle)
+{
+	int offset = particle*PARTICLE_SIZE;
+	float4 f = kernel_tex_fetch(__particles, offset + 2);
+	return make_float3(f.x, f.y, f.z);
+}
+
+__device float3 particle_velocity(KernelGlobals *kg, int particle)
+{
+	int offset = particle*PARTICLE_SIZE;
+	float4 f2 = kernel_tex_fetch(__particles, offset + 2);
+	float4 f3 = kernel_tex_fetch(__particles, offset + 3);
+	return make_float3(f2.w, f3.x, f3.y);
+}
+
+__device float3 particle_angular_velocity(KernelGlobals *kg, int particle)
+{
+	int offset = particle*PARTICLE_SIZE;
+	float4 f3 = kernel_tex_fetch(__particles, offset + 3);
+	float4 f4 = kernel_tex_fetch(__particles, offset + 4);
+	return make_float3(f3.z, f3.w, f4.x);
+}
+
+
 CCL_NAMESPACE_END
 

Modified: trunk/blender/intern/cycles/kernel/kernel_types.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_types.h	2012-08-31 17:27:08 UTC (rev 50294)
+++ trunk/blender/intern/cycles/kernel/kernel_types.h	2012-08-31 19:38:59 UTC (rev 50295)
@@ -33,7 +33,7 @@
 #define LIGHT_SIZE			4
 #define FILTER_TABLE_SIZE	256
 #define RAMP_TABLE_SIZE		256
-#define PARTICLE_SIZE 		1
+#define PARTICLE_SIZE 		5
 #define TIME_INVALID		FLT_MAX
 
 /* device capabilities */

Modified: trunk/blender/intern/cycles/kernel/svm/svm_geometry.h
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm_geometry.h	2012-08-31 17:27:08 UTC (rev 50294)
+++ trunk/blender/intern/cycles/kernel/svm/svm_geometry.h	2012-08-31 19:38:59 UTC (rev 50295)
@@ -98,27 +98,49 @@
 
 __device void svm_node_particle_info(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
 {
-	float data;
-
 	switch(type) {
 		case NODE_INFO_PAR_INDEX: {
 			uint particle_id = object_particle_id(kg, sd->object);
-			data = particle_index(kg, particle_id);
-			stack_store_float(stack, out_offset, data);
+			stack_store_float(stack, out_offset, particle_index(kg, particle_id));
 			break;
 		}
 		case NODE_INFO_PAR_AGE: {
 			uint particle_id = object_particle_id(kg, sd->object);
-			data = particle_age(kg, particle_id);
-			stack_store_float(stack, out_offset, data);
+			stack_store_float(stack, out_offset, particle_age(kg, particle_id));
 			break;
 		}
 		case NODE_INFO_PAR_LIFETIME: {
 			uint particle_id = object_particle_id(kg, sd->object);
-			data = particle_lifetime(kg, particle_id);
-			stack_store_float(stack, out_offset, data);
+			stack_store_float(stack, out_offset, particle_lifetime(kg, particle_id));
 			break;
 		}
+		case NODE_INFO_PAR_LOCATION: {
+			uint particle_id = object_particle_id(kg, sd->object);
+			stack_store_float3(stack, out_offset, particle_location(kg, particle_id));
+			break;
+		}
+		#if 0	/* XXX float4 currently not supported in SVM stack */
+		case NODE_INFO_PAR_ROTATION: {
+			uint particle_id = object_particle_id(kg, sd->object);
+			stack_store_float4(stack, out_offset, particle_rotation(kg, particle_id));
+			break;
+		}
+		#endif
+		case NODE_INFO_PAR_SIZE: {
+			uint particle_id = object_particle_id(kg, sd->object);
+			stack_store_float(stack, out_offset, particle_size(kg, particle_id));
+			break;
+		}
+		case NODE_INFO_PAR_VELOCITY: {
+			uint particle_id = object_particle_id(kg, sd->object);
+			stack_store_float3(stack, out_offset, particle_velocity(kg, particle_id));
+			break;
+		}
+		case NODE_INFO_PAR_ANGULAR_VELOCITY: {
+			uint particle_id = object_particle_id(kg, sd->object);
+			stack_store_float3(stack, out_offset, particle_angular_velocity(kg, particle_id));
+			break;
+		}
 	}
 }
 

Modified: trunk/blender/intern/cycles/kernel/svm/svm_types.h
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm_types.h	2012-08-31 17:27:08 UTC (rev 50294)
+++ trunk/blender/intern/cycles/kernel/svm/svm_types.h	2012-08-31 19:38:59 UTC (rev 50295)
@@ -116,7 +116,12 @@
 typedef enum NodeParticleInfo {
 	NODE_INFO_PAR_INDEX,
 	NODE_INFO_PAR_AGE,
-	NODE_INFO_PAR_LIFETIME
+	NODE_INFO_PAR_LIFETIME,
+	NODE_INFO_PAR_LOCATION,
+	NODE_INFO_PAR_ROTATION,
+	NODE_INFO_PAR_SIZE,
+	NODE_INFO_PAR_VELOCITY,
+	NODE_INFO_PAR_ANGULAR_VELOCITY
 } NodeParticleInfo;
 
 typedef enum NodeLightPath {

Modified: trunk/blender/intern/cycles/render/nodes.cpp
===================================================================
--- trunk/blender/intern/cycles/render/nodes.cpp	2012-08-31 17:27:08 UTC (rev 50294)
+++ trunk/blender/intern/cycles/render/nodes.cpp	2012-08-31 19:38:59 UTC (rev 50295)
@@ -1801,6 +1801,13 @@
 	add_output("Index", SHADER_SOCKET_FLOAT);
 	add_output("Age", SHADER_SOCKET_FLOAT);
 	add_output("Lifetime", SHADER_SOCKET_FLOAT);
+	add_output("Location", SHADER_SOCKET_POINT);
+	#if 0	/* not yet supported */
+	add_output("Rotation", SHADER_SOCKET_QUATERNION);
+	#endif
+	add_output("Size", SHADER_SOCKET_FLOAT);
+	add_output("Velocity", SHADER_SOCKET_VECTOR);
+	add_output("Angular Velocity", SHADER_SOCKET_VECTOR);
 }
 
 void ParticleInfoNode::attributes(AttributeRequestSet *attributes)
@@ -1811,6 +1818,18 @@
 		attributes->add(ATTR_STD_PARTICLE);
 	if(!output("Lifetime")->links.empty())
 		attributes->add(ATTR_STD_PARTICLE);
+	if(!output("Location")->links.empty())
+		attributes->add(ATTR_STD_PARTICLE);
+	#if 0	/* not yet supported */
+	if(!output("Rotation")->links.empty())
+		attributes->add(ATTR_STD_PARTICLE);
+	#endif
+	if(!output("Size")->links.empty())
+		attributes->add(ATTR_STD_PARTICLE);
+	if(!output("Velocity")->links.empty())
+		attributes->add(ATTR_STD_PARTICLE);
+	if(!output("Angular Velocity")->links.empty())
+		attributes->add(ATTR_STD_PARTICLE);
 
 	ShaderNode::attributes(attributes);
 }
@@ -1836,6 +1855,38 @@
 		compiler.stack_assign(out);
 		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_LIFETIME, out->stack_offset);
 	}
+	
+	out = output("Location");
+	if(!out->links.empty()) {
+		compiler.stack_assign(out);
+		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_LOCATION, out->stack_offset);
+	}
+	
+	#if 0	/* XXX Quaternion data is not yet supported by Cycles */
+	out = output("Rotation");
+	if(!out->links.empty()) {
+		compiler.stack_assign(out);
+		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_ROTATION, out->stack_offset);
+	}
+	#endif
+	
+	out = output("Size");
+	if(!out->links.empty()) {
+		compiler.stack_assign(out);
+		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_SIZE, out->stack_offset);
+	}
+	
+	out = output("Velocity");
+	if(!out->links.empty()) {
+		compiler.stack_assign(out);
+		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_VELOCITY, out->stack_offset);
+	}
+	
+	out = output("Angular Velocity");
+	if(!out->links.empty()) {
+		compiler.stack_assign(out);
+		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_ANGULAR_VELOCITY, out->stack_offset);
+	}
 }
 
 void ParticleInfoNode::compile(OSLCompiler& compiler)

Modified: trunk/blender/intern/cycles/render/particles.cpp
===================================================================
--- trunk/blender/intern/cycles/render/particles.cpp	2012-08-31 17:27:08 UTC (rev 50294)
+++ trunk/blender/intern/cycles/render/particles.cpp	2012-08-31 19:38:59 UTC (rev 50295)
@@ -74,7 +74,11 @@
 			/* pack in texture */
 			int offset = i*PARTICLE_SIZE;
 			
-			particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, 0.0f);
+			particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, pa.size);
+			particles[offset+1] = pa.rotation;
+			particles[offset+2] = make_float4(pa.location.x, pa.location.y, pa.location.z, pa.velocity.x);
+			particles[offset+3] = make_float4(pa.velocity.y, pa.velocity.z, pa.angular_velocity.x, pa.angular_velocity.y);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list