Blender V4.3
bsdf_diffuse.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
13
17
18static_assert(sizeof(ShaderClosure) >= sizeof(DiffuseBsdf), "DiffuseBsdf is too large!");
19
20/* DIFFUSE */
21
27
29 const float3 wi,
30 const float3 wo,
31 ccl_private float *pdf)
32{
33 ccl_private const DiffuseBsdf *bsdf = (ccl_private const DiffuseBsdf *)sc;
34 float3 N = bsdf->N;
35
36 float cosNO = fmaxf(dot(N, wo), 0.0f) * M_1_PI_F;
37 *pdf = cosNO;
38 return make_spectrum(cosNO);
39}
40
42 float3 Ng,
43 float3 wi,
44 float2 rand,
47 ccl_private float *pdf)
48{
49 ccl_private const DiffuseBsdf *bsdf = (ccl_private const DiffuseBsdf *)sc;
50 float3 N = bsdf->N;
51
52 // distribution over the hemisphere
53 sample_cos_hemisphere(N, rand, wo, pdf);
54
55 if (dot(Ng, *wo) > 0.0f) {
56 *eval = make_spectrum(*pdf);
57 }
58 else {
59 *pdf = 0.0f;
60 *eval = zero_spectrum();
61 }
63}
64
65/* TRANSLUCENT */
66
72
74 const float3 wi,
75 const float3 wo,
76 ccl_private float *pdf)
77{
78 ccl_private const DiffuseBsdf *bsdf = (ccl_private const DiffuseBsdf *)sc;
79 float3 N = bsdf->N;
80
81 float cosNO = fmaxf(-dot(N, wo), 0.0f) * M_1_PI_F;
82 *pdf = cosNO;
83 return make_spectrum(cosNO);
84}
85
87 float3 Ng,
88 float3 wi,
89 float2 rand,
92 ccl_private float *pdf)
93{
94 ccl_private const DiffuseBsdf *bsdf = (ccl_private const DiffuseBsdf *)sc;
95 float3 N = bsdf->N;
96
97 // we are viewing the surface from the right side - send a ray out with cosine
98 // distribution over the hemisphere
99 sample_cos_hemisphere(-N, rand, wo, pdf);
100 if (dot(Ng, *wo) < 0) {
101 *eval = make_spectrum(*pdf);
102 }
103 else {
104 *pdf = 0;
105 *eval = zero_spectrum();
106 }
108}
109
ccl_device Spectrum bsdf_diffuse_eval(ccl_private const ShaderClosure *sc, const float3 wi, const float3 wo, ccl_private float *pdf)
ccl_device int bsdf_diffuse_sample(ccl_private const ShaderClosure *sc, float3 Ng, float3 wi, float2 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf)
ccl_device int bsdf_translucent_setup(ccl_private DiffuseBsdf *bsdf)
ccl_device int bsdf_diffuse_setup(ccl_private DiffuseBsdf *bsdf)
ccl_device int bsdf_translucent_sample(ccl_private const ShaderClosure *sc, float3 Ng, float3 wi, float2 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf)
ccl_device Spectrum bsdf_translucent_eval(ccl_private const ShaderClosure *sc, const float3 wi, const float3 wo, ccl_private float *pdf)
CCL_NAMESPACE_BEGIN struct DiffuseBsdf DiffuseBsdf
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)
@ CLOSURE_BSDF_DIFFUSE_ID
@ CLOSURE_BSDF_TRANSLUCENT_ID
@ SD_BSDF_HAS_EVAL
@ SD_BSDF
@ SD_BSDF_HAS_TRANSMISSION
@ LABEL_TRANSMIT
@ LABEL_DIFFUSE
@ LABEL_REFLECT
ShaderClosure
#define N
ccl_device_inline void sample_cos_hemisphere(const float3 N, float2 rand_in, ccl_private float3 *wo, ccl_private float *pdf)
#define zero_spectrum
#define make_spectrum(f)
SPECTRUM_DATA_TYPE Spectrum