Blender  V2.93
bsdf_principled_sheen.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2017 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __BSDF_PRINCIPLED_SHEEN_H__
18 #define __BSDF_PRINCIPLED_SHEEN_H__
19 
20 /* DISNEY PRINCIPLED SHEEN BRDF
21  *
22  * Shading model by Brent Burley (Disney): "Physically Based Shading at Disney" (2012)
23  */
24 
26 
29  float avg_value;
31 
32 static_assert(sizeof(ShaderClosure) >= sizeof(PrincipledSheenBsdf),
33  "PrincipledSheenBsdf is too large!");
34 
36 {
37  /* To compute the average, we set the half-vector to the normal, resulting in
38  * NdotI = NdotL = NdotV = LdotH */
39  float NdotI = dot(N, I);
40  if (NdotI < 0.0f) {
41  return 0.0f;
42  }
43 
44  return schlick_fresnel(NdotI) * NdotI;
45 }
46 
49 {
50  float NdotL = dot(N, L);
51  float NdotV = dot(N, V);
52 
53  if (NdotL < 0 || NdotV < 0) {
54  *pdf = 0.0f;
55  return make_float3(0.0f, 0.0f, 0.0f);
56  }
57 
58  float LdotH = dot(L, H);
59 
60  float value = schlick_fresnel(LdotH) * NdotL;
61 
62  return make_float3(value, value, value);
63 }
64 
66 {
68  bsdf->avg_value = calculate_avg_principled_sheen_brdf(bsdf->N, sd->I);
69  bsdf->sample_weight *= bsdf->avg_value;
70  return SD_BSDF | SD_BSDF_HAS_EVAL;
71 }
72 
74  const float3 I,
75  const float3 omega_in,
76  float *pdf)
77 {
78  const PrincipledSheenBsdf *bsdf = (const PrincipledSheenBsdf *)sc;
79 
80  float3 N = bsdf->N;
81  float3 V = I; // outgoing
82  float3 L = omega_in; // incoming
83  float3 H = normalize(L + V);
84 
85  if (dot(N, omega_in) > 0.0f) {
86  *pdf = fmaxf(dot(N, omega_in), 0.0f) * M_1_PI_F;
87  return calculate_principled_sheen_brdf(N, V, L, H, pdf);
88  }
89  else {
90  *pdf = 0.0f;
91  return make_float3(0.0f, 0.0f, 0.0f);
92  }
93 }
94 
96  const float3 I,
97  const float3 omega_in,
98  float *pdf)
99 {
100  return make_float3(0.0f, 0.0f, 0.0f);
101 }
102 
104  float3 Ng,
105  float3 I,
106  float3 dIdx,
107  float3 dIdy,
108  float randu,
109  float randv,
110  float3 *eval,
111  float3 *omega_in,
112  float3 *domega_in_dx,
113  float3 *domega_in_dy,
114  float *pdf)
115 {
116  const PrincipledSheenBsdf *bsdf = (const PrincipledSheenBsdf *)sc;
117 
118  float3 N = bsdf->N;
119 
120  sample_cos_hemisphere(N, randu, randv, omega_in, pdf);
121 
122  if (dot(Ng, *omega_in) > 0) {
123  float3 H = normalize(I + *omega_in);
124 
125  *eval = calculate_principled_sheen_brdf(N, I, *omega_in, H, pdf);
126 
127 #ifdef __RAY_DIFFERENTIALS__
128  // TODO: find a better approximation for the diffuse bounce
129  *domega_in_dx = -((2 * dot(N, dIdx)) * N - dIdx);
130  *domega_in_dy = -((2 * dot(N, dIdy)) * N - dIdy);
131 #endif
132  }
133  else {
134  *pdf = 0.0f;
135  }
136  return LABEL_REFLECT | LABEL_DIFFUSE;
137 }
138 
140 
141 #endif /* __BSDF_PRINCIPLED_SHEEN_H__ */
ccl_device int bsdf_principled_sheen_sample(const ShaderClosure *sc, float3 Ng, float3 I, float3 dIdx, float3 dIdy, float randu, float randv, float3 *eval, float3 *omega_in, float3 *domega_in_dx, float3 *domega_in_dy, float *pdf)
ccl_device float3 bsdf_principled_sheen_eval_transmit(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
CCL_NAMESPACE_BEGIN typedef ccl_addr_space struct PrincipledSheenBsdf PrincipledSheenBsdf
ccl_device int bsdf_principled_sheen_setup(const ShaderData *sd, PrincipledSheenBsdf *bsdf)
ccl_device_inline float calculate_avg_principled_sheen_brdf(float3 N, float3 I)
ccl_device float3 calculate_principled_sheen_brdf(float3 N, float3 V, float3 L, float3 H, float *pdf)
ccl_device float3 bsdf_principled_sheen_eval_reflect(const ShaderClosure *sc, const float3 I, const float3 omega_in, float *pdf)
ccl_device float schlick_fresnel(float u)
Definition: bsdf_util.h:130
#define ccl_addr_space
#define ccl_device
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define fmaxf(x, y)
#define make_float3(x, y, z)
ccl_device_inline void sample_cos_hemisphere(const float3 N, float randu, float randv, float3 *omega_in, float *pdf)
@ SD_BSDF_HAS_EVAL
Definition: kernel_types.h:849
@ SD_BSDF
Definition: kernel_types.h:847
ShaderData
@ LABEL_DIFFUSE
Definition: kernel_types.h:330
@ LABEL_REFLECT
Definition: kernel_types.h:329
ShaderClosure
Definition: kernel_types.h:831
#define L
#define I
params N
@ CLOSURE_BSDF_PRINCIPLED_SHEEN_ID
Definition: svm_types.h:538
#define M_1_PI_F
Definition: util_math.h:52
ccl_device_inline float2 normalize(const float2 &a)
ccl_device_inline float dot(const float2 &a, const float2 &b)
#define H(x, y, z)
CCL_NAMESPACE_BEGIN struct View V