Cycles: add Displacement node.
[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         NODE_DISPLACEMENT,
137 } ShaderNodeType;
138
139 typedef enum NodeAttributeType {
140         NODE_ATTR_FLOAT = 0,
141         NODE_ATTR_FLOAT3,
142         NODE_ATTR_MATRIX
143 } NodeAttributeType;
144
145 typedef enum NodeGeometry {
146         NODE_GEOM_P = 0,
147         NODE_GEOM_N,
148         NODE_GEOM_T,
149         NODE_GEOM_I,
150         NODE_GEOM_Ng,
151         NODE_GEOM_uv
152 } NodeGeometry;
153
154 typedef enum NodeObjectInfo {
155         NODE_INFO_OB_LOCATION,
156         NODE_INFO_OB_INDEX,
157         NODE_INFO_MAT_INDEX,
158         NODE_INFO_OB_RANDOM
159 } NodeObjectInfo;
160
161 typedef enum NodeParticleInfo {
162         NODE_INFO_PAR_INDEX,
163         NODE_INFO_PAR_AGE,
164         NODE_INFO_PAR_LIFETIME,
165         NODE_INFO_PAR_LOCATION,
166         NODE_INFO_PAR_ROTATION,
167         NODE_INFO_PAR_SIZE,
168         NODE_INFO_PAR_VELOCITY,
169         NODE_INFO_PAR_ANGULAR_VELOCITY
170 } NodeParticleInfo;
171
172 typedef enum NodeHairInfo {
173         NODE_INFO_CURVE_IS_STRAND,
174         NODE_INFO_CURVE_INTERCEPT,
175         NODE_INFO_CURVE_THICKNESS,
176         /*fade for minimum hair width transpency*/
177         /*NODE_INFO_CURVE_FADE,*/
178         NODE_INFO_CURVE_TANGENT_NORMAL
179 } NodeHairInfo;
180
181 typedef enum NodeLightPath {
182         NODE_LP_camera = 0,
183         NODE_LP_shadow,
184         NODE_LP_diffuse,
185         NODE_LP_glossy,
186         NODE_LP_singular,
187         NODE_LP_reflection,
188         NODE_LP_transmission,
189         NODE_LP_volume_scatter,
190         NODE_LP_backfacing,
191         NODE_LP_ray_length,
192         NODE_LP_ray_depth,
193         NODE_LP_ray_diffuse,
194         NODE_LP_ray_glossy,
195         NODE_LP_ray_transparent,
196         NODE_LP_ray_transmission,
197 } NodeLightPath;
198
199 typedef enum NodeLightFalloff {
200         NODE_LIGHT_FALLOFF_QUADRATIC,
201         NODE_LIGHT_FALLOFF_LINEAR,
202         NODE_LIGHT_FALLOFF_CONSTANT
203 } NodeLightFalloff;
204
205 typedef enum NodeTexCoord {
206         NODE_TEXCO_NORMAL,
207         NODE_TEXCO_OBJECT,
208         NODE_TEXCO_CAMERA,
209         NODE_TEXCO_WINDOW,
210         NODE_TEXCO_REFLECTION,
211         NODE_TEXCO_DUPLI_GENERATED,
212         NODE_TEXCO_DUPLI_UV,
213         NODE_TEXCO_VOLUME_GENERATED
214 } NodeTexCoord;
215
216 typedef enum NodeMix {
217         NODE_MIX_BLEND = 0,
218         NODE_MIX_ADD,
219         NODE_MIX_MUL,
220         NODE_MIX_SUB,
221         NODE_MIX_SCREEN,
222         NODE_MIX_DIV,
223         NODE_MIX_DIFF,
224         NODE_MIX_DARK,
225         NODE_MIX_LIGHT,
226         NODE_MIX_OVERLAY,
227         NODE_MIX_DODGE,
228         NODE_MIX_BURN,
229         NODE_MIX_HUE,
230         NODE_MIX_SAT,
231         NODE_MIX_VAL,
232         NODE_MIX_COLOR,
233         NODE_MIX_SOFT,
234         NODE_MIX_LINEAR,
235         NODE_MIX_CLAMP /* used for the clamp UI option */
236 } NodeMix;
237
238 typedef enum NodeMath {
239         NODE_MATH_ADD,
240         NODE_MATH_SUBTRACT,
241         NODE_MATH_MULTIPLY,
242         NODE_MATH_DIVIDE,
243         NODE_MATH_SINE,
244         NODE_MATH_COSINE,
245         NODE_MATH_TANGENT,
246         NODE_MATH_ARCSINE,
247         NODE_MATH_ARCCOSINE,
248         NODE_MATH_ARCTANGENT,
249         NODE_MATH_POWER,
250         NODE_MATH_LOGARITHM,
251         NODE_MATH_MINIMUM,
252         NODE_MATH_MAXIMUM,
253         NODE_MATH_ROUND,
254         NODE_MATH_LESS_THAN,
255         NODE_MATH_GREATER_THAN,
256         NODE_MATH_MODULO,
257         NODE_MATH_ABSOLUTE,
258         NODE_MATH_CLAMP /* used for the clamp UI option */
259 } NodeMath;
260
261 typedef enum NodeVectorMath {
262         NODE_VECTOR_MATH_ADD,
263         NODE_VECTOR_MATH_SUBTRACT,
264         NODE_VECTOR_MATH_AVERAGE,
265         NODE_VECTOR_MATH_DOT_PRODUCT,
266         NODE_VECTOR_MATH_CROSS_PRODUCT,
267         NODE_VECTOR_MATH_NORMALIZE
268 } NodeVectorMath;
269
270 typedef enum NodeVectorTransformType {
271         NODE_VECTOR_TRANSFORM_TYPE_VECTOR,
272         NODE_VECTOR_TRANSFORM_TYPE_POINT,
273         NODE_VECTOR_TRANSFORM_TYPE_NORMAL
274 } NodeVectorTransformType;
275
276 typedef enum NodeVectorTransformConvertSpace {
277         NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD,
278         NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT,
279         NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA
280 } NodeVectorTransformConvertSpace;
281
282 typedef enum NodeConvert {
283         NODE_CONVERT_FV,
284         NODE_CONVERT_FI,
285         NODE_CONVERT_CF,
286         NODE_CONVERT_CI,
287         NODE_CONVERT_VF,
288         NODE_CONVERT_VI,
289         NODE_CONVERT_IF,
290         NODE_CONVERT_IV
291 } NodeConvert;
292
293 typedef enum NodeMusgraveType {
294         NODE_MUSGRAVE_MULTIFRACTAL,
295         NODE_MUSGRAVE_FBM,
296         NODE_MUSGRAVE_HYBRID_MULTIFRACTAL,
297         NODE_MUSGRAVE_RIDGED_MULTIFRACTAL,
298         NODE_MUSGRAVE_HETERO_TERRAIN
299 } NodeMusgraveType;
300
301 typedef enum NodeWaveType {
302         NODE_WAVE_BANDS,
303         NODE_WAVE_RINGS
304 } NodeWaveType;
305
306 typedef enum NodeWaveProfiles {
307         NODE_WAVE_PROFILE_SIN,
308         NODE_WAVE_PROFILE_SAW,
309 } NodeWaveProfile;
310
311 typedef enum NodeSkyType {
312         NODE_SKY_OLD,
313         NODE_SKY_NEW
314 } NodeSkyType;
315
316 typedef enum NodeGradientType {
317         NODE_BLEND_LINEAR,
318         NODE_BLEND_QUADRATIC,
319         NODE_BLEND_EASING,
320         NODE_BLEND_DIAGONAL,
321         NODE_BLEND_RADIAL,
322         NODE_BLEND_QUADRATIC_SPHERE,
323         NODE_BLEND_SPHERICAL
324 } NodeGradientType;
325
326 typedef enum NodeVoronoiColoring {
327         NODE_VORONOI_INTENSITY,
328         NODE_VORONOI_CELLS
329 } NodeVoronoiColoring;
330
331 typedef enum NodeBlendWeightType {
332         NODE_LAYER_WEIGHT_FRESNEL,
333         NODE_LAYER_WEIGHT_FACING
334 } NodeBlendWeightType;
335
336 typedef enum NodeTangentDirectionType {
337         NODE_TANGENT_RADIAL,
338         NODE_TANGENT_UVMAP
339 } NodeTangentDirectionType;
340
341 typedef enum NodeTangentAxis {
342         NODE_TANGENT_AXIS_X,
343         NODE_TANGENT_AXIS_Y,
344         NODE_TANGENT_AXIS_Z
345 } NodeTangentAxis;
346
347 typedef enum NodeNormalMapSpace {
348         NODE_NORMAL_MAP_TANGENT,
349         NODE_NORMAL_MAP_OBJECT,
350         NODE_NORMAL_MAP_WORLD,
351         NODE_NORMAL_MAP_BLENDER_OBJECT,
352         NODE_NORMAL_MAP_BLENDER_WORLD,
353 } NodeNormalMapSpace;
354
355 typedef enum NodeImageColorSpace {
356         NODE_COLOR_SPACE_NONE  = 0,
357         NODE_COLOR_SPACE_COLOR = 1,
358 } NodeImageColorSpace;
359
360 typedef enum NodeImageProjection {
361         NODE_IMAGE_PROJ_FLAT   = 0,
362         NODE_IMAGE_PROJ_BOX    = 1,
363         NODE_IMAGE_PROJ_SPHERE = 2,
364         NODE_IMAGE_PROJ_TUBE   = 3,
365 } NodeImageProjection;
366
367 typedef enum NodeEnvironmentProjection {
368         NODE_ENVIRONMENT_EQUIRECTANGULAR = 0,
369         NODE_ENVIRONMENT_MIRROR_BALL = 1,
370 } NodeEnvironmentProjection;
371
372 typedef enum NodeBumpOffset {
373         NODE_BUMP_OFFSET_CENTER,
374         NODE_BUMP_OFFSET_DX,
375         NODE_BUMP_OFFSET_DY,
376 } NodeBumpOffset;
377
378 typedef enum NodeTexVoxelSpace {
379         NODE_TEX_VOXEL_SPACE_OBJECT = 0,
380         NODE_TEX_VOXEL_SPACE_WORLD  = 1,
381 } NodeTexVoxelSpace;
382
383 typedef enum ShaderType {
384         SHADER_TYPE_SURFACE,
385         SHADER_TYPE_VOLUME,
386         SHADER_TYPE_DISPLACEMENT,
387         SHADER_TYPE_BUMP,
388 } ShaderType;
389
390 /* Closure */
391
392 typedef enum ClosureType {
393         /* Special type, flags generic node as a non-BSDF. */
394         CLOSURE_NONE_ID,
395
396         CLOSURE_BSDF_ID,
397
398         /* Diffuse */
399         CLOSURE_BSDF_DIFFUSE_ID,
400         CLOSURE_BSDF_OREN_NAYAR_ID,
401         CLOSURE_BSDF_DIFFUSE_RAMP_ID,
402         CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID,
403         CLOSURE_BSDF_PRINCIPLED_SHEEN_ID,
404         CLOSURE_BSDF_DIFFUSE_TOON_ID,
405
406         /* Glossy */
407         CLOSURE_BSDF_REFLECTION_ID,
408         CLOSURE_BSDF_MICROFACET_GGX_ID,
409         CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID,
410         CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID,
411         CLOSURE_BSDF_MICROFACET_BECKMANN_ID,
412         CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID,
413         CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID,
414         CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID,
415         CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID,
416         CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID,
417         CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID,
418         CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_FRESNEL_ID,
419         CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID,
420         CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID,
421         CLOSURE_BSDF_ASHIKHMIN_VELVET_ID,
422         CLOSURE_BSDF_PHONG_RAMP_ID,
423         CLOSURE_BSDF_GLOSSY_TOON_ID,
424         CLOSURE_BSDF_HAIR_REFLECTION_ID,
425
426         /* Transmission */
427         CLOSURE_BSDF_TRANSLUCENT_ID,
428         CLOSURE_BSDF_REFRACTION_ID,
429         CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID,
430         CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID,
431         CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID,
432         CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID,
433         CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID,
434         CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID,
435         CLOSURE_BSDF_SHARP_GLASS_ID,
436         CLOSURE_BSDF_HAIR_TRANSMISSION_ID,
437
438         /* Special cases */
439         CLOSURE_BSDF_BSSRDF_ID,
440         CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID,
441         CLOSURE_BSDF_TRANSPARENT_ID,
442
443         /* BSSRDF */
444         CLOSURE_BSSRDF_CUBIC_ID,
445         CLOSURE_BSSRDF_GAUSSIAN_ID,
446         CLOSURE_BSSRDF_PRINCIPLED_ID,
447         CLOSURE_BSSRDF_BURLEY_ID,
448
449         /* Other */
450         CLOSURE_HOLDOUT_ID,
451         CLOSURE_AMBIENT_OCCLUSION_ID,
452
453         /* Volume */
454         CLOSURE_VOLUME_ID,
455         CLOSURE_VOLUME_ABSORPTION_ID,
456         CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID,
457
458         CLOSURE_BSDF_PRINCIPLED_ID,
459
460         NBUILTIN_CLOSURES
461 } ClosureType;
462
463 /* watch this, being lazy with memory usage */
464 #define CLOSURE_IS_BSDF(type) (type <= CLOSURE_BSDF_TRANSPARENT_ID)
465 #define CLOSURE_IS_BSDF_DIFFUSE(type) (type >= CLOSURE_BSDF_DIFFUSE_ID && type <= CLOSURE_BSDF_DIFFUSE_TOON_ID)
466 #define CLOSURE_IS_BSDF_GLOSSY(type) (type >= CLOSURE_BSDF_REFLECTION_ID && type <= CLOSURE_BSDF_HAIR_REFLECTION_ID)
467 #define CLOSURE_IS_BSDF_TRANSMISSION(type) (type >= CLOSURE_BSDF_TRANSLUCENT_ID && type <= CLOSURE_BSDF_HAIR_TRANSMISSION_ID)
468 #define CLOSURE_IS_BSDF_BSSRDF(type) (type == CLOSURE_BSDF_BSSRDF_ID || type == CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID)
469 #define CLOSURE_IS_BSDF_SINGULAR(type) (type == CLOSURE_BSDF_REFLECTION_ID || \
470                                         type == CLOSURE_BSDF_REFRACTION_ID || \
471                                         type == CLOSURE_BSDF_TRANSPARENT_ID)
472 #define CLOSURE_IS_BSDF_TRANSPARENT(type) (type == CLOSURE_BSDF_TRANSPARENT_ID)
473 #define CLOSURE_IS_BSDF_MULTISCATTER(type) (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID ||\
474                                             type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID || \
475                                             type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID)
476 #define CLOSURE_IS_BSDF_MICROFACET(type) ((type >= CLOSURE_BSDF_MICROFACET_GGX_ID && type <= CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID) ||\
477                                           (type >= CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID && type <= CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) ||\
478                                           (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID))
479 #define CLOSURE_IS_BSDF_OR_BSSRDF(type) (type <= CLOSURE_BSSRDF_BURLEY_ID)
480 #define CLOSURE_IS_BSSRDF(type) (type >= CLOSURE_BSSRDF_CUBIC_ID && type <= CLOSURE_BSSRDF_BURLEY_ID)
481 #define CLOSURE_IS_VOLUME(type) (type >= CLOSURE_VOLUME_ID && type <= CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID)
482 #define CLOSURE_IS_VOLUME_SCATTER(type) (type == CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID)
483 #define CLOSURE_IS_VOLUME_ABSORPTION(type) (type == CLOSURE_VOLUME_ABSORPTION_ID)
484 #define CLOSURE_IS_HOLDOUT(type) (type == CLOSURE_HOLDOUT_ID)
485 #define CLOSURE_IS_AMBIENT_OCCLUSION(type) (type == CLOSURE_AMBIENT_OCCLUSION_ID)
486 #define CLOSURE_IS_PHASE(type) (type == CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID)
487 #define CLOSURE_IS_GLASS(type) (type >= CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID && type <= CLOSURE_BSDF_SHARP_GLASS_ID)
488 #define CLOSURE_IS_PRINCIPLED(type) (type == CLOSURE_BSDF_PRINCIPLED_ID)
489
490 #define CLOSURE_WEIGHT_CUTOFF 1e-5f
491
492 CCL_NAMESPACE_END
493
494 #endif /*  __SVM_TYPES_H__ */
495