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__
53 #ifdef __KERNEL_OPENCL_NVIDIA__
54 #define __KERNEL_SHADING__
55 #define __MULTI_CLOSURE__
58 #ifdef __KERNEL_OPENCL_APPLE__
60 //#define __EMISSION__
61 //#define __IMAGE_TEXTURES__
63 //#define __PROCEDURAL_TEXTURES__
64 //#define __EXTRA_NODES__
67 #ifdef __KERNEL_OPENCL_AMD__
70 #define __IMAGE_TEXTURES__
72 #define __PROCEDURAL_TEXTURES__
73 #define __EXTRA_NODES__
80 #define __INSTANCING__
83 #define __BACKGROUND__
84 #define __CAUSTICS_TRICKS__
85 #define __VISIBILITY_FLAG__
86 #define __RAY_DIFFERENTIALS__
87 #define __CAMERA_CLIPPING__
88 #define __INTERSECTION_REFINE__
89 #define __CLAMP_SAMPLE__
91 #ifdef __KERNEL_SHADING__
94 #define __PROCEDURAL_TEXTURES__
95 #define __IMAGE_TEXTURES__
96 #define __EXTRA_NODES__
100 #ifdef __KERNEL_ADV_SHADING__
101 #define __MULTI_CLOSURE__
102 #define __TRANSPARENT_SHADOWS__
104 #define __BACKGROUND_MIS__
109 //#define __MULTI_LIGHT__
111 //#define __SOBOL_FULL_SCREEN__
114 /* Shader Evaluation */
116 enum ShaderEvalType {
117 SHADER_EVAL_DISPLACE,
118 SHADER_EVAL_BACKGROUND
122 * note we need to keep the u/v pairs at even values */
124 enum PathTraceDimension {
148 /* these flag values correspond exactly to OSL defaults, so be careful not to
149 * change this, or if you do, set the "raytypes" shading system attribute with
150 * your own new ray types and bitflag values.
152 * for ray visibility tests in BVH traversal, the upper 20 bits are used for
153 * layer visibility tests. */
157 PATH_RAY_REFLECT = 2,
158 PATH_RAY_TRANSMIT = 4,
159 PATH_RAY_DIFFUSE = 8,
160 PATH_RAY_GLOSSY = 16,
161 PATH_RAY_SINGULAR = 32,
162 PATH_RAY_TRANSPARENT = 64,
164 PATH_RAY_SHADOW_OPAQUE = 128,
165 PATH_RAY_SHADOW_TRANSPARENT = 256,
166 PATH_RAY_SHADOW = (PATH_RAY_SHADOW_OPAQUE|PATH_RAY_SHADOW_TRANSPARENT),
168 PATH_RAY_MIS_SKIP = 512,
170 PATH_RAY_ALL = (1|2|4|8|16|32|64|128|256|512),
172 PATH_RAY_LAYER_SHIFT = (32-20)
177 typedef enum ClosureLabel {
181 LABEL_BACKGROUND = 4,
188 LABEL_SINGULAR = 512,
189 LABEL_TRANSPARENT = 1024,
195 typedef enum PassType {
202 PASS_MATERIAL_ID = 32,
203 PASS_DIFFUSE_COLOR = 64,
204 PASS_GLOSSY_COLOR = 128,
205 PASS_TRANSMISSION_COLOR = 256,
206 PASS_DIFFUSE_INDIRECT = 512,
207 PASS_GLOSSY_INDIRECT = 1024,
208 PASS_TRANSMISSION_INDIRECT = 2048,
209 PASS_DIFFUSE_DIRECT = 4096,
210 PASS_GLOSSY_DIRECT = 8192,
211 PASS_TRANSMISSION_DIRECT = 16384,
212 PASS_EMISSION = 32768,
213 PASS_BACKGROUND = 65536,
215 PASS_SHADOW = 262144,
216 PASS_MOTION = 524288,
217 PASS_MOTION_WEIGHT = 1048576
220 #define PASS_ALL (~0)
224 typedef float3 PathThroughput;
226 typedef struct PathRadiance {
234 float3 direct_throughput;
235 float3 direct_emission;
237 float3 color_diffuse;
239 float3 color_transmission;
241 float3 direct_diffuse;
242 float3 direct_glossy;
243 float3 direct_transmission;
245 float3 indirect_diffuse;
246 float3 indirect_glossy;
247 float3 indirect_transmission;
252 typedef struct BsdfEval {
263 typedef float3 PathThroughput;
264 typedef float3 PathRadiance;
265 typedef float3 BsdfEval;
271 typedef enum ShaderFlag {
272 SHADER_SMOOTH_NORMAL = (1 << 31),
273 SHADER_CAST_SHADOW = (1 << 30),
274 SHADER_AREA_LIGHT = (1 << 29),
276 SHADER_MASK = ~(SHADER_SMOOTH_NORMAL|SHADER_CAST_SHADOW|SHADER_AREA_LIGHT)
281 typedef enum LightType {
301 PANORAMA_EQUIRECTANGULAR,
302 PANORAMA_FISHEYE_EQUIDISTANT,
303 PANORAMA_FISHEYE_EQUISOLID
308 typedef struct differential3 {
313 typedef struct differential {
326 #ifdef __RAY_DIFFERENTIALS__
334 typedef struct Intersection {
342 typedef enum AttributeElement {
350 typedef enum AttributeStandard {
352 ATTR_STD_VERTEX_NORMAL,
353 ATTR_STD_FACE_NORMAL,
356 ATTR_STD_POSITION_UNDEFORMED,
357 ATTR_STD_POSITION_UNDISPLACED,
359 ATTR_STD_MOTION_POST,
362 ATTR_STD_NOT_FOUND = ~0
367 #define MAX_CLOSURE 8
369 typedef struct ShaderClosure {
373 #ifdef __MULTI_CLOSURE__
388 * Main shader state at a point on the surface or in a volume. All coordinates
389 * are in world space. */
391 enum ShaderDataFlag {
393 SD_BACKFACING = 1, /* backside of surface? */
394 SD_EMISSION = 2, /* have emissive closure? */
395 SD_BSDF = 4, /* have bsdf closure? */
396 SD_BSDF_HAS_EVAL = 8, /* have non-singular bsdf closure? */
397 SD_BSDF_GLOSSY = 16, /* have glossy bsdf */
398 SD_HOLDOUT = 32, /* have holdout closure? */
399 SD_VOLUME = 64, /* have volume closure? */
402 SD_SAMPLE_AS_LIGHT = 128, /* direct light sample */
403 SD_HAS_SURFACE_TRANSPARENT = 256, /* has surface transparency */
404 SD_HAS_VOLUME = 512, /* has volume shader */
405 SD_HOMOGENEOUS_VOLUME = 1024, /* has homogeneous volume */
408 SD_HOLDOUT_MASK = 2048, /* holdout for camera rays */
409 SD_OBJECT_MOTION = 4096 /* has object motion blur */
412 typedef struct ShaderData {
415 /* smooth normal for shading */
417 /* true geometric normal */
419 /* view/incoming direction */
423 /* booleans describing shader, see ShaderDataFlag */
426 /* primitive id if there is one, ~0 otherwise */
428 /* parametric coordinates
429 * - barycentric weights for triangles */
431 /* object id if there is one, ~0 otherwise */
434 /* motion blur sample time */
437 /* length of the ray being shaded */
441 /* object <-> world space transformations, cached to avoid
442 * re-interpolating them constantly for shading */
447 #ifdef __RAY_DIFFERENTIALS__
448 /* differential of P. these are orthogonal to Ng, not N */
450 /* differential of I */
452 /* differential of u, v */
457 /* differential of P w.r.t. parametric coordinates. note that dPdu is
458 * not readily suitable as a tangent for shading on triangles. */
462 #ifdef __MULTI_CLOSURE__
463 /* Closure data, we store a fixed array of closures */
464 ShaderClosure closure[MAX_CLOSURE];
468 /* Closure data, with a single sampled closure for low memory usage */
469 ShaderClosure closure;
478 /* Constrant Kernel Data
480 * These structs are passed from CPU to various devices, and the struct layout
481 * must match exactly. Structs are padded to ensure 16 byte alignment, and we
482 * do not use float3 because its size may not be the same on all devices. */
484 typedef struct KernelCamera {
494 Transform cameratoworld;
495 Transform rastertocamera;
504 float bladesrotation;
523 Transform screentoworld;
524 Transform rastertoworld;
525 Transform ndctoworld;
526 Transform worldtoscreen;
527 Transform worldtoraster;
528 Transform worldtondc;
529 Transform worldtocamera;
531 MotionTransform motion;
534 typedef struct KernelFilm {
545 int pass_motion_weight;
548 int pass_material_id;
550 int pass_diffuse_color;
551 int pass_glossy_color;
552 int pass_transmission_color;
553 int pass_diffuse_indirect;
555 int pass_glossy_indirect;
556 int pass_transmission_indirect;
557 int pass_diffuse_direct;
558 int pass_glossy_direct;
560 int pass_transmission_direct;
571 typedef struct KernelBackground {
572 /* only shader index */
576 /* ambient occlusion */
581 typedef struct KernelSunSky {
582 /* sun direction in spherical and cartesian */
583 float theta, phi, pad3, pad4;
585 /* perez function parameters */
586 float zenith_Y, zenith_x, zenith_y, pad2;
587 float perez_Y[5], perez_x[5], perez_y[5];
591 typedef struct KernelIntegrator {
593 int use_direct_light;
594 int use_ambient_occlusion;
595 int num_distribution;
599 int pdf_background_res;
605 int max_diffuse_bounce;
606 int max_glossy_bounce;
607 int max_transmission_bounce;
610 int transparent_min_bounce;
611 int transparent_max_bounce;
612 int transparent_shadows;
628 typedef struct KernelBVH {
631 int attributes_map_stride;
635 typedef struct KernelData {
638 KernelBackground background;
640 KernelIntegrator integrator;
646 #endif /* __KERNEL_TYPES_H__ */