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-04-30 12:49:26 +00:00
|
|
|
OBJECT_INVERSE_TRANSFORM = 3,
|
|
|
|
OBJECT_PROPERTIES = 6,
|
|
|
|
OBJECT_TRANSFORM_MOTION_PRE = 8,
|
|
|
|
OBJECT_TRANSFORM_MOTION_POST = 12
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
__device_inline Transform object_fetch_transform(KernelGlobals *kg, int object, float time, enum ObjectTransform type)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Transform tfm;
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
#ifdef __MOTION__
|
|
|
|
/* if we do motion blur */
|
2012-05-02 09:33:45 +00:00
|
|
|
if(sd->flag & SD_OBJECT_MOTION) {
|
|
|
|
/* fetch motion transforms */
|
|
|
|
MotionTransform motion;
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-05-02 09:33:45 +00:00
|
|
|
motion.pre.x = have_motion;
|
|
|
|
motion.pre.y = kernel_tex_fetch(__objects, offset + 1);
|
|
|
|
motion.pre.z = kernel_tex_fetch(__objects, offset + 2);
|
|
|
|
motion.pre.w = kernel_tex_fetch(__objects, offset + 3);
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-05-02 09:33:45 +00:00
|
|
|
motion.post.x = kernel_tex_fetch(__objects, offset + 4);
|
|
|
|
motion.post.y = kernel_tex_fetch(__objects, offset + 5);
|
|
|
|
motion.post.z = kernel_tex_fetch(__objects, offset + 6);
|
|
|
|
motion.post.w = kernel_tex_fetch(__objects, offset + 7);
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-05-02 09:33:45 +00:00
|
|
|
/* interpolate (todo: do only once per object) */
|
|
|
|
transform_motion_interpolate(&tfm, &motion, time);
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-05-02 09:33:45 +00:00
|
|
|
/* invert */
|
|
|
|
if(type == OBJECT_INVERSE_TRANSFORM)
|
|
|
|
tfm = transform_quick_inverse(tfm);
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-05-02 09:33:45 +00:00
|
|
|
return tfm;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
int offset = object*OBJECT_SIZE + (int)type;
|
|
|
|
|
|
|
|
tfm.x = kernel_tex_fetch(__objects, offset + 0);
|
|
|
|
tfm.y = kernel_tex_fetch(__objects, offset + 1);
|
|
|
|
tfm.z = kernel_tex_fetch(__objects, offset + 2);
|
2012-04-30 12:49:26 +00:00
|
|
|
tfm.w = make_float4(0.0f, 0.0f, 0.0f, 1.0f);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return tfm;
|
|
|
|
}
|
|
|
|
|
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-04-30 12:49:26 +00:00
|
|
|
#ifdef __MOTION__
|
|
|
|
*P = transform_point(&sd->ob_tfm, *P);
|
|
|
|
#else
|
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, TIME_INVALID, 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)
|
|
|
|
{
|
|
|
|
#ifdef __MOTION__
|
|
|
|
*P = transform_point(&sd->ob_itfm, *P);
|
|
|
|
#else
|
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, TIME_INVALID, OBJECT_INVERSE_TRANSFORM);
|
|
|
|
*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)
|
|
|
|
{
|
|
|
|
#ifdef __MOTION__
|
|
|
|
*N = normalize(transform_direction_transposed(&sd->ob_tfm, *N));
|
|
|
|
#else
|
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, TIME_INVALID, OBJECT_TRANSFORM);
|
|
|
|
*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-04-30 12:49:26 +00:00
|
|
|
#ifdef __MOTION__
|
|
|
|
*N = normalize(transform_direction_transposed(&sd->ob_itfm, *N));
|
|
|
|
#else
|
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, TIME_INVALID, OBJECT_INVERSE_TRANSFORM);
|
|
|
|
*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-04-30 12:49:26 +00:00
|
|
|
#ifdef __MOTION__
|
|
|
|
*D = transform_direction(&sd->ob_tfm, *D);
|
|
|
|
#else
|
|
|
|
Transform tfm = object_fetch_transform(kg, sd->object, 0.0f, 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
|
|
|
}
|
|
|
|
|
|
|
|
__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;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|