2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
enum ObjectTransform {
|
|
|
|
OBJECT_TRANSFORM = 0,
|
2012-12-20 19:26:57 +00:00
|
|
|
OBJECT_TRANSFORM_MOTION_PRE = 0,
|
|
|
|
OBJECT_INVERSE_TRANSFORM = 4,
|
|
|
|
OBJECT_TRANSFORM_MOTION_POST = 4,
|
|
|
|
OBJECT_PROPERTIES = 8,
|
|
|
|
OBJECT_DUPLI = 9
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ObjectVectorTransform {
|
|
|
|
OBJECT_VECTOR_MOTION_PRE = 0,
|
|
|
|
OBJECT_VECTOR_MOTION_POST = 3
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2012-10-15 21:12:58 +00:00
|
|
|
__device_inline Transform object_fetch_transform(KernelGlobals *kg, int object, enum ObjectTransform type)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-10-15 21:12:58 +00:00
|
|
|
int offset = object*OBJECT_SIZE + (int)type;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
Transform tfm;
|
2012-10-15 21:12:58 +00:00
|
|
|
tfm.x = kernel_tex_fetch(__objects, offset + 0);
|
|
|
|
tfm.y = kernel_tex_fetch(__objects, offset + 1);
|
|
|
|
tfm.z = kernel_tex_fetch(__objects, offset + 2);
|
|
|
|
tfm.w = make_float4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
return tfm;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-12-20 19:26:57 +00:00
|
|
|
__device_inline Transform object_fetch_vector_transform(KernelGlobals *kg, int object, enum ObjectVectorTransform type)
|
|
|
|
{
|
|
|
|
int offset = object*OBJECT_VECTOR_SIZE + (int)type;
|
|
|
|
|
|
|
|
Transform tfm;
|
|
|
|
tfm.x = kernel_tex_fetch(__objects_vector, offset + 0);
|
|
|
|
tfm.y = kernel_tex_fetch(__objects_vector, offset + 1);
|
|
|
|
tfm.z = kernel_tex_fetch(__objects_vector, offset + 2);
|
|
|
|
tfm.w = make_float4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
return tfm;
|
|
|
|
}
|
|
|
|
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-10-17 22:48:29 +00:00
|
|
|
__device_inline Transform object_fetch_transform_motion(KernelGlobals *kg, int object, float time)
|
2012-10-15 21:12:58 +00:00
|
|
|
{
|
2012-11-29 00:43:50 +00:00
|
|
|
DecompMotionTransform motion;
|
2012-10-15 21:12:58 +00:00
|
|
|
|
2012-10-17 22:48:29 +00:00
|
|
|
int offset = object*OBJECT_SIZE + (int)OBJECT_TRANSFORM_MOTION_PRE;
|
2012-10-15 21:12:58 +00:00
|
|
|
|
2012-11-29 00:43:50 +00:00
|
|
|
motion.mid.x = kernel_tex_fetch(__objects, offset + 0);
|
|
|
|
motion.mid.y = kernel_tex_fetch(__objects, offset + 1);
|
|
|
|
motion.mid.z = kernel_tex_fetch(__objects, offset + 2);
|
|
|
|
motion.mid.w = kernel_tex_fetch(__objects, offset + 3);
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-11-29 00:43:50 +00:00
|
|
|
motion.pre_x = kernel_tex_fetch(__objects, offset + 4);
|
|
|
|
motion.pre_y = kernel_tex_fetch(__objects, offset + 5);
|
|
|
|
motion.post_x = kernel_tex_fetch(__objects, offset + 6);
|
|
|
|
motion.post_y = kernel_tex_fetch(__objects, offset + 7);
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-10-17 22:48:29 +00:00
|
|
|
Transform tfm;
|
|
|
|
transform_motion_interpolate(&tfm, &motion, time);
|
2012-10-15 21:12:58 +00:00
|
|
|
|
2012-10-17 22:48:29 +00:00
|
|
|
return tfm;
|
|
|
|
}
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-10-17 22:48:29 +00:00
|
|
|
__device_inline Transform object_fetch_transform_motion_test(KernelGlobals *kg, int object, float time, Transform *itfm)
|
|
|
|
{
|
|
|
|
int object_flag = kernel_tex_fetch(__object_flag, object);
|
|
|
|
|
|
|
|
if(object_flag & SD_OBJECT_MOTION) {
|
|
|
|
/* if we do motion blur */
|
|
|
|
Transform tfm = object_fetch_transform_motion(kg, object, time);
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-10-15 21:12:58 +00:00
|
|
|
if(itfm)
|
|
|
|
*itfm = transform_quick_inverse(tfm);
|
2012-10-17 22:48:29 +00:00
|
|
|
|
|
|
|
return tfm;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2012-10-15 21:12:58 +00:00
|
|
|
else {
|
2012-10-17 22:48:29 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
|
2012-11-04 22:31:32 +00:00
|
|
|
if(itfm)
|
|
|
|
*itfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-17 22:48:29 +00:00
|
|
|
return tfm;
|
2012-10-15 21:12:58 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-10-15 21:12:58 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
__device_inline void object_position_transform(KernelGlobals *kg, ShaderData *sd, float3 *P)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-04-30 12:49:26 +00:00
|
|
|
*P = transform_point(&sd->ob_tfm, *P);
|
|
|
|
#else
|
2012-10-15 21:12:58 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_TRANSFORM);
|
2012-04-16 08:35:21 +00:00
|
|
|
*P = transform_point(&tfm, *P);
|
2012-04-30 12:49:26 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-08 23:39:31 +00:00
|
|
|
__device_inline void object_inverse_position_transform(KernelGlobals *kg, ShaderData *sd, float3 *P)
|
|
|
|
{
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-05-08 23:39:31 +00:00
|
|
|
*P = transform_point(&sd->ob_itfm, *P);
|
|
|
|
#else
|
2012-10-15 21:12:58 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_INVERSE_TRANSFORM);
|
2012-05-08 23:39:31 +00:00
|
|
|
*P = transform_point(&tfm, *P);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-05-02 09:33:45 +00:00
|
|
|
__device_inline void object_inverse_normal_transform(KernelGlobals *kg, ShaderData *sd, float3 *N)
|
|
|
|
{
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-05-02 09:33:45 +00:00
|
|
|
*N = normalize(transform_direction_transposed(&sd->ob_tfm, *N));
|
|
|
|
#else
|
2012-10-15 21:12:58 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_TRANSFORM);
|
2012-05-02 09:33:45 +00:00
|
|
|
*N = normalize(transform_direction_transposed(&tfm, *N));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
__device_inline void object_normal_transform(KernelGlobals *kg, ShaderData *sd, float3 *N)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-04-30 12:49:26 +00:00
|
|
|
*N = normalize(transform_direction_transposed(&sd->ob_itfm, *N));
|
|
|
|
#else
|
2012-10-15 21:12:58 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_INVERSE_TRANSFORM);
|
2012-04-30 12:49:26 +00:00
|
|
|
*N = normalize(transform_direction_transposed(&tfm, *N));
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
__device_inline void object_dir_transform(KernelGlobals *kg, ShaderData *sd, float3 *D)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-04-30 12:49:26 +00:00
|
|
|
*D = transform_direction(&sd->ob_tfm, *D);
|
|
|
|
#else
|
2012-10-15 21:12:58 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_TRANSFORM);
|
2011-04-27 11:58:34 +00:00
|
|
|
*D = transform_direction(&tfm, *D);
|
2012-04-30 12:49:26 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-21 12:52:28 +00:00
|
|
|
__device_inline float3 object_location(KernelGlobals *kg, ShaderData *sd)
|
|
|
|
{
|
2012-10-16 13:20:57 +00:00
|
|
|
if(sd->object == ~0)
|
|
|
|
return make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-05-21 12:52:28 +00:00
|
|
|
return make_float3(sd->ob_tfm.x.w, sd->ob_tfm.y.w, sd->ob_tfm.z.w);
|
|
|
|
#else
|
2012-10-15 21:12:58 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_TRANSFORM);
|
2012-05-21 12:52:28 +00:00
|
|
|
return make_float3(tfm.x.w, tfm.y.w, tfm.z.w);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
__device_inline float object_surface_area(KernelGlobals *kg, int object)
|
|
|
|
{
|
|
|
|
int offset = object*OBJECT_SIZE + OBJECT_PROPERTIES;
|
|
|
|
float4 f = kernel_tex_fetch(__objects, offset);
|
|
|
|
return f.x;
|
|
|
|
}
|
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
__device_inline float object_pass_id(KernelGlobals *kg, int object)
|
|
|
|
{
|
|
|
|
if(object == ~0)
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
int offset = object*OBJECT_SIZE + OBJECT_PROPERTIES;
|
|
|
|
float4 f = kernel_tex_fetch(__objects, offset);
|
|
|
|
return f.y;
|
|
|
|
}
|
|
|
|
|
2012-05-21 12:52:28 +00:00
|
|
|
__device_inline float object_random_number(KernelGlobals *kg, int object)
|
|
|
|
{
|
|
|
|
if(object == ~0)
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
int offset = object*OBJECT_SIZE + OBJECT_PROPERTIES;
|
|
|
|
float4 f = kernel_tex_fetch(__objects, offset);
|
|
|
|
return f.z;
|
|
|
|
}
|
|
|
|
|
2012-06-08 16:17:57 +00:00
|
|
|
__device_inline uint object_particle_id(KernelGlobals *kg, int object)
|
|
|
|
{
|
|
|
|
if(object == ~0)
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
int offset = object*OBJECT_SIZE + OBJECT_PROPERTIES;
|
|
|
|
float4 f = kernel_tex_fetch(__objects, offset);
|
2013-06-07 16:06:17 +00:00
|
|
|
return __float_as_uint(f.w);
|
2012-06-08 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
2012-10-04 21:40:39 +00:00
|
|
|
__device_inline float3 object_dupli_generated(KernelGlobals *kg, int object)
|
|
|
|
{
|
|
|
|
if(object == ~0)
|
|
|
|
return make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
int offset = object*OBJECT_SIZE + OBJECT_DUPLI;
|
|
|
|
float4 f = kernel_tex_fetch(__objects, offset);
|
|
|
|
return make_float3(f.x, f.y, f.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
__device_inline float3 object_dupli_uv(KernelGlobals *kg, int object)
|
|
|
|
{
|
|
|
|
if(object == ~0)
|
|
|
|
return make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
int offset = object*OBJECT_SIZE + OBJECT_DUPLI;
|
|
|
|
float4 f = kernel_tex_fetch(__objects, offset + 1);
|
|
|
|
return make_float3(f.x, f.y, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-21 12:52:28 +00:00
|
|
|
__device int shader_pass_id(KernelGlobals *kg, ShaderData *sd)
|
|
|
|
{
|
|
|
|
return kernel_tex_fetch(__shader_flag, (sd->shader & SHADER_MASK)*2 + 1);
|
|
|
|
}
|
|
|
|
|
2012-07-26 11:40:58 +00:00
|
|
|
__device_inline float particle_index(KernelGlobals *kg, int particle)
|
2012-06-08 16:17:57 +00:00
|
|
|
{
|
|
|
|
int offset = particle*PARTICLE_SIZE;
|
2012-08-31 19:38:59 +00:00
|
|
|
float4 f = kernel_tex_fetch(__particles, offset + 0);
|
2012-06-08 16:17:57 +00:00
|
|
|
return f.x;
|
|
|
|
}
|
|
|
|
|
2012-07-26 11:40:58 +00:00
|
|
|
__device float particle_age(KernelGlobals *kg, int particle)
|
2012-06-08 16:17:57 +00:00
|
|
|
{
|
|
|
|
int offset = particle*PARTICLE_SIZE;
|
2012-08-31 19:38:59 +00:00
|
|
|
float4 f = kernel_tex_fetch(__particles, offset + 0);
|
2012-06-08 16:17:57 +00:00
|
|
|
return f.y;
|
|
|
|
}
|
|
|
|
|
2012-07-26 11:40:58 +00:00
|
|
|
__device float particle_lifetime(KernelGlobals *kg, int particle)
|
|
|
|
{
|
|
|
|
int offset = particle*PARTICLE_SIZE;
|
2012-08-31 19:38:59 +00:00
|
|
|
float4 f = kernel_tex_fetch(__particles, offset + 0);
|
2012-07-26 11:40:58 +00:00
|
|
|
return f.z;
|
|
|
|
}
|
|
|
|
|
2012-08-31 19:38:59 +00:00
|
|
|
__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);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|