Remove redundant check for armature mode
[blender.git] / intern / cycles / kernel / osl / osl_bssrdf.cpp
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 #include <OSL/genclosure.h>
34
35 #include "kernel/kernel_compat_cpu.h"
36 #include "kernel/osl/osl_closures.h"
37
38 #include "kernel/kernel_types.h"
39 #include "kernel/kernel_montecarlo.h"
40
41 #include "kernel/closure/alloc.h"
42 #include "kernel/closure/bsdf_util.h"
43 #include "kernel/closure/bsdf_diffuse.h"
44 #include "kernel/closure/bsdf_principled_diffuse.h"
45 #include "kernel/closure/bssrdf.h"
46
47 CCL_NAMESPACE_BEGIN
48
49 using namespace OSL;
50
51 class CBSSRDFClosure : public CClosurePrimitive {
52 public:
53         Bssrdf params;
54
55         void alloc(ShaderData *sd, int path_flag, float3 weight, ClosureType type)
56         {
57                 Bssrdf *bssrdf = bssrdf_alloc(sd, weight);
58
59                 if(bssrdf) {
60                         /* disable in case of diffuse ancestor, can't see it well then and
61                          * adds considerably noise due to probabilities of continuing path
62                          * getting lower and lower */
63                         if(path_flag & PATH_RAY_DIFFUSE_ANCESTOR) {
64                                 params.radius = make_float3(0.0f, 0.0f, 0.0f);
65                         }
66
67                         /* create one closure per color channel */
68                         bssrdf->radius = params.radius;
69                         bssrdf->albedo = params.albedo;
70                         bssrdf->texture_blur = params.texture_blur;
71                         bssrdf->sharpness = params.sharpness;
72                         bssrdf->N = params.N;
73                         bssrdf->roughness = params.roughness;
74                         sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)type);
75                 }
76         }
77 };
78
79 /* Cubic */
80
81 class CubicBSSRDFClosure : public CBSSRDFClosure {
82 public:
83         void setup(ShaderData *sd, int path_flag, float3 weight)
84         {
85                 alloc(sd, path_flag, weight, CLOSURE_BSSRDF_CUBIC_ID);
86         }
87 };
88
89 ClosureParam *closure_bssrdf_cubic_params()
90 {
91         static ClosureParam params[] = {
92                 CLOSURE_FLOAT3_PARAM(CubicBSSRDFClosure, params.N),
93                 CLOSURE_FLOAT3_PARAM(CubicBSSRDFClosure, params.radius),
94                 CLOSURE_FLOAT_PARAM(CubicBSSRDFClosure, params.texture_blur),
95                 CLOSURE_FLOAT_PARAM(CubicBSSRDFClosure, params.sharpness),
96                 CLOSURE_STRING_KEYPARAM(CubicBSSRDFClosure, label, "label"),
97                 CLOSURE_FINISH_PARAM(CubicBSSRDFClosure)
98         };
99         return params;
100 }
101
102 CCLOSURE_PREPARE(closure_bssrdf_cubic_prepare, CubicBSSRDFClosure)
103
104 /* Gaussian */
105
106 class GaussianBSSRDFClosure : public CBSSRDFClosure {
107 public:
108         void setup(ShaderData *sd, int path_flag, float3 weight)
109         {
110                 alloc(sd, path_flag, weight, CLOSURE_BSSRDF_GAUSSIAN_ID);
111         }
112 };
113
114 ClosureParam *closure_bssrdf_gaussian_params()
115 {
116         static ClosureParam params[] = {
117                 CLOSURE_FLOAT3_PARAM(GaussianBSSRDFClosure, params.N),
118                 CLOSURE_FLOAT3_PARAM(GaussianBSSRDFClosure, params.radius),
119                 CLOSURE_FLOAT_PARAM(GaussianBSSRDFClosure, params.texture_blur),
120                 CLOSURE_STRING_KEYPARAM(GaussianBSSRDFClosure, label, "label"),
121                 CLOSURE_FINISH_PARAM(GaussianBSSRDFClosure)
122         };
123         return params;
124 }
125
126 CCLOSURE_PREPARE(closure_bssrdf_gaussian_prepare, GaussianBSSRDFClosure)
127
128 /* Burley */
129
130 class BurleyBSSRDFClosure : public CBSSRDFClosure {
131 public:
132         void setup(ShaderData *sd, int path_flag, float3 weight)
133         {
134                 alloc(sd, path_flag, weight, CLOSURE_BSSRDF_BURLEY_ID);
135         }
136 };
137
138 ClosureParam *closure_bssrdf_burley_params()
139 {
140         static ClosureParam params[] = {
141                 CLOSURE_FLOAT3_PARAM(BurleyBSSRDFClosure, params.N),
142                 CLOSURE_FLOAT3_PARAM(BurleyBSSRDFClosure, params.radius),
143                 CLOSURE_FLOAT_PARAM(BurleyBSSRDFClosure, params.texture_blur),
144                 CLOSURE_FLOAT3_PARAM(BurleyBSSRDFClosure, params.albedo),
145                 CLOSURE_STRING_KEYPARAM(BurleyBSSRDFClosure, label, "label"),
146                 CLOSURE_FINISH_PARAM(BurleyBSSRDFClosure)
147         };
148         return params;
149 }
150
151 CCLOSURE_PREPARE(closure_bssrdf_burley_prepare, BurleyBSSRDFClosure)
152
153 /* Disney principled */
154
155 class PrincipledBSSRDFClosure : public CBSSRDFClosure {
156 public:
157         void setup(ShaderData *sd, int path_flag, float3 weight)
158         {
159                 alloc(sd, path_flag, weight, CLOSURE_BSSRDF_PRINCIPLED_ID);
160         }
161 };
162
163 ClosureParam *closure_bssrdf_principled_params()
164 {
165         static ClosureParam params[] = {
166                 CLOSURE_FLOAT3_PARAM(PrincipledBSSRDFClosure, params.N),
167                 CLOSURE_FLOAT3_PARAM(PrincipledBSSRDFClosure, params.radius),
168                 CLOSURE_FLOAT_PARAM(PrincipledBSSRDFClosure, params.texture_blur),
169                 CLOSURE_FLOAT3_PARAM(PrincipledBSSRDFClosure, params.albedo),
170                 CLOSURE_FLOAT_PARAM(PrincipledBSSRDFClosure, params.roughness),
171                 CLOSURE_STRING_KEYPARAM(PrincipledBSSRDFClosure, label, "label"),
172                 CLOSURE_FINISH_PARAM(PrincipledBSSRDFClosure)
173         };
174         return params;
175 }
176
177 CCLOSURE_PREPARE(closure_bssrdf_principled_prepare, PrincipledBSSRDFClosure)
178
179 CCL_NAMESPACE_END
180