Fix T40117: cycles sobol RNG issue when disabling __CAMERA_MOTION__.
[blender-staging.git] / intern / cycles / kernel / kernel_types.h
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16
17 #ifndef __KERNEL_TYPES_H__
18 #define __KERNEL_TYPES_H__
19
20 #include "kernel_math.h"
21 #include "svm/svm_types.h"
22
23 #ifndef __KERNEL_GPU__
24 #define __KERNEL_CPU__
25 #endif
26
27 CCL_NAMESPACE_BEGIN
28
29 /* constants */
30 #define OBJECT_SIZE             11
31 #define OBJECT_VECTOR_SIZE      6
32 #define LIGHT_SIZE                      4
33 #define FILTER_TABLE_SIZE       256
34 #define RAMP_TABLE_SIZE         256
35 #define PARTICLE_SIZE           5
36 #define TIME_INVALID            FLT_MAX
37
38 #define BSSRDF_MIN_RADIUS                       1e-8f
39 #define BSSRDF_MAX_HITS                         4
40
41 #define BB_DRAPPER                              800.0f
42 #define BB_MAX_TABLE_RANGE              12000.0f
43 #define BB_TABLE_XPOWER                 1.5f
44 #define BB_TABLE_YPOWER                 5.0f
45 #define BB_TABLE_SPACING                2.0f
46
47 #define TEX_NUM_FLOAT_IMAGES    5
48
49 #define SHADER_NONE                             (~0)
50 #define OBJECT_NONE                             (~0)
51 #define PRIM_NONE                               (~0)
52 #define LAMP_NONE                               (~0)
53
54 #define VOLUME_STACK_SIZE               16
55
56 /* device capabilities */
57 #ifdef __KERNEL_CPU__
58 #define __KERNEL_SHADING__
59 #define __KERNEL_ADV_SHADING__
60 #define __BRANCHED_PATH__
61 #ifdef WITH_OSL
62 #define __OSL__
63 #endif
64 #define __SUBSURFACE__
65 #define __CMJ__
66 #define __VOLUME__
67 #define __SHADOW_RECORD_ALL__
68 #endif
69
70 #ifdef __KERNEL_CUDA__
71 #define __KERNEL_SHADING__
72 #define __KERNEL_ADV_SHADING__
73 #define __BRANCHED_PATH__
74
75 /* Experimental on GPU */
76 //#define __VOLUME__
77 //#define __SUBSURFACE__
78 #endif
79
80 #ifdef __KERNEL_OPENCL__
81
82 /* keep __KERNEL_ADV_SHADING__ in sync with opencl_kernel_use_advanced_shading! */
83
84 #ifdef __KERNEL_OPENCL_NVIDIA__
85 #define __KERNEL_SHADING__
86 #define __KERNEL_ADV_SHADING__
87 #endif
88
89 #ifdef __KERNEL_OPENCL_APPLE__
90 #define __KERNEL_SHADING__
91 //#define __KERNEL_ADV_SHADING__
92 #endif
93
94 #ifdef __KERNEL_OPENCL_AMD__
95 #define __CL_USE_NATIVE__
96 #define __KERNEL_SHADING__
97 //__KERNEL_ADV_SHADING__
98 #define __MULTI_CLOSURE__
99 #define __TRANSPARENT_SHADOWS__
100 #define __PASSES__
101 #define __BACKGROUND_MIS__
102 #define __LAMP_MIS__
103 #define __AO__
104 #define __ANISOTROPIC__
105 //#define __CAMERA_MOTION__
106 //#define __OBJECT_MOTION__
107 //#define __HAIR__
108 //end __KERNEL_ADV_SHADING__
109 #endif
110
111 #ifdef __KERNEL_OPENCL_INTEL_CPU__
112 #define __CL_USE_NATIVE__
113 #define __KERNEL_SHADING__
114 #define __KERNEL_ADV_SHADING__
115 #endif
116
117 #endif
118
119 /* kernel features */
120 #define __SOBOL__
121 #define __INSTANCING__
122 #define __DPDU__
123 #define __UV__
124 #define __BACKGROUND__
125 #define __CAUSTICS_TRICKS__
126 #define __VISIBILITY_FLAG__
127 #define __RAY_DIFFERENTIALS__
128 #define __CAMERA_CLIPPING__
129 #define __INTERSECTION_REFINE__
130 #define __CLAMP_SAMPLE__
131
132 #ifdef __KERNEL_SHADING__
133 #define __SVM__
134 #define __EMISSION__
135 #define __PROCEDURAL_TEXTURES__
136 #define __IMAGE_TEXTURES__
137 #define __EXTRA_NODES__
138 #define __HOLDOUT__
139 #define __NORMAL_MAP__
140 #endif
141
142 #ifdef __KERNEL_ADV_SHADING__
143 #define __MULTI_CLOSURE__
144 #define __TRANSPARENT_SHADOWS__
145 #define __PASSES__
146 #define __BACKGROUND_MIS__
147 #define __LAMP_MIS__
148 #define __AO__
149 #define __ANISOTROPIC__
150 #define __CAMERA_MOTION__
151 #define __OBJECT_MOTION__
152 #define __HAIR__
153 #endif
154
155 /* Random Numbers */
156
157 typedef uint RNG;
158
159 /* Shader Evaluation */
160
161 typedef enum ShaderEvalType {
162         SHADER_EVAL_DISPLACE,
163         SHADER_EVAL_BACKGROUND,
164         /* bake types */
165         SHADER_EVAL_BAKE, /* no real shade, it's used in the code to
166                            * differentiate the type of shader eval from the above
167                            */
168         /* data passes */
169         SHADER_EVAL_NORMAL,
170         SHADER_EVAL_UV,
171         SHADER_EVAL_DIFFUSE_COLOR,
172         SHADER_EVAL_GLOSSY_COLOR,
173         SHADER_EVAL_TRANSMISSION_COLOR,
174         SHADER_EVAL_SUBSURFACE_COLOR,
175         SHADER_EVAL_EMISSION,
176
177         /* light passes */
178         SHADER_EVAL_AO,
179         SHADER_EVAL_COMBINED,
180         SHADER_EVAL_SHADOW,
181         SHADER_EVAL_DIFFUSE_DIRECT,
182         SHADER_EVAL_GLOSSY_DIRECT,
183         SHADER_EVAL_TRANSMISSION_DIRECT,
184         SHADER_EVAL_SUBSURFACE_DIRECT,
185         SHADER_EVAL_DIFFUSE_INDIRECT,
186         SHADER_EVAL_GLOSSY_INDIRECT,
187         SHADER_EVAL_TRANSMISSION_INDIRECT,
188         SHADER_EVAL_SUBSURFACE_INDIRECT,
189
190         /* extra */
191         SHADER_EVAL_ENVIRONMENT,
192 } ShaderEvalType;
193
194 /* Path Tracing
195  * note we need to keep the u/v pairs at even values */
196
197 enum PathTraceDimension {
198         PRNG_FILTER_U = 0,
199         PRNG_FILTER_V = 1,
200         PRNG_LENS_U = 2,
201         PRNG_LENS_V = 3,
202 #ifdef __CAMERA_MOTION__
203         PRNG_TIME = 4,
204         PRNG_UNUSED_0 = 5,
205         PRNG_UNUSED_1 = 6,      /* for some reason (6, 7) is a bad sobol pattern */
206         PRNG_UNUSED_2 = 7,  /* with a low number of samples (< 64) */
207 #endif
208         PRNG_BASE_NUM = 8,
209
210         PRNG_BSDF_U = 0,
211         PRNG_BSDF_V = 1,
212         PRNG_BSDF = 2,
213         PRNG_LIGHT = 3,
214         PRNG_LIGHT_U = 4,
215         PRNG_LIGHT_V = 5,
216         PRNG_UNUSED_3 = 6,
217         PRNG_TERMINATE = 7,
218
219 #ifdef __VOLUME__
220         PRNG_PHASE_U = 8,
221         PRNG_PHASE_V = 9,
222         PRNG_PHASE = 10,
223         PRNG_SCATTER_DISTANCE = 11,
224         PRNG_BOUNCE_NUM = 12,
225 #else
226         PRNG_BOUNCE_NUM = 8,
227 #endif
228 };
229
230 enum SamplingPattern {
231         SAMPLING_PATTERN_SOBOL = 0,
232         SAMPLING_PATTERN_CMJ = 1
233 };
234
235 /* these flags values correspond to raytypes in osl.cpp, so keep them in sync!
236  *
237  * for ray visibility tests in BVH traversal, the upper 20 bits are used for
238  * layer visibility tests. */
239
240 enum PathRayFlag {
241         PATH_RAY_CAMERA = 1,
242         PATH_RAY_REFLECT = 2,
243         PATH_RAY_TRANSMIT = 4,
244         PATH_RAY_DIFFUSE = 8,
245         PATH_RAY_GLOSSY = 16,
246         PATH_RAY_SINGULAR = 32,
247         PATH_RAY_TRANSPARENT = 64,
248
249         PATH_RAY_SHADOW_OPAQUE = 128,
250         PATH_RAY_SHADOW_TRANSPARENT = 256,
251         PATH_RAY_SHADOW = (PATH_RAY_SHADOW_OPAQUE|PATH_RAY_SHADOW_TRANSPARENT),
252
253         PATH_RAY_CURVE = 512, /* visibility flag to define curve segments*/
254
255         /* note that these can use maximum 12 bits, the other are for layers */
256         PATH_RAY_ALL_VISIBILITY = (1|2|4|8|16|32|64|128|256|512),
257
258         PATH_RAY_MIS_SKIP = 1024,
259         PATH_RAY_DIFFUSE_ANCESTOR = 2048,
260         PATH_RAY_GLOSSY_ANCESTOR = 4096,
261         PATH_RAY_BSSRDF_ANCESTOR = 8192,
262         PATH_RAY_SINGLE_PASS_DONE = 16384,
263         PATH_RAY_VOLUME_SCATTER = 32768,
264
265         /* we need layer member flags to be the 20 upper bits */
266         PATH_RAY_LAYER_SHIFT = (32-20)
267 };
268
269 /* Closure Label */
270
271 typedef enum ClosureLabel {
272         LABEL_NONE = 0,
273         LABEL_TRANSMIT = 1,
274         LABEL_REFLECT = 2,
275         LABEL_DIFFUSE = 4,
276         LABEL_GLOSSY = 8,
277         LABEL_SINGULAR = 16,
278         LABEL_TRANSPARENT = 32,
279         LABEL_VOLUME_SCATTER = 64,
280 } ClosureLabel;
281
282 /* Render Passes */
283
284 typedef enum PassType {
285         PASS_NONE = 0,
286         PASS_COMBINED = 1,
287         PASS_DEPTH = 2,
288         PASS_NORMAL = 4,
289         PASS_UV = 8,
290         PASS_OBJECT_ID = 16,
291         PASS_MATERIAL_ID = 32,
292         PASS_DIFFUSE_COLOR = 64,
293         PASS_GLOSSY_COLOR = 128,
294         PASS_TRANSMISSION_COLOR = 256,
295         PASS_DIFFUSE_INDIRECT = 512,
296         PASS_GLOSSY_INDIRECT = 1024,
297         PASS_TRANSMISSION_INDIRECT = 2048,
298         PASS_DIFFUSE_DIRECT = 4096,
299         PASS_GLOSSY_DIRECT = 8192,
300         PASS_TRANSMISSION_DIRECT = 16384,
301         PASS_EMISSION = 32768,
302         PASS_BACKGROUND = 65536,
303         PASS_AO = 131072,
304         PASS_SHADOW = 262144,
305         PASS_MOTION = 524288,
306         PASS_MOTION_WEIGHT = 1048576,
307         PASS_MIST = 2097152,
308         PASS_SUBSURFACE_DIRECT = 4194304,
309         PASS_SUBSURFACE_INDIRECT = 8388608,
310         PASS_SUBSURFACE_COLOR = 16777216,
311         PASS_LIGHT = 33554432, /* no real pass, used to force use_light_pass */
312 } PassType;
313
314 #define PASS_ALL (~0)
315
316 #ifdef __PASSES__
317
318 typedef struct PathRadiance {
319         int use_light_pass;
320
321         float3 emission;
322         float3 background;
323         float3 ao;
324
325         float3 indirect;
326         float3 direct_throughput;
327         float3 direct_emission;
328
329         float3 color_diffuse;
330         float3 color_glossy;
331         float3 color_transmission;
332         float3 color_subsurface;
333
334         float3 direct_diffuse;
335         float3 direct_glossy;
336         float3 direct_transmission;
337         float3 direct_subsurface;
338
339         float3 indirect_diffuse;
340         float3 indirect_glossy;
341         float3 indirect_transmission;
342         float3 indirect_subsurface;
343
344         float3 path_diffuse;
345         float3 path_glossy;
346         float3 path_transmission;
347         float3 path_subsurface;
348
349         float4 shadow;
350         float mist;
351 } PathRadiance;
352
353 typedef struct BsdfEval {
354         int use_light_pass;
355
356         float3 diffuse;
357         float3 glossy;
358         float3 transmission;
359         float3 transparent;
360         float3 subsurface;
361 } BsdfEval;
362
363 #else
364
365 typedef float3 PathRadiance;
366 typedef float3 BsdfEval;
367
368 #endif
369
370 /* Shader Flag */
371
372 typedef enum ShaderFlag {
373         SHADER_SMOOTH_NORMAL = (1 << 31),
374         SHADER_CAST_SHADOW = (1 << 30),
375         SHADER_AREA_LIGHT = (1 << 29),
376         SHADER_USE_MIS = (1 << 28),
377         SHADER_EXCLUDE_DIFFUSE = (1 << 27),
378         SHADER_EXCLUDE_GLOSSY = (1 << 26),
379         SHADER_EXCLUDE_TRANSMIT = (1 << 25),
380         SHADER_EXCLUDE_CAMERA = (1 << 24),
381         SHADER_EXCLUDE_ANY = (SHADER_EXCLUDE_DIFFUSE|SHADER_EXCLUDE_GLOSSY|SHADER_EXCLUDE_TRANSMIT|SHADER_EXCLUDE_CAMERA),
382
383         SHADER_MASK = ~(SHADER_SMOOTH_NORMAL|SHADER_CAST_SHADOW|SHADER_AREA_LIGHT|SHADER_USE_MIS|SHADER_EXCLUDE_ANY)
384 } ShaderFlag;
385
386 /* Light Type */
387
388 typedef enum LightType {
389         LIGHT_POINT,
390         LIGHT_DISTANT,
391         LIGHT_BACKGROUND,
392         LIGHT_AREA,
393         LIGHT_AO,
394         LIGHT_SPOT,
395         LIGHT_TRIANGLE,
396         LIGHT_STRAND
397 } LightType;
398
399 /* Camera Type */
400
401 enum CameraType {
402         CAMERA_PERSPECTIVE,
403         CAMERA_ORTHOGRAPHIC,
404         CAMERA_PANORAMA
405 };
406
407 /* Panorama Type */
408
409 enum PanoramaType {
410         PANORAMA_EQUIRECTANGULAR,
411         PANORAMA_FISHEYE_EQUIDISTANT,
412         PANORAMA_FISHEYE_EQUISOLID
413 };
414
415 /* Differential */
416
417 typedef struct differential3 {
418         float3 dx;
419         float3 dy;
420 } differential3;
421
422 typedef struct differential {
423         float dx;
424         float dy;
425 } differential;
426
427 /* Ray */
428
429 typedef struct Ray {
430         float3 P;               /* origin */
431         float3 D;               /* direction */
432         float t;                /* length of the ray */
433         float time;             /* time (for motion blur) */
434
435 #ifdef __RAY_DIFFERENTIALS__
436         differential3 dP;
437         differential3 dD;
438 #endif
439 } Ray;
440
441 /* Intersection */
442
443 typedef struct Intersection {
444         float t, u, v;
445         int prim;
446         int object;
447         int type;
448 } Intersection;
449
450 /* Primitives */
451
452 typedef enum PrimitiveType {
453         PRIMITIVE_NONE = 0,
454         PRIMITIVE_TRIANGLE = 1,
455         PRIMITIVE_MOTION_TRIANGLE = 2,
456         PRIMITIVE_CURVE = 4,
457         PRIMITIVE_MOTION_CURVE = 8,
458
459         PRIMITIVE_ALL_TRIANGLE = (PRIMITIVE_TRIANGLE|PRIMITIVE_MOTION_TRIANGLE),
460         PRIMITIVE_ALL_CURVE = (PRIMITIVE_CURVE|PRIMITIVE_MOTION_CURVE),
461         PRIMITIVE_ALL_MOTION = (PRIMITIVE_MOTION_TRIANGLE|PRIMITIVE_MOTION_CURVE),
462         PRIMITIVE_ALL = (PRIMITIVE_ALL_TRIANGLE|PRIMITIVE_ALL_CURVE)
463 } PrimitiveType;
464
465 #define PRIMITIVE_PACK_SEGMENT(type, segment) ((segment << 16) | type)
466 #define PRIMITIVE_UNPACK_SEGMENT(type) (type >> 16)
467
468 /* Attributes */
469
470 #define ATTR_PRIM_TYPES         2
471 #define ATTR_PRIM_CURVE         1
472
473 typedef enum AttributeElement {
474         ATTR_ELEMENT_NONE,
475         ATTR_ELEMENT_OBJECT,
476         ATTR_ELEMENT_MESH,
477         ATTR_ELEMENT_FACE,
478         ATTR_ELEMENT_VERTEX,
479         ATTR_ELEMENT_VERTEX_MOTION,
480         ATTR_ELEMENT_CORNER,
481         ATTR_ELEMENT_CURVE,
482         ATTR_ELEMENT_CURVE_KEY,
483         ATTR_ELEMENT_CURVE_KEY_MOTION,
484         ATTR_ELEMENT_VOXEL
485 } AttributeElement;
486
487 typedef enum AttributeStandard {
488         ATTR_STD_NONE = 0,
489         ATTR_STD_VERTEX_NORMAL,
490         ATTR_STD_FACE_NORMAL,
491         ATTR_STD_UV,
492         ATTR_STD_UV_TANGENT,
493         ATTR_STD_UV_TANGENT_SIGN,
494         ATTR_STD_GENERATED,
495         ATTR_STD_GENERATED_TRANSFORM,
496         ATTR_STD_POSITION_UNDEFORMED,
497         ATTR_STD_POSITION_UNDISPLACED,
498         ATTR_STD_MOTION_VERTEX_POSITION,
499         ATTR_STD_MOTION_VERTEX_NORMAL,
500         ATTR_STD_PARTICLE,
501         ATTR_STD_CURVE_INTERCEPT,
502         ATTR_STD_PTEX_FACE_ID,
503         ATTR_STD_PTEX_UV,
504         ATTR_STD_VOLUME_DENSITY,
505         ATTR_STD_VOLUME_COLOR,
506         ATTR_STD_VOLUME_FLAME,
507         ATTR_STD_VOLUME_HEAT,
508         ATTR_STD_VOLUME_VELOCITY,
509         ATTR_STD_NUM,
510
511         ATTR_STD_NOT_FOUND = ~0
512 } AttributeStandard;
513
514 /* Closure data */
515
516 #ifdef __MULTI_CLOSURE__
517 #define MAX_CLOSURE 64
518 #else
519 #define MAX_CLOSURE 1
520 #endif
521
522 typedef struct ShaderClosure {
523         ClosureType type;
524         float3 weight;
525
526         float sample_weight;
527
528         float data0;
529         float data1;
530
531         float3 N;
532 #if defined(__ANISOTROPIC__) || defined(__SUBSURFACE__) || defined(__HAIR__)
533         float3 T;
534 #endif
535
536 #ifdef __HAIR__
537         float offset;
538 #endif
539
540 #ifdef __OSL__
541         void *prim;
542 #endif
543 } ShaderClosure;
544
545 /* Shader Context
546  *
547  * For OSL we recycle a fixed number of contexts for speed */
548
549 typedef enum ShaderContext {
550         SHADER_CONTEXT_MAIN = 0,
551         SHADER_CONTEXT_INDIRECT = 1,
552         SHADER_CONTEXT_EMISSION = 2,
553         SHADER_CONTEXT_SHADOW = 3,
554         SHADER_CONTEXT_SSS = 4,
555         SHADER_CONTEXT_VOLUME = 5,
556         SHADER_CONTEXT_NUM = 6
557 } ShaderContext;
558
559 /* Shader Data
560  *
561  * Main shader state at a point on the surface or in a volume. All coordinates
562  * are in world space. */
563
564 enum ShaderDataFlag {
565         /* runtime flags */
566         SD_BACKFACING = 1,              /* backside of surface? */
567         SD_EMISSION = 2,                /* have emissive closure? */
568         SD_BSDF = 4,                    /* have bsdf closure? */
569         SD_BSDF_HAS_EVAL = 8,   /* have non-singular bsdf closure? */
570         SD_PHASE_HAS_EVAL = 8,  /* have non-singular phase closure? */
571         SD_BSDF_GLOSSY = 16,    /* have glossy bsdf */
572         SD_BSSRDF = 32,                 /* have bssrdf */
573         SD_HOLDOUT = 64,                /* have holdout closure? */
574         SD_ABSORPTION = 128,    /* have volume absorption closure? */
575         SD_SCATTER = 256,               /* have volume phase closure? */
576         SD_AO = 512,                    /* have ao closure? */
577         SD_TRANSPARENT = 1024,  /* have transparent closure? */
578
579         SD_CLOSURE_FLAGS = (SD_EMISSION|SD_BSDF|SD_BSDF_HAS_EVAL|SD_BSDF_GLOSSY|SD_BSSRDF|SD_HOLDOUT|SD_ABSORPTION|SD_SCATTER|SD_AO),
580
581         /* shader flags */
582         SD_USE_MIS = 2048,                                      /* direct light sample */
583         SD_HAS_TRANSPARENT_SHADOW = 4096,       /* has transparent shadow */
584         SD_HAS_VOLUME = 8192,                           /* has volume shader */
585         SD_HAS_ONLY_VOLUME = 16384,                     /* has only volume shader, no surface */
586         SD_HETEROGENEOUS_VOLUME = 32768,        /* has heterogeneous volume */
587         SD_HAS_BSSRDF_BUMP = 65536,                     /* bssrdf normal uses bump */
588
589         SD_SHADER_FLAGS = (SD_USE_MIS|SD_HAS_TRANSPARENT_SHADOW|SD_HAS_VOLUME|SD_HAS_ONLY_VOLUME|SD_HETEROGENEOUS_VOLUME|SD_HAS_BSSRDF_BUMP),
590
591         /* object flags */
592         SD_HOLDOUT_MASK = 131072,                       /* holdout for camera rays */
593         SD_OBJECT_MOTION = 262144,                      /* has object motion blur */
594         SD_TRANSFORM_APPLIED = 524288,          /* vertices have transform applied */
595
596         SD_OBJECT_FLAGS = (SD_HOLDOUT_MASK|SD_OBJECT_MOTION|SD_TRANSFORM_APPLIED)
597 };
598
599 struct KernelGlobals;
600
601 typedef struct ShaderData {
602         /* position */
603         float3 P;
604         /* smooth normal for shading */
605         float3 N;
606         /* true geometric normal */
607         float3 Ng;
608         /* view/incoming direction */
609         float3 I;
610         /* shader id */
611         int shader;
612         /* booleans describing shader, see ShaderDataFlag */
613         int flag;
614
615         /* primitive id if there is one, ~0 otherwise */
616         int prim;
617
618         /* combined type and curve segment for hair */
619         int type;
620
621         /* parametric coordinates
622          * - barycentric weights for triangles */
623         float u, v;
624         /* object id if there is one, ~0 otherwise */
625         int object;
626
627         /* motion blur sample time */
628         float time;
629         
630         /* length of the ray being shaded */
631         float ray_length;
632         
633         /* ray bounce depth */
634         int ray_depth;
635
636         /* ray transparent depth */
637         int transparent_depth;
638
639 #ifdef __RAY_DIFFERENTIALS__
640         /* differential of P. these are orthogonal to Ng, not N */
641         differential3 dP;
642         /* differential of I */
643         differential3 dI;
644         /* differential of u, v */
645         differential du;
646         differential dv;
647 #endif
648 #ifdef __DPDU__
649         /* differential of P w.r.t. parametric coordinates. note that dPdu is
650          * not readily suitable as a tangent for shading on triangles. */
651         float3 dPdu, dPdv;
652 #endif
653
654 #ifdef __OBJECT_MOTION__
655         /* object <-> world space transformations, cached to avoid
656          * re-interpolating them constantly for shading */
657         Transform ob_tfm;
658         Transform ob_itfm;
659 #endif
660
661         /* Closure data, we store a fixed array of closures */
662         ShaderClosure closure[MAX_CLOSURE];
663         int num_closure;
664         float randb_closure;
665
666         /* ray start position, only set for backgrounds */
667         float3 ray_P;
668         differential3 ray_dP;
669
670 #ifdef __OSL__
671         struct KernelGlobals *osl_globals;
672 #endif
673 } ShaderData;
674
675 /* Path State */
676
677 #ifdef __VOLUME__
678 typedef struct VolumeStack {
679         int object;
680         int shader;
681 } VolumeStack;
682 #endif
683
684 typedef struct PathState {
685         /* see enum PathRayFlag */
686         int flag;          
687
688         /* random number generator state */
689         int rng_offset;    /* dimension offset */
690         int sample;        /* path sample number */
691         int num_samples;   /* total number of times this path will be sampled */
692
693         /* bounce counting */
694         int bounce;
695         int diffuse_bounce;
696         int glossy_bounce;
697         int transmission_bounce;
698         int transparent_bounce;
699
700         /* multiple importance sampling */
701         float min_ray_pdf; /* smallest bounce pdf over entire path up to now */
702         float ray_pdf;     /* last bounce pdf */
703 #ifdef __LAMP_MIS__
704         float ray_t;       /* accumulated distance through transparent surfaces */
705 #endif
706
707         /* volume rendering */
708 #ifdef __VOLUME__
709         int volume_bounce;
710         RNG rng_congruential;
711         VolumeStack volume_stack[VOLUME_STACK_SIZE];
712 #endif
713 } PathState;
714
715 /* Constant Kernel Data
716  *
717  * These structs are passed from CPU to various devices, and the struct layout
718  * must match exactly. Structs are padded to ensure 16 byte alignment, and we
719  * do not use float3 because its size may not be the same on all devices. */
720
721 typedef struct KernelCamera {
722         /* type */
723         int type;
724
725         /* panorama */
726         int panorama_type;
727         float fisheye_fov;
728         float fisheye_lens;
729
730         /* matrices */
731         Transform cameratoworld;
732         Transform rastertocamera;
733
734         /* differentials */
735         float4 dx;
736         float4 dy;
737
738         /* depth of field */
739         float aperturesize;
740         float blades;
741         float bladesrotation;
742         float focaldistance;
743
744         /* motion blur */
745         float shuttertime;
746         int have_motion;
747
748         /* clipping */
749         float nearclip;
750         float cliplength;
751
752         /* sensor size */
753         float sensorwidth;
754         float sensorheight;
755
756         /* render size */
757         float width, height;
758         int resolution;
759         int pad1;
760         int pad2;
761         int pad3;
762
763         /* more matrices */
764         Transform screentoworld;
765         Transform rastertoworld;
766         /* work around cuda sm 2.0 crash, this seems to
767          * cross some limit in combination with motion 
768          * Transform ndctoworld; */
769         Transform worldtoscreen;
770         Transform worldtoraster;
771         Transform worldtondc;
772         Transform worldtocamera;
773
774         MotionTransform motion;
775 } KernelCamera;
776
777 typedef struct KernelFilm {
778         float exposure;
779         int pass_flag;
780         int pass_stride;
781         int use_light_pass;
782
783         int pass_combined;
784         int pass_depth;
785         int pass_normal;
786         int pass_motion;
787
788         int pass_motion_weight;
789         int pass_uv;
790         int pass_object_id;
791         int pass_material_id;
792
793         int pass_diffuse_color;
794         int pass_glossy_color;
795         int pass_transmission_color;
796         int pass_subsurface_color;
797         
798         int pass_diffuse_indirect;
799         int pass_glossy_indirect;
800         int pass_transmission_indirect;
801         int pass_subsurface_indirect;
802         
803         int pass_diffuse_direct;
804         int pass_glossy_direct;
805         int pass_transmission_direct;
806         int pass_subsurface_direct;
807         
808         int pass_emission;
809         int pass_background;
810         int pass_ao;
811         float pass_alpha_threshold;
812
813         int pass_shadow;
814         float pass_shadow_scale;
815         int filter_table_offset;
816         int pass_pad2;
817
818         int pass_mist;
819         float mist_start;
820         float mist_inv_depth;
821         float mist_falloff;
822 } KernelFilm;
823
824 typedef struct KernelBackground {
825         /* only shader index */
826         int surface_shader;
827         int volume_shader;
828         int transparent;
829         int pad;
830
831         /* ambient occlusion */
832         float ao_factor;
833         float ao_distance;
834         float ao_pad1, ao_pad2;
835 } KernelBackground;
836
837 typedef struct KernelIntegrator {
838         /* emission */
839         int use_direct_light;
840         int use_ambient_occlusion;
841         int num_distribution;
842         int num_all_lights;
843         float pdf_triangles;
844         float pdf_lights;
845         float inv_pdf_lights;
846         int pdf_background_res;
847
848         /* bounces */
849         int min_bounce;
850         int max_bounce;
851
852         int max_diffuse_bounce;
853         int max_glossy_bounce;
854         int max_transmission_bounce;
855         int max_volume_bounce;
856
857         /* transparent */
858         int transparent_min_bounce;
859         int transparent_max_bounce;
860         int transparent_shadows;
861
862         /* caustics */
863         int no_caustics;
864         float filter_glossy;
865
866         /* seed */
867         int seed;
868
869         /* render layer */
870         int layer_flag;
871
872         /* clamp */
873         float sample_clamp_direct;
874         float sample_clamp_indirect;
875
876         /* branched path */
877         int branched;
878         int diffuse_samples;
879         int glossy_samples;
880         int transmission_samples;
881         int ao_samples;
882         int mesh_light_samples;
883         int subsurface_samples;
884         int sample_all_lights_direct;
885         int sample_all_lights_indirect;
886
887         /* mis */
888         int use_lamp_mis;
889
890         /* sampler */
891         int sampling_pattern;
892         int aa_samples;
893
894         /* volume render */
895         int volume_homogeneous_sampling;
896         int use_volumes;
897         int volume_max_steps;
898         float volume_step_size;
899         int volume_samples;
900 } KernelIntegrator;
901
902 typedef struct KernelBVH {
903         /* root node */
904         int root;
905         int attributes_map_stride;
906         int have_motion;
907         int have_curves;
908         int have_instancing;
909
910         int pad1, pad2, pad3;
911 } KernelBVH;
912
913 typedef enum CurveFlag {
914         /* runtime flags */
915         CURVE_KN_BACKFACING = 1,                                /* backside of cylinder? */
916         CURVE_KN_ENCLOSEFILTER = 2,                             /* don't consider strands surrounding start point? */
917         CURVE_KN_INTERPOLATE = 4,                               /* render as a curve? */
918         CURVE_KN_ACCURATE = 8,                                  /* use accurate intersections test? */
919         CURVE_KN_INTERSECTCORRECTION = 16,              /* correct for width after determing closest midpoint? */
920         CURVE_KN_TRUETANGENTGNORMAL = 32,               /* use tangent normal for geometry? */
921         CURVE_KN_RIBBONS = 64,                                  /* use flat curve ribbons */
922 } CurveFlag;
923
924 typedef struct KernelCurves {
925         /* strand intersect and normal parameters - many can be changed to flags */
926         int curveflags;
927         int subdivisions;
928
929         float minimum_width;
930         float maximum_width;
931 } KernelCurves;
932
933 typedef struct KernelBlackbody {
934         int table_offset;
935         int pad1, pad2, pad3;
936 } KernelBlackbody;
937
938
939 typedef struct KernelData {
940         KernelCamera cam;
941         KernelFilm film;
942         KernelBackground background;
943         KernelIntegrator integrator;
944         KernelBVH bvh;
945         KernelCurves curve;
946         KernelBlackbody blackbody;
947 } KernelData;
948
949 CCL_NAMESPACE_END
950
951 #endif /*  __KERNEL_TYPES_H__ */
952