Blender  V3.3
bsdf_diffuse_ramp.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 <OpenImageIO/fmath.h>
10 
11 #include <OSL/genclosure.h>
12 
14 #include "kernel/osl/closures.h"
15 
16 // clang-format off
17 #include "kernel/types.h"
18 #include "kernel/closure/alloc.h"
21 // clang-format on
22 
24 
25 using namespace OSL;
26 
28  public:
29  DiffuseRampBsdf params;
30  Color3 colors[8];
31 
32  void setup(ShaderData *sd, uint32_t /* path_flag */, float3 weight)
33  {
34  params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
35 
36  DiffuseRampBsdf *bsdf = (DiffuseRampBsdf *)bsdf_alloc_osl(
37  sd, sizeof(DiffuseRampBsdf), weight, &params);
38 
39  if (bsdf) {
40  bsdf->colors = (float3 *)closure_alloc_extra(sd, sizeof(float3) * 8);
41 
42  if (bsdf->colors) {
43  for (int i = 0; i < 8; i++)
44  bsdf->colors[i] = TO_FLOAT3(colors[i]);
45 
46  sd->flag |= bsdf_diffuse_ramp_setup(bsdf);
47  }
48  }
49  }
50 };
51 
53 {
54  static ClosureParam params[] = {CLOSURE_FLOAT3_PARAM(DiffuseRampClosure, params.N),
55  CLOSURE_COLOR_ARRAY_PARAM(DiffuseRampClosure, colors, 8),
56  CLOSURE_STRING_KEYPARAM(DiffuseRampClosure, label, "label"),
57  CLOSURE_FINISH_PARAM(DiffuseRampClosure)};
58  return params;
59 }
60 
62 
ccl_device ccl_private void * closure_alloc_extra(ccl_private ShaderData *sd, int size)
Definition: alloc.h:29
ClosureParam * closure_bsdf_diffuse_ramp_params()
ccl_device float3 ensure_valid_reflection(float3 Ng, float3 I, float3 N)
Definition: bsdf_util.h:127
DiffuseRampBsdf params
void setup(ShaderData *sd, uint32_t, float3 weight)
#define CLOSURE_FLOAT3_PARAM(st, fld)
Definition: closures.h:79
#define CCLOSURE_PREPARE(name, classname)
Definition: closures.h:70
#define TO_FLOAT3(v)
Definition: closures.h:89
void closure_bsdf_diffuse_ramp_prepare(OSL::RendererServices *, int id, void *data)
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
const char * label
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ShaderData
Definition: kernel/types.h:925
unsigned int uint32_t
Definition: stdint.h:80