2 * Copyright 2011, Blender Foundation.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef __KERNEL_TYPES_H__
20 #define __KERNEL_TYPES_H__
22 #include "kernel_math.h"
23 #include "svm/svm_types.h"
25 #ifndef __KERNEL_GPU__
26 #define __KERNEL_CPU__
32 #define OBJECT_SIZE 16
34 #define FILTER_TABLE_SIZE 256
35 #define RAMP_TABLE_SIZE 256
36 #define TIME_INVALID FLT_MAX
38 /* device capabilities */
40 #define __KERNEL_SHADING__
41 #define __KERNEL_ADV_SHADING__
44 #ifdef __KERNEL_CUDA__
45 #define __KERNEL_SHADING__
46 #if __CUDA_ARCH__ >= 200
47 #define __KERNEL_ADV_SHADING__
51 #ifdef __KERNEL_OPENCL__
52 //#define __KERNEL_SHADING__
53 //#define __KERNEL_ADV_SHADING__
58 #define __INSTANCING__
61 #define __BACKGROUND__
62 #define __CAUSTICS_TRICKS__
63 #define __VISIBILITY_FLAG__
64 #define __RAY_DIFFERENTIALS__
65 #define __CAMERA_CLIPPING__
66 #define __INTERSECTION_REFINE__
67 #define __CLAMP_SAMPLE__
69 #ifdef __KERNEL_SHADING__
76 #ifdef __KERNEL_ADV_SHADING__
77 #define __MULTI_CLOSURE__
78 #define __TRANSPARENT_SHADOWS__
80 #define __BACKGROUND_MIS__
85 //#define __MULTI_LIGHT__
87 //#define __SOBOL_FULL_SCREEN__
88 //#define __MODIFY_TP__
91 /* Shader Evaluation */
95 SHADER_EVAL_BACKGROUND
99 * note we need to keep the u/v pairs at even values */
101 enum PathTraceDimension {
125 /* these flag values correspond exactly to OSL defaults, so be careful not to
126 * change this, or if you do, set the "raytypes" shading system attribute with
127 * your own new ray types and bitflag values.
129 * for ray visibility tests in BVH traversal, the upper 20 bits are used for
130 * layer visibility tests. */
134 PATH_RAY_REFLECT = 2,
135 PATH_RAY_TRANSMIT = 4,
136 PATH_RAY_DIFFUSE = 8,
137 PATH_RAY_GLOSSY = 16,
138 PATH_RAY_SINGULAR = 32,
139 PATH_RAY_TRANSPARENT = 64,
141 PATH_RAY_SHADOW_OPAQUE = 128,
142 PATH_RAY_SHADOW_TRANSPARENT = 256,
143 PATH_RAY_SHADOW = (PATH_RAY_SHADOW_OPAQUE|PATH_RAY_SHADOW_TRANSPARENT),
145 PATH_RAY_MIS_SKIP = 512,
147 PATH_RAY_ALL = (1|2|4|8|16|32|64|128|256|512),
149 PATH_RAY_LAYER_SHIFT = (32-20)
154 typedef enum ClosureLabel {
158 LABEL_BACKGROUND = 4,
165 LABEL_SINGULAR = 512,
166 LABEL_TRANSPARENT = 1024,
172 typedef enum PassType {
179 PASS_MATERIAL_ID = 64,
180 PASS_DIFFUSE_COLOR = 128,
181 PASS_GLOSSY_COLOR = 256,
182 PASS_TRANSMISSION_COLOR = 512,
183 PASS_DIFFUSE_INDIRECT = 1024,
184 PASS_GLOSSY_INDIRECT = 2048,
185 PASS_TRANSMISSION_INDIRECT = 4096,
186 PASS_DIFFUSE_DIRECT = 8192,
187 PASS_GLOSSY_DIRECT = 16384,
188 PASS_TRANSMISSION_DIRECT = 32768,
189 PASS_EMISSION = 65536,
190 PASS_BACKGROUND = 131072,
192 PASS_SHADOW = 524288,
193 PASS_MOTION = 1048576,
194 PASS_MOTION_WEIGHT = 2097152
197 #define PASS_ALL (~0)
201 typedef float3 PathThroughput;
203 typedef struct PathRadiance {
211 float3 direct_throughput;
212 float3 direct_emission;
214 float3 color_diffuse;
216 float3 color_transmission;
218 float3 direct_diffuse;
219 float3 direct_glossy;
220 float3 direct_transmission;
222 float3 indirect_diffuse;
223 float3 indirect_glossy;
224 float3 indirect_transmission;
229 typedef struct BsdfEval {
240 typedef float3 PathThroughput;
241 typedef float3 PathRadiance;
242 typedef float3 BsdfEval;
248 typedef enum ShaderFlag {
249 SHADER_SMOOTH_NORMAL = (1 << 31),
250 SHADER_CAST_SHADOW = (1 << 30),
251 SHADER_AREA_LIGHT = (1 << 29),
253 SHADER_MASK = ~(SHADER_SMOOTH_NORMAL|SHADER_CAST_SHADOW|SHADER_AREA_LIGHT)
258 typedef enum LightType {
276 typedef struct differential3 {
281 typedef struct differential {
294 #ifdef __RAY_DIFFERENTIALS__
302 typedef struct Intersection {
310 typedef enum AttributeElement {
318 typedef enum AttributeStandard {
320 ATTR_STD_VERTEX_NORMAL,
321 ATTR_STD_FACE_NORMAL,
324 ATTR_STD_POSITION_UNDEFORMED,
325 ATTR_STD_POSITION_UNDISPLACED,
327 ATTR_STD_MOTION_POST,
330 ATTR_STD_NOT_FOUND = ~0
335 #define MAX_CLOSURE 8
337 typedef struct ShaderClosure {
341 #ifdef __MULTI_CLOSURE__
356 * Main shader state at a point on the surface or in a volume. All coordinates
357 * are in world space. */
359 enum ShaderDataFlag {
361 SD_BACKFACING = 1, /* backside of surface? */
362 SD_EMISSION = 2, /* have emissive closure? */
363 SD_BSDF = 4, /* have bsdf closure? */
364 SD_BSDF_HAS_EVAL = 8, /* have non-singular bsdf closure? */
365 SD_BSDF_GLOSSY = 16, /* have glossy bsdf */
366 SD_HOLDOUT = 32, /* have holdout closure? */
367 SD_VOLUME = 64, /* have volume closure? */
370 SD_SAMPLE_AS_LIGHT = 128, /* direct light sample */
371 SD_HAS_SURFACE_TRANSPARENT = 256, /* has surface transparency */
372 SD_HAS_VOLUME = 512, /* has volume shader */
373 SD_HOMOGENEOUS_VOLUME = 1024, /* has homogeneous volume */
376 SD_HOLDOUT_MASK = 2048, /* holdout for camera rays */
377 SD_OBJECT_MOTION = 4096 /* has object motion blur */
380 typedef struct ShaderData {
383 /* smooth normal for shading */
385 /* true geometric normal */
387 /* view/incoming direction */
391 /* booleans describing shader, see ShaderDataFlag */
394 /* primitive id if there is one, ~0 otherwise */
396 /* parametric coordinates
397 * - barycentric weights for triangles */
399 /* object id if there is one, ~0 otherwise */
402 /* motion blur sample time */
405 /* length of the ray being shaded */
409 /* object <-> world space transformations, cached to avoid
410 * re-interpolating them constantly for shading */
415 #ifdef __RAY_DIFFERENTIALS__
416 /* differential of P. these are orthogonal to Ng, not N */
418 /* differential of I */
420 /* differential of u, v */
425 /* differential of P w.r.t. parametric coordinates. note that dPdu is
426 * not readily suitable as a tangent for shading on triangles. */
430 #ifdef __MULTI_CLOSURE__
431 /* Closure data, we store a fixed array of closures */
432 ShaderClosure closure[MAX_CLOSURE];
436 /* Closure data, with a single sampled closure for low memory usage */
437 ShaderClosure closure;
446 /* Constrant Kernel Data
448 * These structs are passed from CPU to various devices, and the struct layout
449 * must match exactly. Structs are padded to ensure 16 byte alignment, and we
450 * do not use float3 because its size may not be the same on all devices. */
452 typedef struct KernelCamera {
455 int pad1, pad2, pad3;
458 Transform cameratoworld;
459 Transform rastertocamera;
468 float bladesrotation;
480 Transform screentoworld;
481 Transform rastertoworld;
482 Transform ndctoworld;
483 Transform worldtoscreen;
484 Transform worldtoraster;
485 Transform worldtondc;
486 Transform worldtocamera;
488 MotionTransform motion;
491 typedef struct KernelFilm {
502 int pass_motion_weight;
505 int pass_material_id;
507 int pass_diffuse_color;
508 int pass_glossy_color;
509 int pass_transmission_color;
510 int pass_diffuse_indirect;
512 int pass_glossy_indirect;
513 int pass_transmission_indirect;
514 int pass_diffuse_direct;
515 int pass_glossy_direct;
517 int pass_transmission_direct;
528 typedef struct KernelBackground {
529 /* only shader index */
533 /* ambient occlusion */
538 typedef struct KernelSunSky {
539 /* sun direction in spherical and cartesian */
540 float theta, phi, pad3, pad4;
542 /* perez function parameters */
543 float zenith_Y, zenith_x, zenith_y, pad2;
544 float perez_Y[5], perez_x[5], perez_y[5];
548 typedef struct KernelIntegrator {
550 int use_direct_light;
551 int use_ambient_occlusion;
552 int num_distribution;
556 int pdf_background_res;
562 int max_diffuse_bounce;
563 int max_glossy_bounce;
564 int max_transmission_bounce;
567 int transparent_min_bounce;
568 int transparent_max_bounce;
569 int transparent_shadows;
585 typedef struct KernelBVH {
588 int attributes_map_stride;
592 typedef struct KernelData {
595 KernelBackground background;
597 KernelIntegrator integrator;
603 #endif /* __KERNEL_TYPES_H__ */