c7fe7948422098d263a4043e50f823af558acd57
[blender.git] / intern / cycles / kernel / svm / svm_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 __SVM_TYPES_H__
18 #define __SVM_TYPES_H__
19
20 CCL_NAMESPACE_BEGIN
21
22 /* Stack */
23
24 /* SVM stack has a fixed size */
25 #define SVM_STACK_SIZE 255
26 /* SVM stack offsets with this value indicate that it's not on the stack */
27 #define SVM_STACK_INVALID 255 
28
29 #define SVM_BUMP_EVAL_STATE_SIZE 9
30
31 /* Nodes */
32
33 /* Known frequencies of used nodes, used for selective nodes compilation
34  * in the kernel. Currently only affects split OpenCL kernel.
35  *
36  * Keep as defines so it's easy to check which nodes are to be compiled
37  * from preprocessor.
38  *
39  * Lower the number of group more often the node is used.
40  */
41 #define NODE_GROUP_LEVEL_0    0
42 #define NODE_GROUP_LEVEL_1    1
43 #define NODE_GROUP_LEVEL_2    2
44 #define NODE_GROUP_LEVEL_3    3
45 #define NODE_GROUP_LEVEL_MAX  NODE_GROUP_LEVEL_3
46
47 #define NODE_FEATURE_VOLUME     (1 << 0)
48 #define NODE_FEATURE_HAIR       (1 << 1)
49 #define NODE_FEATURE_BUMP       (1 << 2)
50 #define NODE_FEATURE_BUMP_STATE (1 << 3)
51 /* TODO(sergey): Consider using something like ((uint)(-1)).
52  * Need to check carefully operand types around usage of this
53  * define first.
54  */
55 #define NODE_FEATURE_ALL        (NODE_FEATURE_VOLUME|NODE_FEATURE_HAIR|NODE_FEATURE_BUMP|NODE_FEATURE_BUMP_STATE)
56
57 typedef enum ShaderNodeType {
58         NODE_END = 0,
59         NODE_CLOSURE_BSDF,
60         NODE_CLOSURE_EMISSION,
61         NODE_CLOSURE_BACKGROUND,
62         NODE_CLOSURE_SET_WEIGHT,
63         NODE_CLOSURE_WEIGHT,
64         NODE_MIX_CLOSURE,
65         NODE_JUMP_IF_ZERO,
66         NODE_JUMP_IF_ONE,
67         NODE_TEX_IMAGE,
68         NODE_TEX_IMAGE_BOX,
69         NODE_TEX_SKY,
70         NODE_GEOMETRY,
71         NODE_GEOMETRY_DUPLI,
72         NODE_LIGHT_PATH,
73         NODE_VALUE_F,
74         NODE_VALUE_V,
75         NODE_MIX,
76         NODE_ATTR,
77         NODE_CONVERT,
78         NODE_FRESNEL,
79         NODE_WIREFRAME,
80         NODE_WAVELENGTH,
81         NODE_BLACKBODY,
82         NODE_EMISSION_WEIGHT,
83         NODE_TEX_GRADIENT,
84         NODE_TEX_VORONOI,
85         NODE_TEX_MUSGRAVE,
86         NODE_TEX_WAVE,
87         NODE_TEX_MAGIC,
88         NODE_TEX_NOISE,
89         NODE_SHADER_JUMP,
90         NODE_SET_DISPLACEMENT,
91         NODE_GEOMETRY_BUMP_DX,
92         NODE_GEOMETRY_BUMP_DY,
93         NODE_SET_BUMP,
94         NODE_MATH,
95         NODE_VECTOR_MATH,
96         NODE_VECTOR_TRANSFORM,
97         NODE_MAPPING,
98         NODE_TEX_COORD,
99         NODE_TEX_COORD_BUMP_DX,
100         NODE_TEX_COORD_BUMP_DY,
101         NODE_ATTR_BUMP_DX,
102         NODE_ATTR_BUMP_DY,
103         NODE_TEX_ENVIRONMENT,
104         NODE_CLOSURE_HOLDOUT,
105         NODE_LAYER_WEIGHT,
106         NODE_CLOSURE_VOLUME,
107         NODE_SEPARATE_VECTOR,
108         NODE_COMBINE_VECTOR,
109         NODE_SEPARATE_HSV,
110         NODE_COMBINE_HSV,
111         NODE_HSV,
112         NODE_CAMERA,
113         NODE_INVERT,
114         NODE_NORMAL,
115         NODE_GAMMA,
116         NODE_TEX_CHECKER,
117         NODE_BRIGHTCONTRAST,
118         NODE_RGB_RAMP,
119         NODE_RGB_CURVES,
120         NODE_VECTOR_CURVES,
121         NODE_MIN_MAX,
122         NODE_LIGHT_FALLOFF,
123         NODE_OBJECT_INFO,
124         NODE_PARTICLE_INFO,
125         NODE_TEX_BRICK,
126         NODE_CLOSURE_SET_NORMAL,
127         NODE_CLOSURE_AMBIENT_OCCLUSION,
128         NODE_TANGENT,
129         NODE_NORMAL_MAP,
130         NODE_HAIR_INFO,
131         NODE_UVMAP,
132         NODE_TEX_VOXEL,
133         NODE_ENTER_BUMP_EVAL,
134         NODE_LEAVE_BUMP_EVAL,
135         NODE_BEVEL,
136 } ShaderNodeType;
137
138 typedef enum NodeAttributeType {
139         NODE_ATTR_FLOAT = 0,
140         NODE_ATTR_FLOAT3,
141         NODE_ATTR_MATRIX
142 } NodeAttributeType;
143
144 typedef enum NodeGeometry {
145         NODE_GEOM_P = 0,
146         NODE_GEOM_N,
147         NODE_GEOM_T,
148         NODE_GEOM_I,
149         NODE_GEOM_Ng,
150         NODE_GEOM_uv
151 } NodeGeometry;
152
153 typedef enum NodeObjectInfo {
154         NODE_INFO_OB_LOCATION,
155         NODE_INFO_OB_INDEX,
156         NODE_INFO_MAT_INDEX,
157         NODE_INFO_OB_RANDOM
158 } NodeObjectInfo;
159
160 typedef enum NodeParticleInfo {
161         NODE_INFO_PAR_INDEX,
162         NODE_INFO_PAR_AGE,
163         NODE_INFO_PAR_LIFETIME,
164         NODE_INFO_PAR_LOCATION,
165         NODE_INFO_PAR_ROTATION,
166         NODE_INFO_PAR_SIZE,
167         NODE_INFO_PAR_VELOCITY,
168         NODE_INFO_PAR_ANGULAR_VELOCITY
169 } NodeParticleInfo;
170
171 typedef enum NodeHairInfo {
172         NODE_INFO_CURVE_IS_STRAND,
173         NODE_INFO_CURVE_INTERCEPT,
174         NODE_INFO_CURVE_THICKNESS,
175         /*fade for minimum hair width transpency*/
176         /*NODE_INFO_CURVE_FADE,*/
177         NODE_INFO_CURVE_TANGENT_NORMAL
178 } NodeHairInfo;
179
180 typedef enum NodeLightPath {
181         NODE_LP_camera = 0,
182         NODE_LP_shadow,
183         NODE_LP_diffuse,
184         NODE_LP_glossy,
185         NODE_LP_singular,
186         NODE_LP_reflection,
187         NODE_LP_transmission,
188         NODE_LP_volume_scatter,
189         NODE_LP_backfacing,
190         NODE_LP_ray_length,
191         NODE_LP_ray_depth,
192         NODE_LP_ray_diffuse,
193         NODE_LP_ray_glossy,
194         NODE_LP_ray_transparent,
195         NODE_LP_ray_transmission,
196 } NodeLightPath;
197
198 typedef enum NodeLightFalloff {
199         NODE_LIGHT_FALLOFF_QUADRATIC,
200         NODE_LIGHT_FALLOFF_LINEAR,
201         NODE_LIGHT_FALLOFF_CONSTANT
202 } NodeLightFalloff;
203
204 typedef enum NodeTexCoord {
205         NODE_TEXCO_NORMAL,
206         NODE_TEXCO_OBJECT,
207         NODE_TEXCO_CAMERA,
208         NODE_TEXCO_WINDOW,
209         NODE_TEXCO_REFLECTION,
210         NODE_TEXCO_DUPLI_GENERATED,
211         NODE_TEXCO_DUPLI_UV,
212         NODE_TEXCO_VOLUME_GENERATED
213 } NodeTexCoord;
214
215 typedef enum NodeMix {
216         NODE_MIX_BLEND = 0,
217         NODE_MIX_ADD,
218         NODE_MIX_MUL,
219         NODE_MIX_SUB,
220         NODE_MIX_SCREEN,
221         NODE_MIX_DIV,
222         NODE_MIX_DIFF,
223         NODE_MIX_DARK,
224         NODE_MIX_LIGHT,
225         NODE_MIX_OVERLAY,
226         NODE_MIX_DODGE,
227         NODE_MIX_BURN,
228         NODE_MIX_HUE,
229         NODE_MIX_SAT,
230         NODE_MIX_VAL,
231         NODE_MIX_COLOR,
232         NODE_MIX_SOFT,
233         NODE_MIX_LINEAR,
234         NODE_MIX_CLAMP /* used for the clamp UI option */
235 } NodeMix;
236
237 typedef enum NodeMath {
238         NODE_MATH_ADD,
239         NODE_MATH_SUBTRACT,
240         NODE_MATH_MULTIPLY,
241         NODE_MATH_DIVIDE,
242         NODE_MATH_SINE,
243         NODE_MATH_COSINE,
244         NODE_MATH_TANGENT,
245         NODE_MATH_ARCSINE,
246         NODE_MATH_ARCCOSINE,
247         NODE_MATH_ARCTANGENT,
248         NODE_MATH_POWER,
249         NODE_MATH_LOGARITHM,
250         NODE_MATH_MINIMUM,
251         NODE_MATH_MAXIMUM,
252         NODE_MATH_ROUND,
253         NODE_MATH_LESS_THAN,
254         NODE_MATH_GREATER_THAN,
255         NODE_MATH_MODULO,
256         NODE_MATH_ABSOLUTE,
257         NODE_MATH_CLAMP /* used for the clamp UI option */
258 } NodeMath;
259
260 typedef enum NodeVectorMath {
261         NODE_VECTOR_MATH_ADD,
262         NODE_VECTOR_MATH_SUBTRACT,
263         NODE_VECTOR_MATH_AVERAGE,
264         NODE_VECTOR_MATH_DOT_PRODUCT,
265         NODE_VECTOR_MATH_CROSS_PRODUCT,
266         NODE_VECTOR_MATH_NORMALIZE
267 } NodeVectorMath;
268
269 typedef enum NodeVectorTransformType {
270         NODE_VECTOR_TRANSFORM_TYPE_VECTOR,
271         NODE_VECTOR_TRANSFORM_TYPE_POINT,
272         NODE_VECTOR_TRANSFORM_TYPE_NORMAL
273 } NodeVectorTransformType;
274
275 typedef enum NodeVectorTransformConvertSpace {
276         NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD,
277         NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT,
278         NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA
279 } NodeVectorTransformConvertSpace;
280
281 typedef enum NodeConvert {
282         NODE_CONVERT_FV,
283         NODE_CONVERT_FI,
284         NODE_CONVERT_CF,
285         NODE_CONVERT_CI,
286         NODE_CONVERT_VF,
287         NODE_CONVERT_VI,
288         NODE_CONVERT_IF,
289         NODE_CONVERT_IV
290 } NodeConvert;
291
292 typedef enum NodeMusgraveType {
293         NODE_MUSGRAVE_MULTIFRACTAL,
294         NODE_MUSGRAVE_FBM,
295         NODE_MUSGRAVE_HYBRID_MULTIFRACTAL,
296         NODE_MUSGRAVE_RIDGED_MULTIFRACTAL,
297         NODE_MUSGRAVE_HETERO_TERRAIN
298 } NodeMusgraveType;
299
300 typedef enum NodeWaveType {
301         NODE_WAVE_BANDS,
302         NODE_WAVE_RINGS
303 } NodeWaveType;
304
305 typedef enum NodeWaveProfiles {
306         NODE_WAVE_PROFILE_SIN,
307         NODE_WAVE_PROFILE_SAW,
308 } NodeWaveProfile;
309
310 typedef enum NodeSkyType {
311         NODE_SKY_OLD,
312         NODE_SKY_NEW
313 } NodeSkyType;
314
315 typedef enum NodeGradientType {
316         NODE_BLEND_LINEAR,
317         NODE_BLEND_QUADRATIC,
318         NODE_BLEND_EASING,
319         NODE_BLEND_DIAGONAL,
320         NODE_BLEND_RADIAL,
321         NODE_BLEND_QUADRATIC_SPHERE,
322         NODE_BLEND_SPHERICAL
323 } NodeGradientType;
324
325 typedef enum NodeVoronoiColoring {
326         NODE_VORONOI_INTENSITY,
327         NODE_VORONOI_CELLS
328 } NodeVoronoiColoring;
329
330 typedef enum NodeBlendWeightType {
331         NODE_LAYER_WEIGHT_FRESNEL,
332         NODE_LAYER_WEIGHT_FACING
333 } NodeBlendWeightType;
334
335 typedef enum NodeTangentDirectionType {
336         NODE_TANGENT_RADIAL,
337         NODE_TANGENT_UVMAP
338 } NodeTangentDirectionType;
339
340 typedef enum NodeTangentAxis {
341         NODE_TANGENT_AXIS_X,
342         NODE_TANGENT_AXIS_Y,
343         NODE_TANGENT_AXIS_Z
344 } NodeTangentAxis;
345
346 typedef enum NodeNormalMapSpace {
347         NODE_NORMAL_MAP_TANGENT,
348         NODE_NORMAL_MAP_OBJECT,
349         NODE_NORMAL_MAP_WORLD,
350         NODE_NORMAL_MAP_BLENDER_OBJECT,
351         NODE_NORMAL_MAP_BLENDER_WORLD,
352 } NodeNormalMapSpace;
353
354 typedef enum NodeImageColorSpace {
355         NODE_COLOR_SPACE_NONE  = 0,
356         NODE_COLOR_SPACE_COLOR = 1,
357 } NodeImageColorSpace;
358
359 typedef enum NodeImageProjection {
360         NODE_IMAGE_PROJ_FLAT   = 0,
361         NODE_IMAGE_PROJ_BOX    = 1,
362         NODE_IMAGE_PROJ_SPHERE = 2,
363         NODE_IMAGE_PROJ_TUBE   = 3,
364 } NodeImageProjection;
365
366 typedef enum NodeEnvironmentProjection {
367         NODE_ENVIRONMENT_EQUIRECTANGULAR = 0,
368         NODE_ENVIRONMENT_MIRROR_BALL = 1,
369 } NodeEnvironmentProjection;
370
371 typedef enum NodeBumpOffset {
372         NODE_BUMP_OFFSET_CENTER,
373         NODE_BUMP_OFFSET_DX,
374         NODE_BUMP_OFFSET_DY,
375 } NodeBumpOffset;
376
377 typedef enum NodeTexVoxelSpace {
378         NODE_TEX_VOXEL_SPACE_OBJECT = 0,
379         NODE_TEX_VOXEL_SPACE_WORLD  = 1,
380 } NodeTexVoxelSpace;
381
382 typedef enum ShaderType {
383         SHADER_TYPE_SURFACE,
384         SHADER_TYPE_VOLUME,
385         SHADER_TYPE_DISPLACEMENT,
386         SHADER_TYPE_BUMP,
387 } ShaderType;
388
389 /* Closure */
390
391 typedef enum ClosureType {
392         /* Special type, flags generic node as a non-BSDF. */
393         CLOSURE_NONE_ID,
394
395         CLOSURE_BSDF_ID,
396
397         /* Diffuse */
398         CLOSURE_BSDF_DIFFUSE_ID,
399         CLOSURE_BSDF_OREN_NAYAR_ID,
400         CLOSURE_BSDF_DIFFUSE_RAMP_ID,
401         CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID,
402         CLOSURE_BSDF_PRINCIPLED_SHEEN_ID,
403         CLOSURE_BSDF_DIFFUSE_TOON_ID,
404
405         /* Glossy */
406         CLOSURE_BSDF_REFLECTION_ID,
407         CLOSURE_BSDF_MICROFACET_GGX_ID,
408         CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID,
409         CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID,
410         CLOSURE_BSDF_MICROFACET_BECKMANN_ID,
411         CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID,
412         CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID,
413         CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID,
414         CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID,
415         CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID,
416         CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID,
417         CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_FRESNEL_ID,
418         CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID,
419         CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID,
420         CLOSURE_BSDF_ASHIKHMIN_VELVET_ID,
421         CLOSURE_BSDF_PHONG_RAMP_ID,
422         CLOSURE_BSDF_GLOSSY_TOON_ID,
423         CLOSURE_BSDF_HAIR_REFLECTION_ID,
424
425         /* Transmission */
426         CLOSURE_BSDF_TRANSLUCENT_ID,
427         CLOSURE_BSDF_REFRACTION_ID,
428         CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID,
429         CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID,
430         CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID,
431         CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID,
432         CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID,
433         CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID,
434         CLOSURE_BSDF_SHARP_GLASS_ID,
435         CLOSURE_BSDF_HAIR_TRANSMISSION_ID,
436
437         /* Special cases */
438         CLOSURE_BSDF_BSSRDF_ID,
439         CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID,
440         CLOSURE_BSDF_TRANSPARENT_ID,
441
442         /* BSSRDF */
443         CLOSURE_BSSRDF_CUBIC_ID,
444         CLOSURE_BSSRDF_GAUSSIAN_ID,
445         CLOSURE_BSSRDF_PRINCIPLED_ID,
446         CLOSURE_BSSRDF_BURLEY_ID,
447
448         /* Other */
449         CLOSURE_HOLDOUT_ID,
450         CLOSURE_AMBIENT_OCCLUSION_ID,
451
452         /* Volume */
453         CLOSURE_VOLUME_ID,
454         CLOSURE_VOLUME_ABSORPTION_ID,
455         CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID,
456
457         CLOSURE_BSDF_PRINCIPLED_ID,
458
459         NBUILTIN_CLOSURES
460 } ClosureType;
461
462 /* watch this, being lazy with memory usage */
463 #define CLOSURE_IS_BSDF(type) (type <= CLOSURE_BSDF_TRANSPARENT_ID)
464 #define CLOSURE_IS_BSDF_DIFFUSE(type) (type >= CLOSURE_BSDF_DIFFUSE_ID && type <= CLOSURE_BSDF_DIFFUSE_TOON_ID)
465 #define CLOSURE_IS_BSDF_GLOSSY(type) (type >= CLOSURE_BSDF_REFLECTION_ID && type <= CLOSURE_BSDF_HAIR_REFLECTION_ID)
466 #define CLOSURE_IS_BSDF_TRANSMISSION(type) (type >= CLOSURE_BSDF_TRANSLUCENT_ID && type <= CLOSURE_BSDF_HAIR_TRANSMISSION_ID)
467 #define CLOSURE_IS_BSDF_BSSRDF(type) (type == CLOSURE_BSDF_BSSRDF_ID || type == CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID)
468 #define CLOSURE_IS_BSDF_SINGULAR(type) (type == CLOSURE_BSDF_REFLECTION_ID || \
469                                         type == CLOSURE_BSDF_REFRACTION_ID || \
470                                         type == CLOSURE_BSDF_TRANSPARENT_ID)
471 #define CLOSURE_IS_BSDF_TRANSPARENT(type) (type == CLOSURE_BSDF_TRANSPARENT_ID)
472 #define CLOSURE_IS_BSDF_MULTISCATTER(type) (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID ||\
473                                             type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID || \
474                                             type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID)
475 #define CLOSURE_IS_BSDF_MICROFACET(type) ((type >= CLOSURE_BSDF_MICROFACET_GGX_ID && type <= CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID) ||\
476                                           (type >= CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID && type <= CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) ||\
477                                           (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID))
478 #define CLOSURE_IS_BSDF_OR_BSSRDF(type) (type <= CLOSURE_BSSRDF_BURLEY_ID)
479 #define CLOSURE_IS_BSSRDF(type) (type >= CLOSURE_BSSRDF_CUBIC_ID && type <= CLOSURE_BSSRDF_BURLEY_ID)
480 #define CLOSURE_IS_VOLUME(type) (type >= CLOSURE_VOLUME_ID && type <= CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID)
481 #define CLOSURE_IS_VOLUME_SCATTER(type) (type == CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID)
482 #define CLOSURE_IS_VOLUME_ABSORPTION(type) (type == CLOSURE_VOLUME_ABSORPTION_ID)
483 #define CLOSURE_IS_HOLDOUT(type) (type == CLOSURE_HOLDOUT_ID)
484 #define CLOSURE_IS_AMBIENT_OCCLUSION(type) (type == CLOSURE_AMBIENT_OCCLUSION_ID)
485 #define CLOSURE_IS_PHASE(type) (type == CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID)
486 #define CLOSURE_IS_GLASS(type) (type >= CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID && type <= CLOSURE_BSDF_SHARP_GLASS_ID)
487 #define CLOSURE_IS_PRINCIPLED(type) (type == CLOSURE_BSDF_PRINCIPLED_ID)
488
489 #define CLOSURE_WEIGHT_CUTOFF 1e-5f
490
491 CCL_NAMESPACE_END
492
493 #endif /*  __SVM_TYPES_H__ */
494