Blender  V2.93
osl_bssrdf.cpp
Go to the documentation of this file.
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 
37 
38 // clang-format off
39 #include "kernel/kernel_types.h"
41 
42 #include "kernel/closure/alloc.h"
46 #include "kernel/closure/bssrdf.h"
47 // clang-format on
48 
50 
51 using namespace OSL;
52 
53 static ustring u_cubic("cubic");
54 static ustring u_gaussian("gaussian");
55 static ustring u_burley("burley");
56 static ustring u_principled("principled");
57 static ustring u_random_walk("random_walk");
58 static ustring u_principled_random_walk("principled_random_walk");
59 
61  public:
63  ustring method;
64 
66  {
67  params.texture_blur = 0.0f;
68  params.sharpness = 0.0f;
69  params.roughness = 0.0f;
70  }
71 
72  void setup(ShaderData *sd, int path_flag, float3 weight)
73  {
74  if (method == u_cubic) {
75  alloc(sd, path_flag, weight, CLOSURE_BSSRDF_CUBIC_ID);
76  }
77  else if (method == u_gaussian) {
78  alloc(sd, path_flag, weight, CLOSURE_BSSRDF_GAUSSIAN_ID);
79  }
80  else if (method == u_burley) {
81  alloc(sd, path_flag, weight, CLOSURE_BSSRDF_BURLEY_ID);
82  }
83  else if (method == u_principled) {
84  alloc(sd, path_flag, weight, CLOSURE_BSSRDF_PRINCIPLED_ID);
85  }
86  else if (method == u_random_walk) {
87  alloc(sd, path_flag, weight, CLOSURE_BSSRDF_RANDOM_WALK_ID);
88  }
89  else if (method == u_principled_random_walk) {
90  alloc(sd, path_flag, weight, CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID);
91  }
92  }
93 
94  void alloc(ShaderData *sd, int path_flag, float3 weight, ClosureType type)
95  {
96  Bssrdf *bssrdf = bssrdf_alloc(sd, weight);
97 
98  if (bssrdf) {
99  /* disable in case of diffuse ancestor, can't see it well then and
100  * adds considerably noise due to probabilities of continuing path
101  * getting lower and lower */
102  if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR) {
103  params.radius = make_float3(0.0f, 0.0f, 0.0f);
104  }
105 
106  /* create one closure per color channel */
107  bssrdf->radius = params.radius;
108  bssrdf->albedo = params.albedo;
109  bssrdf->texture_blur = params.texture_blur;
110  bssrdf->sharpness = params.sharpness;
111  bssrdf->N = params.N;
112  bssrdf->roughness = params.roughness;
113  sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)type);
114  }
115  }
116 };
117 
118 ClosureParam *closure_bssrdf_params()
119 {
120  static ClosureParam params[] = {
121  CLOSURE_STRING_PARAM(CBSSRDFClosure, method),
125  CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.texture_blur, "texture_blur"),
126  CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.sharpness, "sharpness"),
127  CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.roughness, "roughness"),
128  CLOSURE_STRING_KEYPARAM(CBSSRDFClosure, label, "label"),
129  CLOSURE_FINISH_PARAM(CBSSRDFClosure)};
130  return params;
131 }
132 
134 
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
ccl_device int bssrdf_setup(ShaderData *sd, Bssrdf *bssrdf, ClosureType type)
Definition: bssrdf.h:345
ccl_device_inline Bssrdf * bssrdf_alloc(ShaderData *sd, float3 weight)
Definition: bssrdf.h:332
void alloc(ShaderData *sd, int path_flag, float3 weight, ClosureType type)
Definition: osl_bssrdf.cpp:94
void setup(ShaderData *sd, int path_flag, float3 weight)
Definition: osl_bssrdf.cpp:72
ustring method
Definition: osl_bssrdf.cpp:63
const char * label
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define CCL_NAMESPACE_END
#define make_float3(x, y, z)
@ PATH_RAY_DIFFUSE_ANCESTOR
Definition: kernel_types.h:302
ShaderData
static ustring u_burley("burley")
static ustring u_cubic("cubic")
static ustring u_principled("principled")
static ustring u_principled_random_walk("principled_random_walk")
ClosureParam * closure_bssrdf_params()
Definition: osl_bssrdf.cpp:118
static ustring u_random_walk("random_walk")
static ustring u_gaussian("gaussian")
void closure_bssrdf_prepare(OSL::RendererServices *, int id, void *data)
#define CLOSURE_FLOAT3_PARAM(st, fld)
Definition: osl_closures.h:103
#define CCLOSURE_PREPARE(name, classname)
Definition: osl_closures.h:94
closure color bssrdf(string method, normal N, vector radius, color albedo) BUILTIN
Definition: bssrdf.h:22
ClosureType
Definition: svm_types.h:527
@ CLOSURE_BSSRDF_CUBIC_ID
Definition: svm_types.h:574
@ CLOSURE_BSSRDF_GAUSSIAN_ID
Definition: svm_types.h:575
@ CLOSURE_BSSRDF_BURLEY_ID
Definition: svm_types.h:577
@ CLOSURE_BSSRDF_RANDOM_WALK_ID
Definition: svm_types.h:578
@ CLOSURE_BSSRDF_PRINCIPLED_ID
Definition: svm_types.h:576
@ CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID
Definition: svm_types.h:579