Blender  V3.3
bssrdf.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Adapted from Open Shading Language
4  * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
5  * All Rights Reserved.
6  *
7  * Modifications Copyright 2011-2022 Blender Foundation. */
8 
9 #include <OSL/genclosure.h>
10 
12 #include "kernel/osl/closures.h"
13 
14 // clang-format off
15 #include "kernel/types.h"
16 
17 #include "kernel/closure/alloc.h"
21 #include "kernel/closure/bssrdf.h"
22 // clang-format on
23 
25 
26 using namespace OSL;
27 
28 static ustring u_burley("burley");
29 static ustring u_random_walk_fixed_radius("random_walk_fixed_radius");
30 static ustring u_random_walk("random_walk");
31 
33  public:
35  float ior;
36  ustring method;
37 
39  {
40  params.roughness = FLT_MAX;
41  params.anisotropy = 1.0f;
42  ior = 1.4f;
43  }
44 
45  void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
46  {
47  params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
48 
49  if (method == u_burley) {
50  alloc(sd, path_flag, weight, CLOSURE_BSSRDF_BURLEY_ID);
51  }
52  else if (method == u_random_walk_fixed_radius) {
53  alloc(sd, path_flag, weight, CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID);
54  }
55  else if (method == u_random_walk) {
56  alloc(sd, path_flag, weight, CLOSURE_BSSRDF_RANDOM_WALK_ID);
57  }
58  }
59 
60  void alloc(ShaderData *sd, uint32_t path_flag, float3 weight, ClosureType type)
61  {
62  Bssrdf *bssrdf = bssrdf_alloc(sd, weight);
63 
64  if (bssrdf) {
65  /* disable in case of diffuse ancestor, can't see it well then and
66  * adds considerably noise due to probabilities of continuing path
67  * getting lower and lower */
68  if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR) {
69  params.radius = make_float3(0.0f, 0.0f, 0.0f);
70  }
71 
72  /* create one closure per color channel */
73  bssrdf->radius = params.radius;
74  bssrdf->albedo = params.albedo;
75  bssrdf->N = params.N;
76  bssrdf->roughness = params.roughness;
77  bssrdf->anisotropy = clamp(params.anisotropy, 0.0f, 0.9f);
78  sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)type, clamp(ior, 1.01f, 3.8f));
79  }
80  }
81 };
82 
83 ClosureParam *closure_bssrdf_params()
84 {
85  static ClosureParam params[] = {
86  CLOSURE_STRING_PARAM(CBSSRDFClosure, method),
90  CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.roughness, "roughness"),
91  CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, ior, "ior"),
92  CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.anisotropy, "anisotropy"),
93  CLOSURE_STRING_KEYPARAM(CBSSRDFClosure, label, "label"),
94  CLOSURE_FINISH_PARAM(CBSSRDFClosure)};
95  return params;
96 }
97 
99 
_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 float3 ensure_valid_reflection(float3 Ng, float3 I, float3 N)
Definition: bsdf_util.h:127
static ustring u_burley("burley")
static ustring u_random_walk_fixed_radius("random_walk_fixed_radius")
ClosureParam * closure_bssrdf_params()
Definition: bssrdf.cpp:83
static ustring u_random_walk("random_walk")
ccl_device_inline ccl_private Bssrdf * bssrdf_alloc(ccl_private ShaderData *sd, float3 weight)
Definition: bssrdf.h:259
ccl_device int bssrdf_setup(ccl_private ShaderData *sd, ccl_private Bssrdf *bssrdf, ClosureType type, const float ior)
Definition: bssrdf.h:273
Bssrdf params
Definition: bssrdf.cpp:34
ustring method
Definition: bssrdf.cpp:36
void alloc(ShaderData *sd, uint32_t path_flag, float3 weight, ClosureType type)
Definition: bssrdf.cpp:60
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
Definition: bssrdf.cpp:45
void closure_bssrdf_prepare(OSL::RendererServices *, int id, void *data)
#define CLOSURE_FLOAT3_PARAM(st, fld)
Definition: closures.h:79
#define CCLOSURE_PREPARE(name, classname)
Definition: closures.h:70
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
const char * label
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ClosureType
@ CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID
@ CLOSURE_BSSRDF_BURLEY_ID
@ CLOSURE_BSSRDF_RANDOM_WALK_ID
@ PATH_RAY_DIFFUSE_ANCESTOR
Definition: kernel/types.h:229
ShaderData
Definition: kernel/types.h:925
#define make_float3(x, y, z)
Definition: metal/compat.h:204
T clamp(const T &a, const T &min, const T &max)
static const pxr::TfToken ior("ior", pxr::TfToken::Immortal)
closure color bssrdf(string method, normal N, vector radius, color albedo) BUILTIN
unsigned int uint32_t
Definition: stdint.h:80
Definition: bssrdf.h:8