Blender  V3.3
bsdf_phong_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  PhongRampBsdf 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  PhongRampBsdf *bsdf = (PhongRampBsdf *)bsdf_alloc_osl(
37  sd, sizeof(PhongRampBsdf), 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_phong_ramp_setup(bsdf);
47  }
48  }
49  }
50 };
51 
53 {
54  static ClosureParam params[] = {CLOSURE_FLOAT3_PARAM(PhongRampClosure, params.N),
55  CLOSURE_FLOAT_PARAM(PhongRampClosure, params.exponent),
56  CLOSURE_COLOR_ARRAY_PARAM(PhongRampClosure, colors, 8),
57  CLOSURE_STRING_KEYPARAM(PhongRampClosure, label, "label"),
58  CLOSURE_FINISH_PARAM(PhongRampClosure)};
59  return params;
60 }
61 
63 
ccl_device ccl_private void * closure_alloc_extra(ccl_private ShaderData *sd, int size)
Definition: alloc.h:29
ClosureParam * closure_bsdf_phong_ramp_params()
ccl_device float3 ensure_valid_reflection(float3 Ng, float3 I, float3 N)
Definition: bsdf_util.h:127
PhongRampBsdf 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
void closure_bsdf_phong_ramp_prepare(OSL::RendererServices *, int id, void *data)
#define TO_FLOAT3(v)
Definition: closures.h:89
#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