Blender V5.0
bsdf_burley.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2025 Sony Pictures Imageworks Inc., et al. All Rights Reserved.
2 * SPDX-FileCopyrightText: 2011-2025 Blender Foundation
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Adapted code from Open Shading Language. */
7
8#pragma once
9
12
14
15#ifdef __OSL__
16
17struct BurleyBsdf {
19
20 float roughness;
21};
22
23static_assert(sizeof(ShaderClosure) >= sizeof(BurleyBsdf), "BurleyBsdf is too large!");
24
25ccl_device Spectrum bsdf_burley_get_intensity(const float roughness,
26 const float3 n,
27 const float3 v,
28 const float3 l)
29{
30 const float NdotL = dot(n, l);
31 const float NdotV = dot(n, v);
32 const float fl = schlick_fresnel(NdotL);
33 const float fv = schlick_fresnel(NdotV);
34 const float LdotH = dot(l, normalize(l + v));
35 const float F90 = 0.5f + (2.0f * roughness * LdotH * LdotH);
36 return make_spectrum(M_1_PI_F * NdotL * mix(1.0f, F90, fl) * mix(1.0f, F90, fv));
37}
38
39ccl_device int bsdf_burley_setup(ccl_private BurleyBsdf *bsdf, const float roughness)
40{
41 bsdf->type = CLOSURE_BSDF_BURLEY_ID;
42 bsdf->roughness = saturatef(roughness);
44}
45
46ccl_device Spectrum bsdf_burley_eval(ccl_private const ShaderClosure *sc,
47 const float3 wi,
48 const float3 wo,
49 ccl_private float *pdf)
50{
51 ccl_private const BurleyBsdf *bsdf = (ccl_private const BurleyBsdf *)sc;
52
53 const float cosNO = dot(bsdf->N, wo);
54 if (cosNO > 0.0f) {
55 *pdf = cosNO * M_1_PI_F;
56 return bsdf_burley_get_intensity(bsdf->roughness, bsdf->N, wi, wo);
57 }
58 *pdf = 0.0f;
59 return zero_spectrum();
60}
61
62ccl_device int bsdf_burley_sample(ccl_private const ShaderClosure *sc,
63 float3 Ng,
64 float3 wi,
65 float2 rand,
68 ccl_private float *pdf)
69{
70 ccl_private const BurleyBsdf *bsdf = (ccl_private const BurleyBsdf *)sc;
71 float3 N = bsdf->N;
72
73 // distribution over the hemisphere
74 sample_cos_hemisphere(N, rand, wo, pdf);
75
76 if (dot(Ng, *wo) > 0.0f) {
77 *eval = bsdf_burley_get_intensity(bsdf->roughness, bsdf->N, wi, *wo);
78 }
79 else {
80 *pdf = 0.0f;
81 *eval = zero_spectrum();
82 }
84}
85
86#endif /* __OSL__ */
87
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert * v
ccl_device float schlick_fresnel(const float u)
Definition bsdf_util.h:261
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
#define SHADER_CLOSURE_BASE
#define zero_spectrum
#define make_spectrum(f)
#define ccl_private
#define M_1_PI_F
#define CCL_NAMESPACE_END
#define saturatef(x)
VecBase< float, D > normalize(VecOp< float, D >) RET
@ CLOSURE_BSDF_BURLEY_ID
@ SD_BSDF_HAS_EVAL
@ SD_BSDF
@ LABEL_DIFFUSE
@ LABEL_REFLECT
#define N
#define mix
#define ccl_device
ccl_device_inline void sample_cos_hemisphere(const float3 N, const float2 rand_in, ccl_private float3 *wo, ccl_private float *pdf)
float3 Spectrum