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