[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50604] trunk/blender/intern/cycles/kernel /osl: Implemented the Particle Info for OSL.
Lukas Toenne
lukas.toenne at googlemail.com
Fri Sep 14 21:09:25 CEST 2012
Revision: 50604
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50604
Author: lukastoenne
Date: 2012-09-14 19:09:25 +0000 (Fri, 14 Sep 2012)
Log Message:
-----------
Implemented the Particle Info for OSL. Uses the following attributes:
* std::particle_index
* std::particle_age
* std::particle_lifetime
* std::particle_location
* std::particle_size
* std::particle_velocity
* std::particle_angular_velocity
Just as with SVM the rotation state attribute is currently disabled due to lack of a proper quaternion or matrix type in Cycles nodes.
Modified Paths:
--------------
trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt
trunk/blender/intern/cycles/kernel/osl/osl_services.cpp
Added Paths:
-----------
trunk/blender/intern/cycles/kernel/osl/nodes/node_particle_info.osl
Modified: trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt 2012-09-14 18:10:54 UTC (rev 50603)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt 2012-09-14 19:09:25 UTC (rev 50604)
@@ -42,6 +42,7 @@
node_output_displacement.osl
node_output_surface.osl
node_output_volume.osl
+ node_particle_info.osl
node_separate_rgb.osl
node_sky_texture.osl
node_texture_coordinate.osl
Added: trunk/blender/intern/cycles/kernel/osl/nodes/node_particle_info.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/node_particle_info.osl (rev 0)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/node_particle_info.osl 2012-09-14 19:09:25 UTC (rev 50604)
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * 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.
+ */
+
+#include "stdosl.h"
+
+shader node_particle_info(
+ output float Index = 0.0,
+ output float Age = 0.0,
+ output float Lifetime = 0.0,
+ output point Location = point(0.0, 0.0, 0.0),
+ output float Size = 0.0,
+ output vector Velocity = point(0.0, 0.0, 0.0),
+ output vector AngularVelocity = point(0.0, 0.0, 0.0)
+ )
+{
+ getattribute("std::particle_index", Index);
+ getattribute("std::particle_age", Age);
+ getattribute("std::particle_lifetime", Lifetime);
+ getattribute("std::particle_location", Location);
+ getattribute("std::particle_size", Size);
+ getattribute("std::particle_velocity", Velocity);
+ getattribute("std::particle_angular_velocity", AngularVelocity);
+}
+
Modified: trunk/blender/intern/cycles/kernel/osl/osl_services.cpp
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/osl_services.cpp 2012-09-14 18:10:54 UTC (rev 50603)
+++ trunk/blender/intern/cycles/kernel/osl/osl_services.cpp 2012-09-14 19:09:25 UTC (rev 50604)
@@ -256,34 +256,104 @@
static bool get_object_standard_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
TypeDesc type, bool derivatives, void *val)
{
+ /* Object Attributes */
if (name == "std::object_location") {
- float3 loc[3];
- loc[0] = object_location(kg, sd);
- loc[1] = loc[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */
- set_attribute_float3(loc, type, derivatives, val);
+ float3 fval[3];
+ fval[0] = object_location(kg, sd);
+ fval[1] = fval[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */
+ set_attribute_float3(fval, type, derivatives, val);
return true;
}
else if (name == "std::object_index") {
- float loc[3];
- loc[0] = object_pass_id(kg, sd->object);
- loc[1] = loc[2] = 0.0; /* derivates set to 0 */
- set_attribute_float(loc, type, derivatives, val);
+ float fval[3];
+ fval[0] = object_pass_id(kg, sd->object);
+ fval[1] = fval[2] = 0.0; /* derivates set to 0 */
+ set_attribute_float(fval, type, derivatives, val);
return true;
}
else if (name == "std::material_index") {
- float loc[3];
- loc[0] = shader_pass_id(kg, sd);
- loc[1] = loc[2] = 0.0; /* derivates set to 0 */
- set_attribute_float(loc, type, derivatives, val);
+ float fval[3];
+ fval[0] = shader_pass_id(kg, sd);
+ fval[1] = fval[2] = 0.0; /* derivates set to 0 */
+ set_attribute_float(fval, type, derivatives, val);
return true;
}
else if (name == "std::object_random") {
- float loc[3];
- loc[0] = object_random_number(kg, sd->object);
- loc[1] = loc[2] = 0.0; /* derivates set to 0 */
- set_attribute_float(loc, type, derivatives, val);
+ float fval[3];
+ fval[0] = object_random_number(kg, sd->object);
+ fval[1] = fval[2] = 0.0; /* derivates set to 0 */
+ set_attribute_float(fval, type, derivatives, val);
return true;
}
+
+ /* Particle Attributes */
+ else if (name == "std::particle_index") {
+ float fval[3];
+ uint particle_id = object_particle_id(kg, sd->object);
+ fval[0] = particle_index(kg, particle_id);
+ fval[1] = fval[2] = 0.0; /* derivates set to 0 */
+ set_attribute_float(fval, type, derivatives, val);
+ return true;
+ }
+ else if (name == "std::particle_age") {
+ float fval[3];
+ uint particle_id = object_particle_id(kg, sd->object);
+ fval[0] = particle_age(kg, particle_id);
+ fval[1] = fval[2] = 0.0; /* derivates set to 0 */
+ set_attribute_float(fval, type, derivatives, val);
+ return true;
+ }
+ else if (name == "std::particle_lifetime") {
+ float fval[3];
+ uint particle_id = object_particle_id(kg, sd->object);
+ fval[0] = particle_lifetime(kg, particle_id);
+ fval[1] = fval[2] = 0.0; /* derivates set to 0 */
+ set_attribute_float(fval, type, derivatives, val);
+ return true;
+ }
+ else if (name == "std::particle_location") {
+ float3 fval[3];
+ uint particle_id = object_particle_id(kg, sd->object);
+ fval[0] = particle_location(kg, particle_id);
+ fval[1] = fval[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */
+ set_attribute_float3(fval, type, derivatives, val);
+ return true;
+ }
+#if 0 /* unsupported */
+ else if (name == "std::particle_rotation") {
+ float4 fval[3];
+ uint particle_id = object_particle_id(kg, sd->object);
+ fval[0] = particle_rotation(kg, particle_id);
+ fval[1] = fval[2] = make_float4(0.0, 0.0, 0.0, 0.0); /* derivates set to 0 */
+ set_attribute_float4(fval, type, derivatives, val);
+ return true;
+ }
+#endif
+ else if (name == "std::particle_size") {
+ float fval[3];
+ uint particle_id = object_particle_id(kg, sd->object);
+ fval[0] = particle_size(kg, particle_id);
+ fval[1] = fval[2] = 0.0; /* derivates set to 0 */
+ set_attribute_float(fval, type, derivatives, val);
+ return true;
+ }
+ else if (name == "std::particle_velocity") {
+ float3 fval[3];
+ uint particle_id = object_particle_id(kg, sd->object);
+ fval[0] = particle_velocity(kg, particle_id);
+ fval[1] = fval[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */
+ set_attribute_float3(fval, type, derivatives, val);
+ return true;
+ }
+ else if (name == "std::particle_angular_velocity") {
+ float3 fval[3];
+ uint particle_id = object_particle_id(kg, sd->object);
+ fval[0] = particle_angular_velocity(kg, particle_id);
+ fval[1] = fval[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */
+ set_attribute_float3(fval, type, derivatives, val);
+ return true;
+ }
+
else
return false;
}
More information about the Bf-blender-cvs
mailing list