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.
This commit is contained in:
Lukas Toenne 2012-09-14 19:09:25 +00:00
parent df79ab5a77
commit c4de45e56b
3 changed files with 126 additions and 16 deletions

@ -42,6 +42,7 @@ set(SRC_OSL
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

@ -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);
}

@ -256,34 +256,104 @@ static void get_object_attribute(const OSLGlobals::Attribute& attr, bool derivat
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;
}