Blender V4.5
bsdf_microfacet.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
13
14#include "util/math_fast.h"
15
17
22
24 NONE = 0,
26 DIELECTRIC_TINT, /* used by the OSL MaterialX closures */
30};
31
33 float thickness;
34 float ior;
35};
36
43
47
50
53 /* Reflectivity at perpendicular (F0) and glancing (F90) angles. */
55 /* Negative exponent signals a special case where the real Fresnel is remapped to F0...F90. */
56 float exponent;
57};
58
60 /* Perpendicular reflectivity. */
62 /* Precomputed (1-cos)^6 factor for edge tint. */
64};
65
68
70
71 /* Used to account for missing energy due to the single-scattering microfacet model.
72 * This could be included in bsdf->weight as well, but there it would mess up the color
73 * channels.
74 * Note that this is currently only used by GGX. */
76
77 /* Fresnel model to apply, as well as the extra data for it.
78 * For NONE and DIELECTRIC, no extra storage is needed, so the pointer is nullptr for them. */
81
83};
84
85static_assert(sizeof(ShaderClosure) >= sizeof(MicrofacetBsdf), "MicrofacetBsdf is too large!");
86
87/* Beckmann VNDF importance sampling algorithm from:
88 * Importance Sampling Microfacet-Based BSDFs using the Distribution of Visible Normals.
89 * Eric Heitz and Eugene d'Eon, EGSR 2014.
90 * https://hal.inria.fr/hal-00996995v2/document */
91
93 const float alpha_x,
94 const float alpha_y,
95 const float2 rand)
96{
97 /* 1. stretch wi */
98 float3 wi_ = make_float3(alpha_x * wi.x, alpha_y * wi.y, wi.z);
99 wi_ = normalize(wi_);
100
101 /* 2. sample P22_{wi}(x_slope, y_slope, 1, 1) */
102 float2 slope;
103 float cos_phi_i = 1.0f;
104 float sin_phi_i = 0.0f;
105
106 if (wi_.z >= 0.99999f) {
107 /* Special case (normal incidence). */
108 const float r = sqrtf(-logf(rand.x));
109 const float phi = M_2PI_F * rand.y;
110 slope = polar_to_cartesian(r, phi);
111 }
112 else {
113 /* Precomputations. */
114 const float cos_theta_i = wi_.z;
115 const float sin_theta_i = sin_from_cos(cos_theta_i);
116 const float tan_theta_i = sin_theta_i / cos_theta_i;
117 const float cot_theta_i = 1.0f / tan_theta_i;
118 const float erf_a = fast_erff(cot_theta_i);
119 const float exp_a2 = expf(-cot_theta_i * cot_theta_i);
120 const float SQRT_PI_INV = 0.56418958354f;
121
122 const float invlen = 1.0f / sin_theta_i;
123 cos_phi_i = wi_.x * invlen;
124 sin_phi_i = wi_.y * invlen;
125
126 /* Based on paper from Wenzel Jakob
127 * An Improved Visible Normal Sampling Routine for the Beckmann Distribution
128 *
129 * http://www.mitsuba-renderer.org/~wenzel/files/visnormal.pdf
130 *
131 * Reformulation from OpenShadingLanguage which avoids using inverse
132 * trigonometric functions.
133 */
134
135 /* Sample slope X.
136 *
137 * Compute a coarse approximation using the approximation:
138 * `exp(-ierf(x)^2) ~= 1 - x * x`
139 * `solve y = 1 + b + K * (1 - b * b)`
140 */
141 const float K = tan_theta_i * SQRT_PI_INV;
142 const float y_approx = rand.x * (1.0f + erf_a + K * (1 - erf_a * erf_a));
143 const float y_exact = rand.x * (1.0f + erf_a + K * exp_a2);
144 const float b = K > 0 ? (0.5f - sqrtf(K * (K - y_approx + 1.0f) + 0.25f)) / K :
145 y_approx - 1.0f;
146
147 float inv_erf = fast_ierff(b);
148 float2 begin = make_float2(-1.0f, -y_exact);
149 float2 end = make_float2(erf_a, 1.0f + erf_a + K * exp_a2 - y_exact);
150 float2 current = make_float2(b, 1.0f + b + K * expf(-sqr(inv_erf)) - y_exact);
151
152 /* Find root in a monotonic interval using newton method, under given precision and maximal
153 * iterations. Falls back to bisection if newton step produces results outside of the valid
154 * interval. */
155 const float precision = 1e-6f;
156 const int max_iter = 3;
157 int iter = 0;
158 while (fabsf(current.y) > precision && iter++ < max_iter) {
159 if (signf(begin.y) == signf(current.y)) {
160 begin.x = current.x;
161 begin.y = current.y;
162 }
163 else {
164 end.x = current.x;
165 }
166 const float newton_x = current.x - current.y / (1.0f - inv_erf * tan_theta_i);
167 current.x = (newton_x >= begin.x && newton_x <= end.x) ? newton_x : 0.5f * (begin.x + end.x);
168 inv_erf = fast_ierff(current.x);
169 current.y = 1.0f + current.x + K * expf(-sqr(inv_erf)) - y_exact;
170 }
171
172 slope.x = inv_erf;
173 slope.y = fast_ierff(2.0f * rand.y - 1.0f);
174 }
175
176 /* 3. rotate */
177 slope = make_float2(cos_phi_i * slope.x - sin_phi_i * slope.y,
178 sin_phi_i * slope.x + cos_phi_i * slope.y);
179
180 /* 4. unstretch */
181 slope *= make_float2(alpha_x, alpha_y);
182
183 /* 5. compute normal */
184 return normalize(make_float3(-slope.x, -slope.y, 1.0f));
185}
186
187/* GGX VNDF importance sampling algorithm from:
188 * Sampling the GGX Distribution of Visible Normals.
189 * Eric Heitz, JCGT Vol. 7, No. 4, 2018.
190 * https://jcgt.org/published/0007/04/01/ */
192 const float alpha_x,
193 const float alpha_y,
194 const float2 rand)
195{
196 /* Section 3.2: Transforming the view direction to the hemisphere configuration. */
197 const float3 wi_ = normalize(make_float3(alpha_x * wi.x, alpha_y * wi.y, wi.z));
198
199 /* Section 4.1: Orthonormal basis. */
200 const float lensq = sqr(wi_.x) + sqr(wi_.y);
201 float3 T1;
202 float3 T2;
203 if (lensq > 1e-7f) {
204 T1 = make_float3(-wi_.y, wi_.x, 0.0f) * inversesqrtf(lensq);
205 T2 = cross(wi_, T1);
206 }
207 else {
208 /* Normal incidence, any basis is fine. */
209 T1 = make_float3(1.0f, 0.0f, 0.0f);
210 T2 = make_float3(0.0f, 1.0f, 0.0f);
211 }
212
213 /* Section 4.2: Parameterization of the projected area. */
214 float2 t = sample_uniform_disk(rand);
215 t.y = mix(safe_sqrtf(1.0f - sqr(t.x)), t.y, 0.5f * (1.0f + wi_.z));
216
217 /* Section 4.3: Reprojection onto hemisphere. */
218 const float3 H_ = to_global(disk_to_hemisphere(t), T1, T2, wi_);
219
220 /* Section 3.4: Transforming the normal back to the ellipsoid configuration. */
221 return normalize(make_float3(alpha_x * H_.x, alpha_y * H_.y, max(0.0f, H_.z)));
222}
223
224/* Computes the Fresnel reflectance and transmittance given the Microfacet BSDF and the cosine of
225 * the incoming angle `cos_theta_i`.
226 * Also returns the cosine of the angle between the normal and the refracted ray as `r_cos_theta_t`
227 * if provided. */
229 const ccl_private MicrofacetBsdf *bsdf,
230 const float cos_theta_i,
231 ccl_private float *r_cos_theta_t,
232 ccl_private Spectrum *r_reflectance,
233 ccl_private Spectrum *r_transmittance)
234{
235 /* Whether the closure has reflective or transmissive lobes. */
236 const bool has_reflection = !CLOSURE_IS_REFRACTION(bsdf->type);
237 const bool has_transmission = CLOSURE_IS_GLASS(bsdf->type) || !has_reflection;
238
239 if (bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC) {
240 const Spectrum F = make_spectrum(fresnel_dielectric(cos_theta_i, bsdf->ior, r_cos_theta_t));
241 *r_reflectance = F;
242 *r_transmittance = one_spectrum() - F;
243 }
244 else if (bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC_TINT) {
246 bsdf->fresnel;
247 const float F = fresnel_dielectric(cos_theta_i, bsdf->ior, r_cos_theta_t);
248 *r_reflectance = F * fresnel->reflection_tint;
249 *r_transmittance = (1.0f - F) * fresnel->transmission_tint;
250 }
251 else if (bsdf->fresnel_type == MicrofacetFresnel::CONDUCTOR) {
252 ccl_private FresnelConductor *fresnel = (ccl_private FresnelConductor *)bsdf->fresnel;
253 *r_reflectance = fresnel_conductor(cos_theta_i, fresnel->n, fresnel->k);
254 *r_transmittance = zero_spectrum();
255 }
256 else if (bsdf->fresnel_type == MicrofacetFresnel::F82_TINT) {
257 /* F82-Tint model, described in "Novel aspects of the Adobe Standard Material" by Kutz et al.
258 * Essentially, this is the usual Schlick Fresnel with an additional cosI*(1-cosI)^6
259 * term which modulates the reflectivity around acos(1/7) degrees (ca. 82°). */
260 ccl_private FresnelF82Tint *fresnel = (ccl_private FresnelF82Tint *)bsdf->fresnel;
261 const float mu = saturatef(1.0f - cos_theta_i);
262 const float mu5 = sqr(sqr(mu)) * mu;
263 const Spectrum F_schlick = mix(fresnel->f0, one_spectrum(), mu5);
264 *r_reflectance = saturate(F_schlick - fresnel->b * cos_theta_i * mu5 * mu);
265 *r_transmittance = zero_spectrum();
266 }
267 else if (bsdf->fresnel_type == MicrofacetFresnel::GENERALIZED_SCHLICK) {
269 bsdf->fresnel;
270 Spectrum F;
271 if (fresnel->thin_film.thickness > 0.1f) {
272 /* Iridescence doesn't combine well with the general case. We only expose it through the
273 * Principled BSDF for now, so it's fine to not support custom exponents and F90. */
274 kernel_assert(fresnel->exponent < 0.0f);
275 kernel_assert(fresnel->f90 == one_spectrum());
277 1.0f,
278 fresnel->thin_film.ior,
279 bsdf->ior,
280 cos_theta_i,
281 fresnel->thin_film.thickness,
282 r_cos_theta_t);
283 /* Apply F0 scaling (here per-channel, since iridescence produces colored output).
284 * Note that the usual approach (as used below) cannot be used here, since F may be below
285 * F0_real. Therefore, use a different approach: Scale the result by (F0 / F0_real), with
286 * the strength of the scaling depending on how close F is to F0_real.
287 * There isn't one single "correct" way to do this, it's just for artistic control anyways.
288 */
289 const float F0_real = F0_from_ior(bsdf->ior);
290 if (F0_real > 1e-5f && !isequal(F, one_spectrum())) {
292 const float s = saturatef(inverse_lerp(1.0f, F0_real, GET_SPECTRUM_CHANNEL(F, i)));
293 const float factor = GET_SPECTRUM_CHANNEL(fresnel->f0, i) / F0_real;
294 GET_SPECTRUM_CHANNEL(F, i) *= mix(1.0f, factor, s);
295 }
296 }
297 }
298 else if (fresnel->exponent < 0.0f) {
299 /* Special case: Use real Fresnel curve to determine the interpolation between F0 and F90.
300 * Used by Principled BSDF. */
301 const float F_real = fresnel_dielectric(cos_theta_i, bsdf->ior, r_cos_theta_t);
302 const float F0_real = F0_from_ior(bsdf->ior);
303 const float s = saturatef(inverse_lerp(F0_real, 1.0f, F_real));
304 F = mix(fresnel->f0, fresnel->f90, s);
305 }
306 else {
307 /* Regular case: Generalized Schlick term. */
308 const float cos_theta_t_sq = 1.0f - (1.0f - sqr(cos_theta_i)) / sqr(bsdf->ior);
309 if (cos_theta_t_sq <= 0.0f) {
310 /* Total internal reflection */
311 *r_reflectance = fresnel->reflection_tint * (float)has_reflection;
312 *r_transmittance = zero_spectrum();
313 return;
314 }
315 const float cos_theta_t = sqrtf(cos_theta_t_sq);
316 if (r_cos_theta_t) {
317 *r_cos_theta_t = cos_theta_t;
318 }
319
320 /* TODO(lukas): Is a special case for exponent==5 worth it? */
321 /* When going from a higher to a lower IOR, we must use the transmitted angle. */
322 const float fresnel_angle = ((bsdf->ior < 1.0f) ? cos_theta_t : cos_theta_i);
323 const float s = powf(1.0f - fresnel_angle, fresnel->exponent);
324 F = mix(fresnel->f0, fresnel->f90, s);
325 }
326 *r_reflectance = F * fresnel->reflection_tint;
327 *r_transmittance = (one_spectrum() - F) * fresnel->transmission_tint;
328 }
329 else {
330 kernel_assert(bsdf->fresnel_type == MicrofacetFresnel::NONE);
331 /* No Fresnel used, this is either purely reflective or purely refractive closure. */
332 *r_reflectance = *r_transmittance = one_spectrum();
333
334 /* Exclude total internal reflection. */
335 if (has_transmission && fresnel_dielectric(cos_theta_i, bsdf->ior, r_cos_theta_t) == 1.0f) {
336 *r_transmittance = zero_spectrum();
337 }
338 }
339
340 *r_reflectance *= (float)has_reflection;
341 *r_transmittance *= (float)has_transmission;
342}
343
346 const ccl_private ShaderData *sd,
347 const Spectrum Fss)
348{
349 const float mu = dot(sd->wi, bsdf->N);
350 const float rough = sqrtf(sqrtf(bsdf->alpha_x * bsdf->alpha_y));
351
352 float E;
353 float E_avg;
354 if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_ID) {
355 E = lookup_table_read_2D(kg, rough, mu, kernel_data.tables.ggx_E, 32, 32);
356 E_avg = lookup_table_read(kg, rough, kernel_data.tables.ggx_Eavg, 32);
357 }
358 else if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID) {
359 int ofs = kernel_data.tables.ggx_glass_E;
360 int avg_ofs = kernel_data.tables.ggx_glass_Eavg;
361 float ior = bsdf->ior;
362 if (ior < 1.0f) {
363 ior = 1.0f / ior;
364 ofs = kernel_data.tables.ggx_glass_inv_E;
365 avg_ofs = kernel_data.tables.ggx_glass_inv_Eavg;
366 }
367 /* TODO: Bias mu towards more precision for low values. */
368 const float z = sqrtf(fabsf((ior - 1.0f) / (ior + 1.0f)));
369 E = lookup_table_read_3D(kg, rough, mu, z, ofs, 16, 16, 16);
370 E_avg = lookup_table_read_2D(kg, rough, z, avg_ofs, 16, 16);
371 }
372 else {
373 kernel_assert(false);
374 E = 1.0f;
375 E_avg = 1.0f;
376 }
377
378 const float missing_factor = ((1.0f - E) / E);
379 bsdf->energy_scale = 1.0f + missing_factor;
380
381 /* Check if we need to account for extra darkening/saturation due to multi-bounce Fresnel. */
382 if (!isequal(Fss, one_spectrum())) {
383 /* Fms here is based on the appendix of "Revisiting Physically Based Shading at Imageworks"
384 * by Christopher Kulla and Alejandro Conty,
385 * with one Fss cancelled out since this is just a multiplier on top of
386 * the single-scattering BSDF, which already contains one bounce of Fresnel. */
387 const Spectrum Fms = Fss * E_avg / (one_spectrum() - Fss * (1.0f - E_avg));
388 /* Since we already include the energy compensation in bsdf->energy_scale,
389 * this term is what's needed to make the full BSDF * weight * energy_scale
390 * computation work out to the correct value. */
391 const Spectrum darkening = (one_spectrum() + Fms * missing_factor) / bsdf->energy_scale;
392 bsdf->weight *= darkening;
393 bsdf->sample_weight *= average(darkening);
394 }
395}
396
397/* This function estimates the albedo of the BSDF (NOT including the bsdf->weight) as caused by
398 * the applied Fresnel model for the given view direction.
399 * The base microfacet model is assumed to have an albedo of 1 (we have the energy preservation
400 * code for that), but e.g. a reflection-only closure with Fresnel applied can end up having
401 * a very low overall albedo.
402 * This is used to adjust the sample weight, as well as for the Diff/Gloss/Trans Color pass
403 * and the Denoising Albedo pass.
404 *
405 * TODO: The Schlick LUT seems to assume energy preservation, which is not true for GGX. if
406 * energy-preserving then transmission should just be `1 - reflection`. For dielectric we could
407 * probably split the LUT for multiGGX if smooth assumption is not good enough. */
409 const ccl_private ShaderData *sd,
410 const ccl_private MicrofacetBsdf *bsdf,
411 const bool eval_reflection,
412 const bool eval_transmission)
413{
414 const float cos_NI = dot(sd->wi, bsdf->N);
415 Spectrum reflectance;
416 Spectrum transmittance;
417 microfacet_fresnel(kg, bsdf, cos_NI, nullptr, &reflectance, &transmittance);
418
419 reflectance *= (float)eval_reflection;
420 transmittance *= (float)eval_transmission;
421
422 /* Use lookup tables for generalized Schlick reflection, otherwise assume smooth surface. */
423 if (is_zero(reflectance)) {
424 /* Reflectivity is either zero or not requested, so don't compute the more complex estimate. */
425 }
426 else if (bsdf->fresnel_type == MicrofacetFresnel::GENERALIZED_SCHLICK) {
428 bsdf->fresnel;
429
430 if (fresnel->thin_film.thickness > 0.1f) {
431 /* Precomputing LUTs for thin-film iridescence isn't viable, so fall back to the specular
432 * reflection approximation from the microfacet_fresnel call above in that case. */
433 }
434 else {
435 const float rough = sqrtf(sqrtf(bsdf->alpha_x * bsdf->alpha_y));
436 float s;
437 if (fresnel->exponent < 0.0f) {
438 const float z = sqrtf(fabsf((bsdf->ior - 1.0f) / (bsdf->ior + 1.0f)));
440 kg, rough, cos_NI, z, kernel_data.tables.ggx_gen_schlick_ior_s, 16, 16, 16);
441 }
442 else {
443 const float z = 1.0f / (0.2f * fresnel->exponent + 1.0f);
445 kg, rough, cos_NI, z, kernel_data.tables.ggx_gen_schlick_s, 16, 16, 16);
446 }
447 reflectance = mix(fresnel->f0, fresnel->f90, s) * fresnel->reflection_tint;
448 }
449 }
450 else if (bsdf->fresnel_type == MicrofacetFresnel::F82_TINT) {
451 ccl_private FresnelF82Tint *fresnel = (ccl_private FresnelF82Tint *)bsdf->fresnel;
452 const float rough = sqrtf(sqrtf(bsdf->alpha_x * bsdf->alpha_y));
453 const float s = lookup_table_read_3D(
454 kg, rough, cos_NI, 0.5f, kernel_data.tables.ggx_gen_schlick_s, 16, 16, 16);
455 /* TODO: Precompute B factor term and account for it here. */
456 reflectance = mix(fresnel->f0, one_spectrum(), s);
457 }
458 else if ((bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC ||
459 bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC_TINT) &&
460 bsdf->ior > 1.0f)
461 {
462 /* We can re-use the ggx_gen_schlick_ior_s table here, since it's already precomputed for our
463 * exponent<0 corner case where we use the real dielectric Fresnel. */
464 const float rough = sqrtf(sqrtf(bsdf->alpha_x * bsdf->alpha_y));
465 const float z = sqrtf(fabsf((bsdf->ior - 1.0f) / (bsdf->ior + 1.0f)));
466 const float s = lookup_table_read_3D(
467 kg, rough, cos_NI, z, kernel_data.tables.ggx_gen_schlick_ior_s, 16, 16, 16);
468 reflectance = make_spectrum(mix(F0_from_ior(bsdf->ior), 1.0f, s));
469 if (bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC_TINT) {
471 bsdf->fresnel;
472 reflectance *= fresnel->reflection_tint;
473 }
474 }
475
476 return reflectance + transmittance;
477}
478
479/* Smith shadowing-masking term, here in the non-separable form.
480 * For details, see:
481 * Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs.
482 * Eric Heitz, JCGT Vol. 3, No. 2, 2014.
483 * https://jcgt.org/published/0003/02/03/ */
484template<MicrofacetType m_type>
485ccl_device_inline float bsdf_lambda_from_sqr_alpha_tan_n(const float sqr_alpha_tan_n)
486{
488 /* Equation 72. */
489 return 0.5f * (sqrtf(1.0f + sqr_alpha_tan_n) - 1.0f);
490 }
492 /* Approximation from below Equation 69. */
493 if (sqr_alpha_tan_n < 0.39f) {
494 /* Equivalent to a >= 1.6f, but also handles sqr_alpha_tan_n == 0.0f cleanly. */
495 return 0.0f;
496 }
497
498 const float a = inversesqrtf(sqr_alpha_tan_n);
499 return ((0.396f * a - 1.259f) * a + 1.0f) / ((2.181f * a + 3.535f) * a);
500}
501
502template<MicrofacetType m_type>
503ccl_device_inline float bsdf_lambda(const float alpha2, const float cos_N)
504{
505 return bsdf_lambda_from_sqr_alpha_tan_n<m_type>(alpha2 * fmaxf(1.0f / sqr(cos_N) - 1.0f, 0.0f));
506}
507
508template<MicrofacetType m_type>
509ccl_device_inline float bsdf_aniso_lambda(const float alpha_x, const float alpha_y, const float3 V)
510{
511 const float sqr_alpha_tan_n = (sqr(alpha_x * V.x) + sqr(alpha_y * V.y)) / sqr(V.z);
512 return bsdf_lambda_from_sqr_alpha_tan_n<m_type>(sqr_alpha_tan_n);
513}
514
515/* Mono-directional shadowing-masking term. */
516template<MicrofacetType m_type>
517ccl_device_inline float bsdf_G(const float alpha2, const float cos_N)
518{
519 return 1.0f / (1.0f + bsdf_lambda<m_type>(alpha2, cos_N));
520}
521
522/* Combined shadowing-masking term. */
523template<MicrofacetType m_type>
524ccl_device_inline float bsdf_G(const float alpha2, const float cos_NI, const float cos_NO)
525{
526 return 1.0f / (1.0f + bsdf_lambda<m_type>(alpha2, cos_NI) + bsdf_lambda<m_type>(alpha2, cos_NO));
527}
528
529/* Normal distribution function. */
530template<MicrofacetType m_type>
531ccl_device_inline float bsdf_D(const float alpha2, const float cos_NH)
532{
533 const float cos_NH2 = min(sqr(cos_NH), 1.0f);
534 const float one_minus_cos_NH2 = 1.0f - cos_NH2;
535
537 return 1.0f / (expf(one_minus_cos_NH2 / (cos_NH2 * alpha2)) * M_PI_F * alpha2 * sqr(cos_NH2));
538 }
540 return alpha2 / (M_PI_F * sqr(one_minus_cos_NH2 + alpha2 * cos_NH2));
541}
542
543template<MicrofacetType m_type>
544ccl_device_inline float bsdf_aniso_D(const float alpha_x, const float alpha_y, float3 H)
545{
546 H /= make_float3(alpha_x, alpha_y, 1.0f);
547
548 const float cos_NH2 = sqr(H.z);
549 const float alpha2 = alpha_x * alpha_y;
550
552 return expf(-(sqr(H.x) + sqr(H.y)) / cos_NH2) / (M_PI_F * alpha2 * sqr(cos_NH2));
553 }
555 return M_1_PI_F / (alpha2 * sqr(len_squared(H)));
556}
557
558/* Do not set `SD_BSDF_HAS_EVAL` flag if the squared roughness is below a certain threshold. */
560{
561 return (bsdf->alpha_x * bsdf->alpha_y > BSDF_ROUGHNESS_SQ_THRESH) ? SD_BSDF_HAS_EVAL : 0;
562}
563
564template<MicrofacetType m_type>
566 const ccl_private ShaderClosure *sc,
567 const float3 Ng,
568 const float3 wi,
569 const float3 wo,
570 ccl_private float *pdf)
571{
572 const ccl_private MicrofacetBsdf *bsdf = (const ccl_private MicrofacetBsdf *)sc;
573
574 /* Whether the closure has reflective or transmissive lobes. */
575 const bool has_reflection = !CLOSURE_IS_REFRACTION(bsdf->type);
576 const bool has_transmission = CLOSURE_IS_GLASS(bsdf->type) || !has_reflection;
577
578 const float3 N = bsdf->N;
579 const float cos_NI = dot(N, wi);
580 const float cos_NO = dot(N, wo);
581 const float cos_NgO = dot(Ng, wo);
582
583 const float alpha_x = bsdf->alpha_x;
584 const float alpha_y = bsdf->alpha_y;
585
586 const bool is_transmission = (cos_NO < 0.0f);
587
588 /* Check whether the pair of directions is valid for evaluation:
589 * - Incoming direction has to be in the upper hemisphere (Cycles convention)
590 * - Specular cases can't be evaluated, only sampled.
591 * - The outgoing direction has to be the in the same hemisphere w.r.t. both normals.
592 * - Purely reflective closures can't have refraction.
593 * - Purely refractive closures can't have reflection.
594 */
595 if ((cos_NI <= 0) || !bsdf_microfacet_eval_flag(bsdf) || ((cos_NgO < 0.0f) != is_transmission) ||
596 (is_transmission && !has_transmission) || (!is_transmission && !has_reflection))
597 {
598 return zero_spectrum();
599 }
600
601 /* Compute half vector. */
602 /* TODO: deal with the case when `bsdf->ior` is close to one. */
603 /* TODO: check if the refraction configuration is valid. See `btdf_ggx()` in
604 * `eevee_bxdf_lib.glsl`. */
605 float3 H = is_transmission ? -(bsdf->ior * wo + wi) : (wi + wo);
606 const float inv_len_H = safe_divide(1.0f, len(H));
607 H *= inv_len_H;
608
609 /* Compute Fresnel coefficients. */
610 const float cos_HI = dot(H, wi);
611 Spectrum reflectance;
612 Spectrum transmittance;
613 microfacet_fresnel(kg, bsdf, cos_HI, nullptr, &reflectance, &transmittance);
614
615 if (is_zero(reflectance) && is_zero(transmittance)) {
616 return zero_spectrum();
617 }
618
619 const float cos_NH = dot(N, H);
620 float D;
621 float lambdaI;
622 float lambdaO;
623
624 /* NOTE: we could add support for anisotropic transmission, although it will make dispersion
625 * harder to compute. */
626 if (alpha_x == alpha_y || is_transmission) { /* Isotropic. */
627 const float alpha2 = alpha_x * alpha_y;
628 D = bsdf_D<m_type>(alpha2, cos_NH);
629 lambdaI = bsdf_lambda<m_type>(alpha2, cos_NI);
630 lambdaO = bsdf_lambda<m_type>(alpha2, cos_NO);
631 }
632 else { /* Anisotropic. */
633 float3 X;
634 float3 Y;
635 make_orthonormals_tangent(N, bsdf->T, &X, &Y);
636
637 const float3 local_H = make_float3(dot(X, H), dot(Y, H), cos_NH);
638 const float3 local_I = make_float3(dot(X, wi), dot(Y, wi), cos_NI);
639 const float3 local_O = make_float3(dot(X, wo), dot(Y, wo), cos_NO);
640
641 D = bsdf_aniso_D<m_type>(alpha_x, alpha_y, local_H);
642
643 lambdaI = bsdf_aniso_lambda<m_type>(alpha_x, alpha_y, local_I);
644 lambdaO = bsdf_aniso_lambda<m_type>(alpha_x, alpha_y, local_O);
645 }
646
647 const float common = D / cos_NI *
648 (is_transmission ? sqr(bsdf->ior * inv_len_H) * fabsf(cos_HI * dot(H, wo)) :
649 0.25f);
650
651 const float pdf_reflect = average(reflectance) / average(reflectance + transmittance);
652 const float lobe_pdf = is_transmission ? 1.0f - pdf_reflect : pdf_reflect;
653
654 *pdf = common * lobe_pdf / (1.0f + lambdaI);
655 return (is_transmission ? transmittance : reflectance) * common / (1.0f + lambdaO + lambdaI);
656}
657
658template<MicrofacetType m_type>
660 const ccl_private ShaderClosure *sc,
661 const float3 Ng,
662 const float3 wi,
663 const float3 rand,
664 ccl_private Spectrum *eval,
666 ccl_private float *pdf,
667 ccl_private float2 *sampled_roughness,
668 ccl_private float *eta)
669{
670 const ccl_private MicrofacetBsdf *bsdf = (const ccl_private MicrofacetBsdf *)sc;
671
672 const float3 N = bsdf->N;
673 const float cos_NI = dot(N, wi);
674 if (cos_NI <= 0) {
675 /* Incident angle from the lower hemisphere is invalid. */
676 return LABEL_NONE;
677 }
678
679 const float m_eta = bsdf->ior;
680 const float m_inv_eta = safe_divide(1.0f, bsdf->ior);
681 const float alpha_x = bsdf->alpha_x;
682 const float alpha_y = bsdf->alpha_y;
683 bool m_singular = !bsdf_microfacet_eval_flag(bsdf);
684
685 /* Half vector. */
686 float3 H;
687 /* Needed for anisotropic microfacets later. */
688 float3 local_H;
689 float3 local_I;
690 if (m_singular) {
691 H = N;
692 }
693 else {
694 float3 X;
695 float3 Y;
696 if (alpha_x == alpha_y) {
697 make_orthonormals(N, &X, &Y);
698 }
699 else {
700 make_orthonormals_tangent(N, bsdf->T, &X, &Y);
701 }
702
703 /* Importance sampling with distribution of visible normals. Vectors are transformed to local
704 * space before and after sampling. */
705 local_I = make_float3(dot(X, wi), dot(Y, wi), cos_NI);
707 local_H = microfacet_ggx_sample_vndf(local_I, alpha_x, alpha_y, make_float2(rand));
708 }
709 else {
710 /* m_type == MicrofacetType::BECKMANN */
711 local_H = microfacet_beckmann_sample_vndf(local_I, alpha_x, alpha_y, make_float2(rand));
712 }
713
714 H = to_global(local_H, X, Y, N);
715 }
716 const float cos_HI = dot(H, wi);
717
718 /* The angle between the half vector and the refracted ray. Not used when sampling reflection. */
719 float cos_HO;
720 /* Compute Fresnel coefficients. */
721 Spectrum reflectance;
722 Spectrum transmittance;
723 microfacet_fresnel(kg, bsdf, cos_HI, &cos_HO, &reflectance, &transmittance);
724
725 if (is_zero(reflectance) && is_zero(transmittance)) {
726 return LABEL_NONE;
727 }
728
729 /* Decide between refraction and reflection based on the energy. */
730 const float pdf_reflect = average(reflectance) / average(reflectance + transmittance);
731 const bool do_refract = (rand.z >= pdf_reflect);
732
733 /* Compute actual reflected or refracted direction. */
734 *wo = do_refract ? refract_angle(wi, H, cos_HO, m_inv_eta) : 2.0f * cos_HI * H - wi;
735 if ((dot(Ng, *wo) < 0) != do_refract) {
736 return LABEL_NONE;
737 }
738
739 if (do_refract) {
740 *eval = transmittance;
741 *pdf = 1.0f - pdf_reflect;
742 /* If the IOR is close enough to 1.0, just treat the interaction as specular. */
743 m_singular = m_singular || (fabsf(m_eta - 1.0f) < 1e-4f);
744 }
745 else {
746 *eval = reflectance;
747 *pdf = pdf_reflect;
748 }
749
750 if (m_singular) {
751 /* Some high number for MIS. */
752 *pdf *= 1e6f;
753 *eval *= 1e6f;
754 }
755 else {
756 float D;
757 float lambdaI;
758 float lambdaO;
759
760 /* TODO: add support for anisotropic transmission. */
761 if (alpha_x == alpha_y || do_refract) { /* Isotropic. */
762 const float alpha2 = alpha_x * alpha_y;
763 const float cos_NH = local_H.z;
764 const float cos_NO = dot(N, *wo);
765
766 D = bsdf_D<m_type>(alpha2, cos_NH);
767 lambdaO = bsdf_lambda<m_type>(alpha2, cos_NO);
768 lambdaI = bsdf_lambda<m_type>(alpha2, cos_NI);
769 }
770 else { /* Anisotropic. */
771 const float3 local_O = 2.0f * cos_HI * local_H - local_I;
772
773 D = bsdf_aniso_D<m_type>(alpha_x, alpha_y, local_H);
774
775 lambdaO = bsdf_aniso_lambda<m_type>(alpha_x, alpha_y, local_O);
776 lambdaI = bsdf_aniso_lambda<m_type>(alpha_x, alpha_y, local_I);
777 }
778
779 const float common = D / cos_NI *
780 (do_refract ? fabsf(cos_HI * cos_HO) / sqr(cos_HO + cos_HI * m_inv_eta) :
781 0.25f);
782
783 *pdf *= common / (1.0f + lambdaI);
784 *eval *= common / (1.0f + lambdaI + lambdaO);
785 }
786
787 *sampled_roughness = make_float2(alpha_x, alpha_y);
788 *eta = do_refract ? m_eta : 1.0f;
789
790 return (do_refract ? LABEL_TRANSMIT : LABEL_REFLECT) |
791 (m_singular ? LABEL_SINGULAR : LABEL_GLOSSY);
792}
793
794/* Fresnel term setup functions. These get called after the distribution-specific setup functions
795 * like bsdf_microfacet_ggx_setup. */
796
799 const ccl_private ShaderData *sd,
801 const bool preserve_energy)
802{
803 bsdf->fresnel_type = MicrofacetFresnel::CONDUCTOR;
804 bsdf->fresnel = fresnel;
805 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, sd, bsdf, true, true));
806
807 if (preserve_energy) {
808 microfacet_ggx_preserve_energy(kg, bsdf, sd, fresnel_conductor_Fss(fresnel->n, fresnel->k));
809 }
810}
811
813 KernelGlobals kg,
815 const ccl_private ShaderData *sd,
817 const bool preserve_energy)
818{
819 bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC_TINT;
820 bsdf->fresnel = fresnel;
821 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, sd, bsdf, true, true));
822
823 if (preserve_energy) {
824 /* Assume that the transmissive tint makes up most of the overall color. */
825 Spectrum Fss = fresnel->transmission_tint;
826 if (is_zero(fresnel->transmission_tint)) {
827 /* For purely reflective closures, use the reflection component. */
828 Fss = fresnel_dielectric_Fss(bsdf->ior) * fresnel->reflection_tint;
829 }
830 microfacet_ggx_preserve_energy(kg, bsdf, sd, Fss);
831 }
832}
833
835 KernelGlobals kg,
837 const ccl_private ShaderData *sd,
839 const bool preserve_energy)
840{
841 fresnel->f0 = saturate(fresnel->f0);
842 bsdf->fresnel_type = MicrofacetFresnel::GENERALIZED_SCHLICK;
843 bsdf->fresnel = fresnel;
844 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, sd, bsdf, true, true));
845
846 if (preserve_energy) {
847 Spectrum Fss = one_spectrum();
848 /* Multi-bounce Fresnel is only supported for reflective lobes here. */
849 if (is_zero(fresnel->transmission_tint)) {
850 float s;
851 if (fresnel->exponent < 0.0f) {
852 const float F0 = F0_from_ior(bsdf->ior);
853 const float Fss = fresnel_dielectric_Fss(bsdf->ior);
854 s = saturatef(inverse_lerp(F0, 1.0f, Fss));
855 }
856 else {
857 /* Integral of 2*cosI * (1 - cosI)^exponent over 0...1. */
858 s = 2.0f / ((fresnel->exponent + 3.0f) * fresnel->exponent + 2.0f);
859 }
860 /* Due to the linearity of the generalized model, this ends up working. */
861 Fss = fresnel->reflection_tint * mix(fresnel->f0, fresnel->f90, s);
862 }
863 else {
864 /* For transmissive BSDFs, assume that the transmissive tint makes up most of the overall
865 * color. */
866 Fss = fresnel->transmission_tint;
867 }
868
869 microfacet_ggx_preserve_energy(kg, bsdf, sd, Fss);
870 }
871}
872
875 const ccl_private ShaderData *sd,
877 const Spectrum f82_tint,
878 const bool preserve_energy)
879{
880 if (isequal(f82_tint, one_spectrum())) {
881 fresnel->b = zero_spectrum();
882 }
883 else {
884 fresnel->b = fresnel_f82tint_B(fresnel->f0, f82_tint);
885 }
886
887 bsdf->fresnel_type = MicrofacetFresnel::F82_TINT;
888 bsdf->fresnel = fresnel;
889 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, sd, bsdf, true, true));
890
891 if (preserve_energy) {
892 microfacet_ggx_preserve_energy(kg, bsdf, sd, fresnel_f82_Fss(fresnel->f0, fresnel->b));
893 }
894}
895
898 const ccl_private ShaderData *sd,
899 const Spectrum color)
900{
901 /* Constant Fresnel is a special case - the color is already baked into the closure's
902 * weight, so we just need to perform the energy preservation. */
903 kernel_assert(bsdf->fresnel_type == MicrofacetFresnel::NONE ||
904 bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC);
905
906 microfacet_ggx_preserve_energy(kg, bsdf, sd, color);
907}
908
911 const ccl_private ShaderData *sd)
912{
913 bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC;
914 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, sd, bsdf, true, true));
915
916 const float Fss = fresnel_dielectric_Fss(bsdf->ior);
918}
919
920/* GGX microfacet with Smith shadow-masking from:
921 *
922 * Microfacet Models for Refraction through Rough Surfaces
923 * B. Walter, S. R. Marschner, H. Li, K. E. Torrance, EGSR 2007
924 *
925 * Anisotropic from:
926 *
927 * Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs
928 * E. Heitz, Research Report 2014
929 *
930 * Anisotropy is only supported for reflection currently, but adding it for
931 * transmission is just a matter of copying code from reflection if needed. */
932
934{
935 bsdf->alpha_x = saturatef(bsdf->alpha_x);
936 bsdf->alpha_y = saturatef(bsdf->alpha_y);
937
938 bsdf->fresnel_type = MicrofacetFresnel::NONE;
939 bsdf->energy_scale = 1.0f;
941
942 return SD_BSDF | bsdf_microfacet_eval_flag(bsdf);
943}
944
946{
947 bsdf->alpha_x = saturatef(bsdf->alpha_x);
948 bsdf->alpha_y = bsdf->alpha_x;
949
950 bsdf->fresnel_type = MicrofacetFresnel::NONE;
951 bsdf->energy_scale = 1.0f;
953
955}
956
958{
959 bsdf->alpha_x = saturatef(bsdf->alpha_x);
960 bsdf->alpha_y = bsdf->alpha_x;
961
962 bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC;
963 bsdf->energy_scale = 1.0f;
965
967}
968
969ccl_device void bsdf_microfacet_blur(ccl_private ShaderClosure *sc, const float roughness)
970{
972
973 bsdf->alpha_x = fmaxf(roughness, bsdf->alpha_x);
974 bsdf->alpha_y = fmaxf(roughness, bsdf->alpha_y);
975}
976
978 const ccl_private ShaderClosure *sc,
979 const float3 Ng,
980 const float3 wi,
981 const float3 wo,
982 ccl_private float *pdf)
983{
984 const ccl_private MicrofacetBsdf *bsdf = (const ccl_private MicrofacetBsdf *)sc;
985 return bsdf->energy_scale * bsdf_microfacet_eval<MicrofacetType::GGX>(kg, sc, Ng, wi, wo, pdf);
986}
987
989 const ccl_private ShaderClosure *sc,
990 const float3 Ng,
991 const float3 wi,
992 const float3 rand,
993 ccl_private Spectrum *eval,
995 ccl_private float *pdf,
996 ccl_private float2 *sampled_roughness,
997 ccl_private float *eta)
998{
999
1001 kg, sc, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
1002 *eval *= ((const ccl_private MicrofacetBsdf *)sc)->energy_scale;
1003 return label;
1004}
1005
1006/* Beckmann microfacet with Smith shadow-masking from:
1007 *
1008 * Microfacet Models for Refraction through Rough Surfaces
1009 * B. Walter, S. R. Marschner, H. Li, K. E. Torrance, EGSR 2007 */
1010
1012{
1013 bsdf->alpha_x = saturatef(bsdf->alpha_x);
1014 bsdf->alpha_y = saturatef(bsdf->alpha_y);
1015
1016 bsdf->fresnel_type = MicrofacetFresnel::NONE;
1018
1019 return SD_BSDF | bsdf_microfacet_eval_flag(bsdf);
1020}
1021
1023{
1024 bsdf->alpha_x = saturatef(bsdf->alpha_x);
1025 bsdf->alpha_y = bsdf->alpha_x;
1026
1027 bsdf->fresnel_type = MicrofacetFresnel::NONE;
1029
1031}
1032
1034{
1035 bsdf->alpha_x = saturatef(bsdf->alpha_x);
1036 bsdf->alpha_y = bsdf->alpha_x;
1037
1038 bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC;
1040
1042}
1043
1045 const ccl_private ShaderClosure *sc,
1046 const float3 Ng,
1047 const float3 wi,
1048 const float3 wo,
1049 ccl_private float *pdf)
1050{
1051 return bsdf_microfacet_eval<MicrofacetType::BECKMANN>(kg, sc, Ng, wi, wo, pdf);
1052}
1053
1055 const ccl_private ShaderClosure *sc,
1056 const float3 Ng,
1057 const float3 wi,
1058 const float3 rand,
1059 ccl_private Spectrum *eval,
1060 ccl_private float3 *wo,
1061 ccl_private float *pdf,
1062 ccl_private float2 *sampled_roughness,
1063 ccl_private float *eta)
1064{
1066 kg, sc, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
1067}
1068
#define D
MINLINE float signf(float f)
MINLINE float safe_sqrtf(float a)
MINLINE float safe_divide(float a, float b)
#define K(key)
#define X
#define Y
iter begin(iter)
ccl_device_forceinline float3 microfacet_beckmann_sample_vndf(const float3 wi, const float alpha_x, const float alpha_y, const float2 rand)
ccl_device Spectrum bsdf_microfacet_ggx_eval(KernelGlobals kg, const ccl_private ShaderClosure *sc, const float3 Ng, const float3 wi, const float3 wo, ccl_private float *pdf)
ccl_device void bsdf_microfacet_setup_fresnel_f82_tint(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const ccl_private ShaderData *sd, ccl_private FresnelF82Tint *fresnel, const Spectrum f82_tint, const bool preserve_energy)
ccl_device Spectrum bsdf_microfacet_eval(KernelGlobals kg, const ccl_private ShaderClosure *sc, const float3 Ng, const float3 wi, const float3 wo, ccl_private float *pdf)
ccl_device_inline float bsdf_lambda_from_sqr_alpha_tan_n(const float sqr_alpha_tan_n)
ccl_device int bsdf_microfacet_sample(KernelGlobals kg, const ccl_private ShaderClosure *sc, const float3 Ng, const float3 wi, const float3 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf, ccl_private float2 *sampled_roughness, ccl_private float *eta)
ccl_device_forceinline float3 microfacet_ggx_sample_vndf(const float3 wi, const float alpha_x, const float alpha_y, const float2 rand)
ccl_device Spectrum bsdf_microfacet_estimate_albedo(KernelGlobals kg, const ccl_private ShaderData *sd, const ccl_private MicrofacetBsdf *bsdf, const bool eval_reflection, const bool eval_transmission)
ccl_device int bsdf_microfacet_beckmann_glass_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_beckmann_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device_forceinline int bsdf_microfacet_eval_flag(const ccl_private MicrofacetBsdf *bsdf)
ccl_device void bsdf_microfacet_setup_fresnel_constant(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const ccl_private ShaderData *sd, const Spectrum color)
ccl_device Spectrum bsdf_microfacet_beckmann_eval(KernelGlobals kg, const ccl_private ShaderClosure *sc, const float3 Ng, const float3 wi, const float3 wo, ccl_private float *pdf)
ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals kg, const ccl_private ShaderClosure *sc, const float3 Ng, const float3 wi, const float3 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf, ccl_private float2 *sampled_roughness, ccl_private float *eta)
MicrofacetType
@ GGX
@ BECKMANN
ccl_device void bsdf_microfacet_setup_fresnel_generalized_schlick(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const ccl_private ShaderData *sd, ccl_private FresnelGeneralizedSchlick *fresnel, const bool preserve_energy)
ccl_device_inline float bsdf_D(const float alpha2, const float cos_NH)
ccl_device_inline float bsdf_lambda(const float alpha2, const float cos_N)
ccl_device void bsdf_microfacet_setup_fresnel_dielectric(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const ccl_private ShaderData *sd)
ccl_device_inline float bsdf_G(const float alpha2, const float cos_N)
ccl_device void bsdf_microfacet_setup_fresnel_conductor(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const ccl_private ShaderData *sd, ccl_private FresnelConductor *fresnel, const bool preserve_energy)
ccl_device_inline void microfacet_ggx_preserve_energy(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const ccl_private ShaderData *sd, const Spectrum Fss)
ccl_device void bsdf_microfacet_setup_fresnel_dielectric_tint(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const ccl_private ShaderData *sd, ccl_private FresnelDielectricTint *fresnel, const bool preserve_energy)
ccl_device_inline float bsdf_aniso_D(const float alpha_x, const float alpha_y, float3 H)
ccl_device_inline float bsdf_aniso_lambda(const float alpha_x, const float alpha_y, const float3 V)
ccl_device int bsdf_microfacet_beckmann_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
MicrofacetFresnel
@ CONDUCTOR
@ DIELECTRIC_TINT
@ GENERALIZED_SCHLICK
@ DIELECTRIC
@ NONE
@ F82_TINT
ccl_device int bsdf_microfacet_ggx_glass_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals kg, const ccl_private ShaderClosure *sc, const float3 Ng, const float3 wi, const float3 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf, ccl_private float2 *sampled_roughness, ccl_private float *eta)
ccl_device int bsdf_microfacet_ggx_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device_forceinline void microfacet_fresnel(KernelGlobals kg, const ccl_private MicrofacetBsdf *bsdf, const float cos_theta_i, ccl_private float *r_cos_theta_t, ccl_private Spectrum *r_reflectance, ccl_private Spectrum *r_transmittance)
ccl_device void bsdf_microfacet_blur(ccl_private ShaderClosure *sc, const float roughness)
ccl_device int bsdf_microfacet_ggx_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device float F0_from_ior(const float ior)
Definition bsdf_util.h:172
ccl_device Spectrum fresnel_conductor(const float cosi, const Spectrum eta, const Spectrum k)
Definition bsdf_util.h:114
ccl_device Spectrum fresnel_iridescence(KernelGlobals kg, float eta1, float eta2, float eta3, float cos_theta_1, const float thickness, ccl_private float *r_cos_theta_3)
Definition bsdf_util.h:380
ccl_device_inline Spectrum fresnel_f82_Fss(const Spectrum F0, const Spectrum B)
Definition bsdf_util.h:127
ccl_device_inline Spectrum fresnel_conductor_Fss(const Spectrum eta, const Spectrum k)
Definition bsdf_util.h:157
ccl_device_inline float fresnel_dielectric_Fss(const float eta)
Definition bsdf_util.h:106
ccl_device_forceinline float fresnel_dielectric(const float cos_theta_i, const float eta, ccl_private float *r_cos_theta_t)
Definition bsdf_util.h:69
ccl_device_inline float3 refract_angle(const float3 incident, const float3 normal, const float cos_theta_t, const float inv_eta)
Definition bsdf_util.h:78
ccl_device_inline Spectrum fresnel_f82tint_B(const Spectrum F0, const Spectrum tint)
Definition bsdf_util.h:133
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
ccl_device_inline float3 disk_to_hemisphere(const float2 p)
ccl_device_inline T to_global(const float2 p, const T X, const T Y)
ccl_device_inline float2 polar_to_cartesian(const float r, const float phi)
#define kernel_assert(cond)
#define CLOSURE_IS_GLASS(type)
#define kernel_data
#define ccl_device_forceinline
#define one_spectrum
#define ccl_device
#define zero_spectrum
#define M_2PI_F
#define make_spectrum(f)
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_inline
#define M_1_PI_F
#define FOREACH_SPECTRUM_CHANNEL(counter)
#define CLOSURE_IS_REFRACTION(type)
#define M_PI_F
#define GET_SPECTRUM_CHANNEL(v, i)
#define BSDF_ROUGHNESS_SQ_THRESH
#define logf(x)
#define expf(x)
#define powf(x, y)
#define CCL_NAMESPACE_END
#define saturatef(x)
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define fmaxf(x, y)
ccl_device_forceinline float2 make_float2(const float x, const float y)
#define fabsf(x)
#define sqrtf(x)
#define common
VecBase< float, D > normalize(VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
#define mix(a, b, c)
Definition hash.h:35
@ CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID
@ CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID
@ CLOSURE_BSDF_MICROFACET_GGX_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_ID
@ SD_BSDF_HAS_EVAL
@ SD_BSDF
@ SD_BSDF_HAS_TRANSMISSION
@ LABEL_TRANSMIT
@ LABEL_NONE
@ LABEL_SINGULAR
@ LABEL_GLOSSY
@ LABEL_REFLECT
ccl_device float lookup_table_read_2D(KernelGlobals kg, const float x, float y, const int offset, const int xsize, const int ysize)
ccl_device float lookup_table_read_3D(KernelGlobals kg, const float x, float y, float z, const int offset, const int xsize, const int ysize, const int zsize)
CCL_NAMESPACE_BEGIN ccl_device float lookup_table_read(KernelGlobals kg, float x, const int offset, const int size)
ccl_device_inline float sqr(const float a)
Definition math_base.h:600
ccl_device_inline float inversesqrtf(const float f)
Definition math_base.h:529
ccl_device_inline float sin_from_cos(const float c)
Definition math_base.h:605
ccl_device_inline float inverse_lerp(const float a, const float b, const float x)
Definition math_base.h:507
ccl_device_inline float fast_erff(const float x)
Definition math_fast.h:563
ccl_device_inline float fast_ierff(const float x)
Definition math_fast.h:598
ccl_device_inline float len_squared(const float2 a)
ccl_device_inline bool is_zero(const float2 a)
ccl_device_inline float average(const float2 a)
ccl_device_inline bool isequal(const float2 a, const float2 b)
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)
#define N
#define F
#define T2
Definition md5.cpp:20
#define T1
Definition md5.cpp:19
#define H(x, y, z)
CCL_NAMESPACE_BEGIN ccl_device float2 sample_uniform_disk(const float2 rand)
ccl_device void make_orthonormals_tangent(const float3 N, const float3 T, ccl_private float3 *a, ccl_private float3 *b)
#define saturate(a)
Definition smaa.cc:315
#define min(a, b)
Definition sort.cc:36
FresnelThinFilm thin_film
ccl_private void * fresnel
float x
float y
float z
Definition sky_float3.h:27
float y
Definition sky_float3.h:27
float x
Definition sky_float3.h:27
i
Definition text_draw.cc:230
max
Definition text_draw.cc:251
float3 Spectrum
uint len
CCL_NAMESPACE_BEGIN struct Window V