forked from bartvdbraak/blender
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:
parent
df79ab5a77
commit
c4de45e56b
@ -42,6 +42,7 @@ set(SRC_OSL
|
|||||||
node_output_displacement.osl
|
node_output_displacement.osl
|
||||||
node_output_surface.osl
|
node_output_surface.osl
|
||||||
node_output_volume.osl
|
node_output_volume.osl
|
||||||
|
node_particle_info.osl
|
||||||
node_separate_rgb.osl
|
node_separate_rgb.osl
|
||||||
node_sky_texture.osl
|
node_sky_texture.osl
|
||||||
node_texture_coordinate.osl
|
node_texture_coordinate.osl
|
||||||
|
39
intern/cycles/kernel/osl/nodes/node_particle_info.osl
Normal file
39
intern/cycles/kernel/osl/nodes/node_particle_info.osl
Normal file
@ -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,
|
static bool get_object_standard_attribute(KernelGlobals *kg, ShaderData *sd, ustring name,
|
||||||
TypeDesc type, bool derivatives, void *val)
|
TypeDesc type, bool derivatives, void *val)
|
||||||
{
|
{
|
||||||
|
/* Object Attributes */
|
||||||
if (name == "std::object_location") {
|
if (name == "std::object_location") {
|
||||||
float3 loc[3];
|
float3 fval[3];
|
||||||
loc[0] = object_location(kg, sd);
|
fval[0] = object_location(kg, sd);
|
||||||
loc[1] = loc[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */
|
fval[1] = fval[2] = make_float3(0.0, 0.0, 0.0); /* derivates set to 0 */
|
||||||
set_attribute_float3(loc, type, derivatives, val);
|
set_attribute_float3(fval, type, derivatives, val);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (name == "std::object_index") {
|
else if (name == "std::object_index") {
|
||||||
float loc[3];
|
float fval[3];
|
||||||
loc[0] = object_pass_id(kg, sd->object);
|
fval[0] = object_pass_id(kg, sd->object);
|
||||||
loc[1] = loc[2] = 0.0; /* derivates set to 0 */
|
fval[1] = fval[2] = 0.0; /* derivates set to 0 */
|
||||||
set_attribute_float(loc, type, derivatives, val);
|
set_attribute_float(fval, type, derivatives, val);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (name == "std::material_index") {
|
else if (name == "std::material_index") {
|
||||||
float loc[3];
|
float fval[3];
|
||||||
loc[0] = shader_pass_id(kg, sd);
|
fval[0] = shader_pass_id(kg, sd);
|
||||||
loc[1] = loc[2] = 0.0; /* derivates set to 0 */
|
fval[1] = fval[2] = 0.0; /* derivates set to 0 */
|
||||||
set_attribute_float(loc, type, derivatives, val);
|
set_attribute_float(fval, type, derivatives, val);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (name == "std::object_random") {
|
else if (name == "std::object_random") {
|
||||||
float loc[3];
|
float fval[3];
|
||||||
loc[0] = object_random_number(kg, sd->object);
|
fval[0] = object_random_number(kg, sd->object);
|
||||||
loc[1] = loc[2] = 0.0; /* derivates set to 0 */
|
fval[1] = fval[2] = 0.0; /* derivates set to 0 */
|
||||||
set_attribute_float(loc, type, derivatives, val);
|
set_attribute_float(fval, type, derivatives, val);
|
||||||
return true;
|
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
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user