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 #ifndef __KERNEL_TYPES_H__ 00020 #define __KERNEL_TYPES_H__ 00021 00022 #include "kernel_math.h" 00023 00024 #include "svm/svm_types.h" 00025 00026 CCL_NAMESPACE_BEGIN 00027 00028 /* constants */ 00029 #define OBJECT_SIZE 16 00030 #define LIGHT_SIZE 4 00031 #define FILTER_TABLE_SIZE 256 00032 00033 /* device capabilities */ 00034 #ifdef __KERNEL_CPU__ 00035 #define __KERNEL_SHADING__ 00036 #define __KERNEL_ADV_SHADING__ 00037 #endif 00038 00039 #ifdef __KERNEL_CUDA__ 00040 #define __KERNEL_SHADING__ 00041 #if __CUDA_ARCH__ >= 200 00042 #define __KERNEL_ADV_SHADING__ 00043 #endif 00044 #endif 00045 00046 #ifdef __KERNEL_OPENCL__ 00047 //#define __KERNEL_SHADING__ 00048 //#define __KERNEL_ADV_SHADING__ 00049 #endif 00050 00051 /* kernel features */ 00052 #define __SOBOL__ 00053 #define __INSTANCING__ 00054 #define __DPDU__ 00055 #define __UV__ 00056 #define __BACKGROUND__ 00057 #define __CAUSTICS_TRICKS__ 00058 #define __VISIBILITY_FLAG__ 00059 #define __RAY_DIFFERENTIALS__ 00060 #define __CAMERA_CLIPPING__ 00061 #define __INTERSECTION_REFINE__ 00062 00063 #ifdef __KERNEL_SHADING__ 00064 #define __SVM__ 00065 #define __EMISSION__ 00066 #define __TEXTURES__ 00067 #define __HOLDOUT__ 00068 #endif 00069 00070 #ifdef __KERNEL_ADV_SHADING__ 00071 #define __MULTI_CLOSURE__ 00072 #define __TRANSPARENT_SHADOWS__ 00073 #endif 00074 00075 #define __SVM__ 00076 #define __EMISSION__ 00077 //#define __MULTI_LIGHT__ 00078 //#define __OSL__ 00079 //#define __SOBOL_FULL_SCREEN__ 00080 //#define __MODIFY_TP__ 00081 //#define __QBVH__ 00082 00083 /* Shader Evaluation */ 00084 00085 enum ShaderEvalType { 00086 SHADER_EVAL_DISPLACE, 00087 SHADER_EVAL_BACKGROUND 00088 }; 00089 00090 /* Path Tracing */ 00091 00092 enum PathTraceDimension { 00093 PRNG_FILTER_U = 0, 00094 PRNG_FILTER_V = 1, 00095 PRNG_LENS_U = 2, 00096 PRNG_LENS_V = 3, 00097 PRNG_BASE_NUM = 4, 00098 00099 PRNG_BSDF_U = 0, 00100 PRNG_BSDF_V = 1, 00101 PRNG_BSDF = 2, 00102 PRNG_LIGHT = 3, 00103 PRNG_LIGHT_U = 4, 00104 PRNG_LIGHT_V = 5, 00105 PRNG_LIGHT_F = 6, 00106 PRNG_TERMINATE = 7, 00107 PRNG_BOUNCE_NUM = 8 00108 }; 00109 00110 /* these flag values correspond exactly to OSL defaults, so be careful not to 00111 * change this, or if you do, set the "raytypes" shading system attribute with 00112 * your own new ray types and bitflag values. 00113 * 00114 * for ray visibility tests in BVH traversal, the upper 20 bits are used for 00115 * layer visibility tests. */ 00116 00117 enum PathRayFlag { 00118 PATH_RAY_CAMERA = 1, 00119 PATH_RAY_REFLECT = 2, 00120 PATH_RAY_TRANSMIT = 4, 00121 PATH_RAY_DIFFUSE = 8, 00122 PATH_RAY_GLOSSY = 16, 00123 PATH_RAY_SINGULAR = 32, 00124 PATH_RAY_TRANSPARENT = 64, 00125 00126 PATH_RAY_SHADOW_OPAQUE = 128, 00127 PATH_RAY_SHADOW_TRANSPARENT = 256, 00128 PATH_RAY_SHADOW = (PATH_RAY_SHADOW_OPAQUE|PATH_RAY_SHADOW_TRANSPARENT), 00129 00130 PATH_RAY_MIS_SKIP = 512, 00131 00132 PATH_RAY_ALL = (1|2|4|8|16|32|64|128|256|512), 00133 00134 PATH_RAY_LAYER_SHIFT = (32-20) 00135 }; 00136 00137 /* Closure Label */ 00138 00139 typedef enum ClosureLabel { 00140 LABEL_NONE = 0, 00141 LABEL_CAMERA = 1, 00142 LABEL_LIGHT = 2, 00143 LABEL_BACKGROUND = 4, 00144 LABEL_TRANSMIT = 8, 00145 LABEL_REFLECT = 16, 00146 LABEL_VOLUME = 32, 00147 LABEL_OBJECT = 64, 00148 LABEL_DIFFUSE = 128, 00149 LABEL_GLOSSY = 256, 00150 LABEL_SINGULAR = 512, 00151 LABEL_TRANSPARENT = 1024, 00152 LABEL_STOP = 2048 00153 } ClosureLabel; 00154 00155 /* Shader Flag */ 00156 00157 typedef enum ShaderFlag { 00158 SHADER_SMOOTH_NORMAL = (1 << 31), 00159 SHADER_CAST_SHADOW = (1 << 30), 00160 SHADER_AREA_LIGHT = (1 << 29), 00161 00162 SHADER_MASK = ~(SHADER_SMOOTH_NORMAL|SHADER_CAST_SHADOW|SHADER_AREA_LIGHT) 00163 } ShaderFlag; 00164 00165 /* Light Type */ 00166 00167 typedef enum LightType { 00168 LIGHT_POINT, 00169 LIGHT_DISTANT, 00170 LIGHT_AREA 00171 } LightType; 00172 00173 /* Differential */ 00174 00175 typedef struct differential3 { 00176 float3 dx; 00177 float3 dy; 00178 } differential3; 00179 00180 typedef struct differential { 00181 float dx; 00182 float dy; 00183 } differential; 00184 00185 /* Ray */ 00186 00187 typedef struct Ray { 00188 float3 P; 00189 float3 D; 00190 float t; 00191 00192 #ifdef __RAY_DIFFERENTIALS__ 00193 differential3 dP; 00194 differential3 dD; 00195 #endif 00196 } Ray; 00197 00198 /* Intersection */ 00199 00200 typedef struct Intersection { 00201 float t, u, v; 00202 int prim; 00203 int object; 00204 } Intersection; 00205 00206 /* Attributes */ 00207 00208 typedef enum AttributeElement { 00209 ATTR_ELEMENT_FACE, 00210 ATTR_ELEMENT_VERTEX, 00211 ATTR_ELEMENT_CORNER, 00212 ATTR_ELEMENT_VALUE, 00213 ATTR_ELEMENT_NONE 00214 } AttributeElement; 00215 00216 /* Closure data */ 00217 00218 #define MAX_CLOSURE 8 00219 00220 typedef struct ShaderClosure { 00221 ClosureType type; 00222 float3 weight; 00223 00224 #ifdef __MULTI_CLOSURE__ 00225 float sample_weight; 00226 #endif 00227 00228 #ifdef __OSL__ 00229 void *prim; 00230 #else 00231 float data0; 00232 float data1; 00233 #endif 00234 00235 } ShaderClosure; 00236 00237 /* Shader Data 00238 * 00239 * Main shader state at a point on the surface or in a volume. All coordinates 00240 * are in world space. */ 00241 00242 enum ShaderDataFlag { 00243 /* runtime flags */ 00244 SD_BACKFACING = 1, /* backside of surface? */ 00245 SD_EMISSION = 2, /* have emissive closure? */ 00246 SD_BSDF = 4, /* have bsdf closure? */ 00247 SD_BSDF_HAS_EVAL = 8, /* have non-singular bsdf closure? */ 00248 SD_BSDF_GLOSSY = 16, /* have glossy bsdf */ 00249 SD_HOLDOUT = 32, /* have holdout closure? */ 00250 SD_VOLUME = 64, /* have volume closure? */ 00251 00252 /* shader flags */ 00253 SD_SAMPLE_AS_LIGHT = 128, /* direct light sample */ 00254 SD_HAS_SURFACE_TRANSPARENT = 256, /* has surface transparency */ 00255 SD_HAS_VOLUME = 512, /* has volume shader */ 00256 SD_HOMOGENEOUS_VOLUME = 1024 /* has homogeneous volume */ 00257 }; 00258 00259 typedef struct ShaderData { 00260 /* position */ 00261 float3 P; 00262 /* smooth normal for shading */ 00263 float3 N; 00264 /* true geometric normal */ 00265 float3 Ng; 00266 /* view/incoming direction */ 00267 float3 I; 00268 /* shader id */ 00269 int shader; 00270 /* booleans describing shader, see ShaderDataFlag */ 00271 int flag; 00272 00273 /* primitive id if there is one, ~0 otherwise */ 00274 int prim; 00275 /* parametric coordinates 00276 * - barycentric weights for triangles */ 00277 float u, v; 00278 /* object id if there is one, ~0 otherwise */ 00279 int object; 00280 00281 #ifdef __RAY_DIFFERENTIALS__ 00282 /* differential of P. these are orthogonal to Ng, not N */ 00283 differential3 dP; 00284 /* differential of I */ 00285 differential3 dI; 00286 /* differential of u, v */ 00287 differential du; 00288 differential dv; 00289 #endif 00290 #ifdef __DPDU__ 00291 /* differential of P w.r.t. parametric coordinates. note that dPdu is 00292 * not readily suitable as a tangent for shading on triangles. */ 00293 float3 dPdu, dPdv; 00294 #endif 00295 00296 #ifdef __MULTI_CLOSURE__ 00297 /* Closure data, we store a fixed array of closures */ 00298 ShaderClosure closure[MAX_CLOSURE]; 00299 int num_closure; 00300 float randb_closure; 00301 #else 00302 /* Closure data, with a single sampled closure for low memory usage */ 00303 ShaderClosure closure; 00304 #endif 00305 00306 #ifdef __OSL__ 00307 /* OSL context */ 00308 void *osl_ctx; 00309 #endif 00310 } ShaderData; 00311 00312 /* Constrant Kernel Data 00313 * 00314 * These structs are passed from CPU to various devices, and the struct layout 00315 * must match exactly. Structs are padded to ensure 16 byte alignment, and we 00316 * do not use float3 because its size may not be the same on all devices. */ 00317 00318 typedef struct KernelCamera { 00319 /* type */ 00320 int ortho; 00321 int pad1, pad2, pad3; 00322 00323 /* matrices */ 00324 Transform cameratoworld; 00325 Transform rastertocamera; 00326 00327 /* differentials */ 00328 float4 dx; 00329 float4 dy; 00330 00331 /* depth of field */ 00332 float aperturesize; 00333 float blades; 00334 float bladesrotation; 00335 float focaldistance; 00336 00337 /* motion blur */ 00338 float shutteropen; 00339 float shutterclose; 00340 00341 /* clipping */ 00342 float nearclip; 00343 float cliplength; 00344 00345 /* more matrices */ 00346 Transform screentoworld; 00347 Transform rastertoworld; 00348 Transform ndctoworld; 00349 Transform worldtoscreen; 00350 Transform worldtoraster; 00351 Transform worldtondc; 00352 Transform worldtocamera; 00353 } KernelCamera; 00354 00355 typedef struct KernelFilm { 00356 float exposure; 00357 int pad1, pad2, pad3; 00358 } KernelFilm; 00359 00360 typedef struct KernelBackground { 00361 /* only shader index */ 00362 int shader; 00363 int transparent; 00364 int pad1, pad2; 00365 } KernelBackground; 00366 00367 typedef struct KernelSunSky { 00368 /* sun direction in spherical and cartesian */ 00369 float theta, phi, pad3, pad4; 00370 00371 /* perez function parameters */ 00372 float zenith_Y, zenith_x, zenith_y, pad2; 00373 float perez_Y[5], perez_x[5], perez_y[5]; 00374 float pad5; 00375 } KernelSunSky; 00376 00377 typedef struct KernelIntegrator { 00378 /* emission */ 00379 int use_direct_light; 00380 int num_distribution; 00381 int num_all_lights; 00382 float pdf_triangles; 00383 float pdf_lights; 00384 00385 /* bounces */ 00386 int min_bounce; 00387 int max_bounce; 00388 00389 int max_diffuse_bounce; 00390 int max_glossy_bounce; 00391 int max_transmission_bounce; 00392 00393 /* transparent */ 00394 int transparent_min_bounce; 00395 int transparent_max_bounce; 00396 int transparent_shadows; 00397 00398 /* caustics */ 00399 int no_caustics; 00400 00401 /* seed */ 00402 int seed; 00403 00404 /* render layer */ 00405 int layer_flag; 00406 } KernelIntegrator; 00407 00408 typedef struct KernelBVH { 00409 /* root node */ 00410 int root; 00411 int attributes_map_stride; 00412 int pad1, pad2; 00413 } KernelBVH; 00414 00415 typedef struct KernelData { 00416 KernelCamera cam; 00417 KernelFilm film; 00418 KernelBackground background; 00419 KernelSunSky sunsky; 00420 KernelIntegrator integrator; 00421 KernelBVH bvh; 00422 } KernelData; 00423 00424 CCL_NAMESPACE_END 00425 00426 #endif /* __KERNEL_TYPES_H__ */ 00427