2 * Copyright 2011-2013 Blender Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 #ifndef __KERNEL_TYPES_H__
18 #define __KERNEL_TYPES_H__
20 #include "kernel_math.h"
21 #include "svm/svm_types.h"
23 #ifndef __KERNEL_GPU__
24 #define __KERNEL_CPU__
30 #define OBJECT_SIZE 11
31 #define OBJECT_VECTOR_SIZE 6
33 #define FILTER_TABLE_SIZE 256
34 #define RAMP_TABLE_SIZE 256
35 #define PARTICLE_SIZE 5
36 #define TIME_INVALID FLT_MAX
38 #define BSSRDF_MIN_RADIUS 1e-8f
39 #define BSSRDF_MAX_HITS 4
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
47 #define TEX_NUM_FLOAT_IMAGES 5
49 /* device capabilities */
51 #define __KERNEL_SHADING__
52 #define __KERNEL_ADV_SHADING__
53 #define __BRANCHED_PATH__
57 #define __SUBSURFACE__
61 #ifdef __KERNEL_CUDA__
62 #define __KERNEL_SHADING__
63 #define __KERNEL_ADV_SHADING__
64 #define __BRANCHED_PATH__
67 #ifdef __KERNEL_OPENCL__
69 /* keep __KERNEL_ADV_SHADING__ in sync with opencl_kernel_use_advanced_shading! */
71 #ifdef __KERNEL_OPENCL_NVIDIA__
72 #define __KERNEL_SHADING__
73 #define __KERNEL_ADV_SHADING__
76 #ifdef __KERNEL_OPENCL_APPLE__
77 #define __KERNEL_SHADING__
78 //#define __KERNEL_ADV_SHADING__
81 #ifdef __KERNEL_OPENCL_AMD__
84 #define __IMAGE_TEXTURES__
85 #define __PROCEDURAL_TEXTURES__
86 #define __EXTRA_NODES__
88 #define __NORMAL_MAP__
89 //#define __BACKGROUND_MIS__
90 //#define __LAMP_MIS__
92 //#define __ANISOTROPIC__
93 //#define __CAMERA_MOTION__
94 //#define __OBJECT_MOTION__
96 //#define __MULTI_CLOSURE__
97 //#define __TRANSPARENT_SHADOWS__
101 #ifdef __KERNEL_OPENCL_INTEL_CPU__
102 #define __KERNEL_SHADING__
103 #define __KERNEL_ADV_SHADING__
108 /* kernel features */
110 #define __INSTANCING__
113 #define __BACKGROUND__
114 #define __CAUSTICS_TRICKS__
115 #define __VISIBILITY_FLAG__
116 #define __RAY_DIFFERENTIALS__
117 #define __CAMERA_CLIPPING__
118 #define __INTERSECTION_REFINE__
119 #define __CLAMP_SAMPLE__
121 #ifdef __KERNEL_SHADING__
124 #define __PROCEDURAL_TEXTURES__
125 #define __IMAGE_TEXTURES__
126 #define __EXTRA_NODES__
128 #define __NORMAL_MAP__
131 #ifdef __KERNEL_ADV_SHADING__
132 #define __MULTI_CLOSURE__
133 #define __TRANSPARENT_SHADOWS__
135 #define __BACKGROUND_MIS__
138 #define __ANISOTROPIC__
139 #define __CAMERA_MOTION__
140 #define __OBJECT_MOTION__
146 #if defined(__KERNEL_OPENCL_NEED_ADVANCED_SHADING__) && !defined(__MULTI_CLOSURE__)
147 #error "OpenCL: mismatch between advanced shading flags in device_opencl.cpp and kernel_types.h"
150 /* Shader Evaluation */
152 typedef enum ShaderEvalType {
153 SHADER_EVAL_DISPLACE,
154 SHADER_EVAL_BACKGROUND
158 * note we need to keep the u/v pairs at even values */
160 enum PathTraceDimension {
165 #ifdef __CAMERA_MOTION__
168 PRNG_UNUSED_1 = 6, /* for some reason (6, 7) is a bad sobol pattern */
169 PRNG_UNUSED_2 = 7, /* with a low number of samples (< 64) */
186 enum SamplingPattern {
187 SAMPLING_PATTERN_SOBOL = 0,
188 SAMPLING_PATTERN_CMJ = 1
191 /* these flags values correspond to raytypes in osl.cpp, so keep them in sync!
193 * for ray visibility tests in BVH traversal, the upper 20 bits are used for
194 * layer visibility tests. */
198 PATH_RAY_REFLECT = 2,
199 PATH_RAY_TRANSMIT = 4,
200 PATH_RAY_DIFFUSE = 8,
201 PATH_RAY_GLOSSY = 16,
202 PATH_RAY_SINGULAR = 32,
203 PATH_RAY_TRANSPARENT = 64,
204 PATH_RAY_VOLUME_SCATTER = 128,
206 PATH_RAY_SHADOW_OPAQUE = 128,
207 PATH_RAY_SHADOW_TRANSPARENT = 256,
208 PATH_RAY_SHADOW = (PATH_RAY_SHADOW_OPAQUE|PATH_RAY_SHADOW_TRANSPARENT),
210 PATH_RAY_CURVE = 512, /* visibility flag to define curve segments*/
212 PATH_RAY_ALL_VISIBILITY = (1|2|4|8|16|32|64|128|256|512),
214 PATH_RAY_MIS_SKIP = 1024,
215 PATH_RAY_DIFFUSE_ANCESTOR = 2048,
216 PATH_RAY_GLOSSY_ANCESTOR = 4096,
217 PATH_RAY_BSSRDF_ANCESTOR = 8192,
219 /* this gives collisions with localview bits
220 * see: blender_util.h, grr - Campbell */
221 PATH_RAY_LAYER_SHIFT = (32-20)
226 typedef enum ClosureLabel {
233 LABEL_TRANSPARENT = 32,
234 LABEL_VOLUME_SCATTER = 64,
239 typedef enum PassType {
246 PASS_MATERIAL_ID = 32,
247 PASS_DIFFUSE_COLOR = 64,
248 PASS_GLOSSY_COLOR = 128,
249 PASS_TRANSMISSION_COLOR = 256,
250 PASS_DIFFUSE_INDIRECT = 512,
251 PASS_GLOSSY_INDIRECT = 1024,
252 PASS_TRANSMISSION_INDIRECT = 2048,
253 PASS_DIFFUSE_DIRECT = 4096,
254 PASS_GLOSSY_DIRECT = 8192,
255 PASS_TRANSMISSION_DIRECT = 16384,
256 PASS_EMISSION = 32768,
257 PASS_BACKGROUND = 65536,
259 PASS_SHADOW = 262144,
260 PASS_MOTION = 524288,
261 PASS_MOTION_WEIGHT = 1048576,
263 PASS_SUBSURFACE_DIRECT = 4194304,
264 PASS_SUBSURFACE_INDIRECT = 8388608,
265 PASS_SUBSURFACE_COLOR = 16777216
268 #define PASS_ALL (~0)
272 typedef struct PathRadiance {
280 float3 direct_throughput;
281 float3 direct_emission;
283 float3 color_diffuse;
285 float3 color_transmission;
286 float3 color_subsurface;
288 float3 direct_diffuse;
289 float3 direct_glossy;
290 float3 direct_transmission;
291 float3 direct_subsurface;
293 float3 indirect_diffuse;
294 float3 indirect_glossy;
295 float3 indirect_transmission;
296 float3 indirect_subsurface;
300 float3 path_transmission;
301 float3 path_subsurface;
307 typedef struct BsdfEval {
319 typedef float3 PathRadiance;
320 typedef float3 BsdfEval;
326 typedef enum ShaderFlag {
327 SHADER_SMOOTH_NORMAL = (1 << 31),
328 SHADER_CAST_SHADOW = (1 << 30),
329 SHADER_AREA_LIGHT = (1 << 29),
330 SHADER_USE_MIS = (1 << 28),
331 SHADER_EXCLUDE_DIFFUSE = (1 << 27),
332 SHADER_EXCLUDE_GLOSSY = (1 << 26),
333 SHADER_EXCLUDE_TRANSMIT = (1 << 25),
334 SHADER_EXCLUDE_CAMERA = (1 << 24),
335 SHADER_EXCLUDE_ANY = (SHADER_EXCLUDE_DIFFUSE|SHADER_EXCLUDE_GLOSSY|SHADER_EXCLUDE_TRANSMIT|SHADER_EXCLUDE_CAMERA),
337 SHADER_MASK = ~(SHADER_SMOOTH_NORMAL|SHADER_CAST_SHADOW|SHADER_AREA_LIGHT|SHADER_USE_MIS|SHADER_EXCLUDE_ANY)
342 typedef enum LightType {
364 PANORAMA_EQUIRECTANGULAR,
365 PANORAMA_FISHEYE_EQUIDISTANT,
366 PANORAMA_FISHEYE_EQUISOLID
371 typedef struct differential3 {
376 typedef struct differential {
384 float3 P; /* origin */
385 float3 D; /* direction */
386 float t; /* length of the ray */
387 float time; /* time (for motion blur) */
389 #ifdef __RAY_DIFFERENTIALS__
397 typedef struct Intersection {
406 #define ATTR_PRIM_TYPES 2
407 #define ATTR_PRIM_CURVE 1
409 typedef enum AttributeElement {
416 ATTR_ELEMENT_CURVE_KEY
419 typedef enum AttributeStandard {
421 ATTR_STD_VERTEX_NORMAL,
422 ATTR_STD_FACE_NORMAL,
425 ATTR_STD_UV_TANGENT_SIGN,
427 ATTR_STD_POSITION_UNDEFORMED,
428 ATTR_STD_POSITION_UNDISPLACED,
430 ATTR_STD_MOTION_POST,
432 ATTR_STD_CURVE_INTERCEPT,
433 ATTR_STD_PTEX_FACE_ID,
437 ATTR_STD_NOT_FOUND = ~0
442 #define MAX_CLOSURE 64
444 typedef struct ShaderClosure {
448 #ifdef __MULTI_CLOSURE__
456 #if defined(__ANISOTROPIC__) || defined(__SUBSURFACE__) || defined(__HAIR__)
471 * For OSL we recycle a fixed number of contexts for speed */
473 typedef enum ShaderContext {
474 SHADER_CONTEXT_MAIN = 0,
475 SHADER_CONTEXT_INDIRECT = 1,
476 SHADER_CONTEXT_EMISSION = 2,
477 SHADER_CONTEXT_SHADOW = 3,
478 SHADER_CONTEXT_SSS = 4,
479 SHADER_CONTEXT_NUM = 5
484 * Main shader state at a point on the surface or in a volume. All coordinates
485 * are in world space. */
487 enum ShaderDataFlag {
489 SD_BACKFACING = 1, /* backside of surface? */
490 SD_EMISSION = 2, /* have emissive closure? */
491 SD_BSDF = 4, /* have bsdf closure? */
492 SD_BSDF_HAS_EVAL = 8, /* have non-singular bsdf closure? */
493 SD_BSDF_GLOSSY = 16, /* have glossy bsdf */
494 SD_BSSRDF = 32, /* have bssrdf */
495 SD_HOLDOUT = 64, /* have holdout closure? */
496 SD_VOLUME = 128, /* have volume closure? */
497 SD_AO = 256, /* have ao closure? */
499 SD_CLOSURE_FLAGS = (SD_EMISSION|SD_BSDF|SD_BSDF_HAS_EVAL|SD_BSDF_GLOSSY|SD_BSSRDF|SD_HOLDOUT|SD_VOLUME|SD_AO),
502 SD_USE_MIS = 512, /* direct light sample */
503 SD_HAS_TRANSPARENT_SHADOW = 1024, /* has transparent shadow */
504 SD_HAS_VOLUME = 2048, /* has volume shader */
505 SD_HOMOGENEOUS_VOLUME = 4096, /* has homogeneous volume */
506 SD_HAS_BSSRDF_BUMP = 8192, /* bssrdf normal uses bump */
509 SD_HOLDOUT_MASK = 16384, /* holdout for camera rays */
510 SD_OBJECT_MOTION = 32768, /* has object motion blur */
511 SD_TRANSFORM_APPLIED = 65536 /* vertices have transform applied */
514 struct KernelGlobals;
516 typedef struct ShaderData {
519 /* smooth normal for shading */
521 /* true geometric normal */
523 /* view/incoming direction */
527 /* booleans describing shader, see ShaderDataFlag */
530 /* primitive id if there is one, ~0 otherwise */
534 /* for curves, segment number in curve, ~0 for triangles */
536 /* variables for minimum hair width using transparency bsdf */
537 /*float curve_transparency; */
538 /*float curve_radius; */
540 /* parametric coordinates
541 * - barycentric weights for triangles */
543 /* object id if there is one, ~0 otherwise */
546 /* motion blur sample time */
549 /* length of the ray being shaded */
552 /* ray bounce depth */
555 #ifdef __RAY_DIFFERENTIALS__
556 /* differential of P. these are orthogonal to Ng, not N */
558 /* differential of I */
560 /* differential of u, v */
565 /* differential of P w.r.t. parametric coordinates. note that dPdu is
566 * not readily suitable as a tangent for shading on triangles. */
570 #ifdef __OBJECT_MOTION__
571 /* object <-> world space transformations, cached to avoid
572 * re-interpolating them constantly for shading */
577 #ifdef __MULTI_CLOSURE__
578 /* Closure data, we store a fixed array of closures */
579 ShaderClosure closure[MAX_CLOSURE];
583 /* Closure data, with a single sampled closure for low memory usage */
584 ShaderClosure closure;
587 /* ray start position, only set for backgrounds */
589 differential3 ray_dP;
592 struct KernelGlobals *osl_globals;
596 /* Constant Kernel Data
598 * These structs are passed from CPU to various devices, and the struct layout
599 * must match exactly. Structs are padded to ensure 16 byte alignment, and we
600 * do not use float3 because its size may not be the same on all devices. */
602 typedef struct KernelCamera {
612 Transform cameratoworld;
613 Transform rastertocamera;
622 float bladesrotation;
645 Transform screentoworld;
646 Transform rastertoworld;
647 /* work around cuda sm 2.0 crash, this seems to
648 * cross some limit in combination with motion
649 * Transform ndctoworld; */
650 Transform worldtoscreen;
651 Transform worldtoraster;
652 Transform worldtondc;
653 Transform worldtocamera;
655 MotionTransform motion;
658 typedef struct KernelFilm {
669 int pass_motion_weight;
672 int pass_material_id;
674 int pass_diffuse_color;
675 int pass_glossy_color;
676 int pass_transmission_color;
677 int pass_subsurface_color;
679 int pass_diffuse_indirect;
680 int pass_glossy_indirect;
681 int pass_transmission_indirect;
682 int pass_subsurface_indirect;
684 int pass_diffuse_direct;
685 int pass_glossy_direct;
686 int pass_transmission_direct;
687 int pass_subsurface_direct;
695 float pass_shadow_scale;
696 int filter_table_offset;
701 float mist_inv_depth;
705 typedef struct KernelBackground {
706 /* only shader index */
710 /* ambient occlusion */
715 typedef struct KernelIntegrator {
717 int use_direct_light;
718 int use_ambient_occlusion;
719 int num_distribution;
723 float inv_pdf_lights;
724 int pdf_background_res;
730 int max_diffuse_bounce;
731 int max_glossy_bounce;
732 int max_transmission_bounce;
735 int transparent_min_bounce;
736 int transparent_max_bounce;
737 int transparent_shadows;
757 int transmission_samples;
759 int mesh_light_samples;
760 int subsurface_samples;
766 int sampling_pattern;
772 typedef struct KernelBVH {
775 int attributes_map_stride;
780 int pad1, pad2, pad3;
783 typedef enum CurveFlag {
785 CURVE_KN_BACKFACING = 1, /* backside of cylinder? */
786 CURVE_KN_ENCLOSEFILTER = 2, /* don't consider strands surrounding start point? */
787 CURVE_KN_INTERPOLATE = 4, /* render as a curve? */
788 CURVE_KN_ACCURATE = 8, /* use accurate intersections test? */
789 CURVE_KN_INTERSECTCORRECTION = 16, /* correct for width after determing closest midpoint? */
790 CURVE_KN_TRUETANGENTGNORMAL = 32, /* use tangent normal for geometry? */
791 CURVE_KN_RIBBONS = 64, /* use flat curve ribbons */
794 typedef struct KernelCurves {
795 /* strand intersect and normal parameters - many can be changed to flags */
796 float encasing_ratio;
806 typedef struct KernelBlackbody {
808 int pad1, pad2, pad3;
812 typedef struct KernelData {
815 KernelBackground background;
816 KernelIntegrator integrator;
819 KernelBlackbody blackbody;
824 #endif /* __KERNEL_TYPES_H__ */