Blender V4.3
bsdf_diffuse_ramp.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2010 Sony Pictures Imageworks Inc., et al. All Rights Reserved.
2 * SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Adapted code from Open Shading Language. */
7
8#pragma once
9
11#include "kernel/util/color.h"
12
14
15#ifdef __OSL__
16
17typedef struct DiffuseRampBsdf {
19
20 ccl_private float3 *colors;
21} DiffuseRampBsdf;
22
23static_assert(sizeof(ShaderClosure) >= sizeof(DiffuseRampBsdf), "DiffuseRampBsdf is too large!");
24
25ccl_device float3 bsdf_diffuse_ramp_get_color(const float3 colors[8], float pos)
26{
27 int MAXCOLORS = 8;
28
29 float npos = pos * (float)(MAXCOLORS - 1);
30 int ipos = float_to_int(npos);
31 if (ipos < 0)
32 return colors[0];
33 if (ipos >= (MAXCOLORS - 1))
34 return colors[MAXCOLORS - 1];
35 float offset = npos - (float)ipos;
36 return colors[ipos] * (1.0f - offset) + colors[ipos + 1] * offset;
37}
38
39ccl_device int bsdf_diffuse_ramp_setup(DiffuseRampBsdf *bsdf)
40{
43}
44
45ccl_device void bsdf_diffuse_ramp_blur(ccl_private ShaderClosure *sc, float roughness) {}
46
47ccl_device Spectrum bsdf_diffuse_ramp_eval(ccl_private const ShaderClosure *sc,
48 const float3 wi,
49 const float3 wo,
50 ccl_private float *pdf)
51{
52 const DiffuseRampBsdf *bsdf = (const DiffuseRampBsdf *)sc;
53 float3 N = bsdf->N;
54
55 float cosNO = fmaxf(dot(N, wo), 0.0f);
56 if (cosNO >= 0.0f) {
57 *pdf = cosNO * M_1_PI_F;
58 return rgb_to_spectrum(bsdf_diffuse_ramp_get_color(bsdf->colors, cosNO) * M_1_PI_F);
59 }
60 else {
61 *pdf = 0.0f;
62 return zero_spectrum();
63 }
64}
65
66ccl_device int bsdf_diffuse_ramp_sample(ccl_private const ShaderClosure *sc,
67 float3 Ng,
68 float3 wi,
69 float2 rand,
72 ccl_private float *pdf)
73{
74 const DiffuseRampBsdf *bsdf = (const DiffuseRampBsdf *)sc;
75 float3 N = bsdf->N;
76
77 // distribution over the hemisphere
78 sample_cos_hemisphere(N, rand, wo, pdf);
79
80 if (dot(Ng, *wo) > 0.0f) {
81 *eval = rgb_to_spectrum(bsdf_diffuse_ramp_get_color(bsdf->colors, *pdf * M_PI_F) * M_1_PI_F);
82 }
83 else {
84 *pdf = 0.0f;
85 *eval = zero_spectrum();
86 }
88}
89
90#endif /* __OSL__ */
91
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
#define ccl_device
#define ccl_private
#define CCL_NAMESPACE_END
#define fmaxf(x, y)
draw_view in_light_buf[] float
@ CLOSURE_BSDF_DIFFUSE_RAMP_ID
@ SD_BSDF_HAS_EVAL
@ SD_BSDF
#define SHADER_CLOSURE_BASE
@ LABEL_DIFFUSE
@ LABEL_REFLECT
ShaderClosure
ccl_device_inline Spectrum rgb_to_spectrum(float3 rgb)
#define N
#define M_PI_F
Definition mikk_util.hh:15
ccl_device_inline void sample_cos_hemisphere(const float3 N, float2 rand_in, ccl_private float3 *wo, ccl_private float *pdf)
#define zero_spectrum
SPECTRUM_DATA_TYPE Spectrum
ccl_device_inline int float_to_int(float f)
Definition util/math.h:424