Blender V2.61 - r43446
|
00001 /* 00002 * Copyright 2011, Blender Foundation. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 CCL_NAMESPACE_BEGIN 00020 00021 enum ObjectTransform { 00022 OBJECT_TRANSFORM = 0, 00023 OBJECT_INVERSE_TRANSFORM = 4, 00024 OBJECT_NORMAL_TRANSFORM = 8, 00025 OBJECT_PROPERTIES = 12 00026 }; 00027 00028 __device_inline Transform object_fetch_transform(KernelGlobals *kg, int object, enum ObjectTransform type) 00029 { 00030 Transform tfm; 00031 00032 int offset = object*OBJECT_SIZE + (int)type; 00033 00034 tfm.x = kernel_tex_fetch(__objects, offset + 0); 00035 tfm.y = kernel_tex_fetch(__objects, offset + 1); 00036 tfm.z = kernel_tex_fetch(__objects, offset + 2); 00037 tfm.w = kernel_tex_fetch(__objects, offset + 3); 00038 00039 return tfm; 00040 } 00041 00042 __device_inline void object_position_transform(KernelGlobals *kg, int object, float3 *P) 00043 { 00044 Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM); 00045 *P = transform(&tfm, *P); 00046 } 00047 00048 __device_inline void object_normal_transform(KernelGlobals *kg, int object, float3 *N) 00049 { 00050 Transform tfm = object_fetch_transform(kg, object, OBJECT_NORMAL_TRANSFORM); 00051 *N = normalize(transform_direction(&tfm, *N)); 00052 } 00053 00054 __device_inline void object_dir_transform(KernelGlobals *kg, int object, float3 *D) 00055 { 00056 Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM); 00057 *D = transform_direction(&tfm, *D); 00058 } 00059 00060 __device_inline float object_surface_area(KernelGlobals *kg, int object) 00061 { 00062 int offset = object*OBJECT_SIZE + OBJECT_PROPERTIES; 00063 float4 f = kernel_tex_fetch(__objects, offset); 00064 return f.x; 00065 } 00066 00067 CCL_NAMESPACE_END 00068