Remove redundant check for armature mode
[blender.git] / intern / cycles / kernel / osl / osl_closures.h
1 /*
2  * Adapted from Open Shading Language with this license:
3  *
4  * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
5  * All Rights Reserved.
6  *
7  * Modifications Copyright 2011, Blender Foundation.
8  * 
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are
11  * met:
12  * * Redistributions of source code must retain the above copyright
13  *   notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  *   notice, this list of conditions and the following disclaimer in the
16  *   documentation and/or other materials provided with the distribution.
17  * * Neither the name of Sony Pictures Imageworks nor the names of its
18  *   contributors may be used to endorse or promote products derived from
19  *   this software without specific prior written permission.
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef __OSL_CLOSURES_H__
34 #define __OSL_CLOSURES_H__
35
36 #include "util/util_types.h"
37 #include "kernel/kernel_types.h"
38
39 #include <OSL/oslclosure.h>
40 #include <OSL/oslexec.h>
41 #include <OSL/genclosure.h>
42
43 CCL_NAMESPACE_BEGIN
44
45 OSL::ClosureParam *closure_emission_params();
46 OSL::ClosureParam *closure_background_params();
47 OSL::ClosureParam *closure_holdout_params();
48 OSL::ClosureParam *closure_ambient_occlusion_params();
49 OSL::ClosureParam *closure_bsdf_diffuse_ramp_params();
50 OSL::ClosureParam *closure_bsdf_phong_ramp_params();
51 OSL::ClosureParam *closure_bsdf_transparent_params();
52 OSL::ClosureParam *closure_bssrdf_cubic_params();
53 OSL::ClosureParam *closure_bssrdf_gaussian_params();
54 OSL::ClosureParam *closure_bssrdf_burley_params();
55 OSL::ClosureParam *closure_bssrdf_principled_params();
56 OSL::ClosureParam *closure_absorption_params();
57 OSL::ClosureParam *closure_henyey_greenstein_params();
58 OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_params();
59 OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_glass_params();
60 OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_aniso_params();
61 OSL::ClosureParam *closure_bsdf_microfacet_ggx_fresnel_params();
62 OSL::ClosureParam *closure_bsdf_microfacet_ggx_aniso_fresnel_params();
63 OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_fresnel_params();
64 OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_glass_fresnel_params();
65 OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_aniso_fresnel_params();
66 OSL::ClosureParam *closure_bsdf_principled_clearcoat_params();
67
68 void closure_emission_prepare(OSL::RendererServices *, int id, void *data);
69 void closure_background_prepare(OSL::RendererServices *, int id, void *data);
70 void closure_holdout_prepare(OSL::RendererServices *, int id, void *data);
71 void closure_ambient_occlusion_prepare(OSL::RendererServices *, int id, void *data);
72 void closure_bsdf_diffuse_ramp_prepare(OSL::RendererServices *, int id, void *data);
73 void closure_bsdf_phong_ramp_prepare(OSL::RendererServices *, int id, void *data);
74 void closure_bsdf_transparent_prepare(OSL::RendererServices *, int id, void *data);
75 void closure_bssrdf_cubic_prepare(OSL::RendererServices *, int id, void *data);
76 void closure_bssrdf_gaussian_prepare(OSL::RendererServices *, int id, void *data);
77 void closure_bssrdf_burley_prepare(OSL::RendererServices *, int id, void *data);
78 void closure_bssrdf_principled_prepare(OSL::RendererServices *, int id, void *data);
79 void closure_absorption_prepare(OSL::RendererServices *, int id, void *data);
80 void closure_henyey_greenstein_prepare(OSL::RendererServices *, int id, void *data);
81 void closure_bsdf_microfacet_multi_ggx_prepare(OSL::RendererServices *, int id, void *data);
82 void closure_bsdf_microfacet_multi_ggx_glass_prepare(OSL::RendererServices *, int id, void *data);
83 void closure_bsdf_microfacet_multi_ggx_aniso_prepare(OSL::RendererServices *, int id, void *data);
84 void closure_bsdf_microfacet_ggx_fresnel_prepare(OSL::RendererServices *, int id, void *data);
85 void closure_bsdf_microfacet_ggx_aniso_fresnel_prepare(OSL::RendererServices *, int id, void *data);
86 void closure_bsdf_microfacet_multi_ggx_fresnel_prepare(OSL::RendererServices *, int id, void *data);
87 void closure_bsdf_microfacet_multi_ggx_glass_fresnel_prepare(OSL::RendererServices *, int id, void *data);
88 void closure_bsdf_microfacet_multi_ggx_aniso_fresnel_prepare(OSL::RendererServices *, int id, void *data);
89 void closure_bsdf_principled_clearcoat_prepare(OSL::RendererServices *, int id, void *data);
90
91 #define CCLOSURE_PREPARE(name, classname)          \
92 void name(RendererServices *, int id, void *data) \
93 {                                                 \
94         memset(data, 0, sizeof(classname));           \
95         new (data) classname();                       \
96 }
97
98 #define CCLOSURE_PREPARE_STATIC(name, classname) static CCLOSURE_PREPARE(name, classname)
99
100 #define CLOSURE_FLOAT3_PARAM(st, fld) \
101         { TypeDesc::TypeVector, (int)reckless_offsetof(st, fld), NULL, sizeof(OSL::Vec3) }
102
103 #define TO_VEC3(v) OSL::Vec3(v.x, v.y, v.z)
104 #define TO_COLOR3(v) OSL::Color3(v.x, v.y, v.z)
105 #define TO_FLOAT3(v) make_float3(v[0], v[1], v[2])
106
107 /* Closure */
108
109 class CClosurePrimitive {
110 public:
111         virtual void setup(ShaderData *sd, int path_flag, float3 weight) = 0;
112
113         OSL::ustring label;
114 };
115
116 /* BSDF */
117
118 class CBSDFClosure : public CClosurePrimitive {
119 public:
120         bool skip(const ShaderData *sd, int path_flag, int scattering);
121 };
122
123 #define BSDF_CLOSURE_CLASS_BEGIN(Upper, lower, structname, TYPE) \
124 \
125 class Upper##Closure : public CBSDFClosure { \
126 public: \
127         structname params; \
128         float3 unused; \
129 \
130         void setup(ShaderData *sd, int path_flag, float3 weight) \
131         { \
132             if(!skip(sd, path_flag, TYPE)) { \
133                         structname *bsdf = (structname*)bsdf_alloc_osl(sd, sizeof(structname), weight, &params); \
134                         sd->flag |= (bsdf) ? bsdf_##lower##_setup(bsdf) : 0; \
135                 } \
136         } \
137 }; \
138 \
139 static ClosureParam *bsdf_##lower##_params() \
140 { \
141         static ClosureParam params[] = {
142
143 /* parameters */
144
145 #define BSDF_CLOSURE_CLASS_END(Upper, lower) \
146                 CLOSURE_STRING_KEYPARAM(Upper##Closure, label, "label"), \
147                 CLOSURE_FINISH_PARAM(Upper##Closure) \
148         }; \
149         return params; \
150 } \
151 \
152 CCLOSURE_PREPARE_STATIC(bsdf_##lower##_prepare, Upper##Closure)
153
154 CCL_NAMESPACE_END
155
156 #endif /* __OSL_CLOSURES_H__ */
157