Blender V5.3
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
12#include "kernel/constants.h"
15
16#include "util/math_fast.h"
17
19
24
26 NONE = 0,
28 DIELECTRIC_TINT, /* used by the OSL MaterialX closures */
32};
33
37
38 FresnelCoeff() = default;
39
44
45 ccl_device_inline_method FresnelCoeff(bool reflective, bool refractive)
46 : reflectance(reflective ? one_spectrum() : zero_spectrum()),
47 transmittance(refractive ? one_spectrum() : zero_spectrum())
48 {
49 }
50
52 {
53 return {this->reflectance * other.reflectance, this->transmittance * other.transmittance};
54 }
55
56 template<class T> ccl_device_inline_method FresnelCoeff operator*(const T reflectance_) const
57 {
58 return {this->reflectance * reflectance_, this->transmittance * (1.0f - reflectance_)};
59 }
60
61 template<class T> ccl_device_inline_method FresnelCoeff operator*=(const T other)
62 {
63 return *this = *this * other;
64 }
65
70};
71
73{
74 return is_zero(coeff.reflectance) && is_zero(coeff.transmittance);
75}
76
81
86
89
91 /* Reflectivity at perpendicular (F0) and glancing (F90) angles. */
93 /* Negative exponent signals a special case where the real Fresnel is remapped to F0...F90. */
94 float exponent;
95};
96
99
100 /* Perpendicular reflectivity. */
102 /* Precomputed (1-cos)^6 factor for edge tint. */
104};
105
108
110
111 /* Used to account for missing energy due to the single-scattering microfacet model.
112 * This could be included in bsdf->weight as well, but there it would mess up the color
113 * channels.
114 * Note that this is currently only used by GGX. */
116
117 /* Fresnel model to apply, as well as the extra data for it.
118 * For NONE and DIELECTRIC, no extra storage is needed, so the pointer is nullptr for them. */
121
123};
124
125static_assert(sizeof(ShaderClosure) >= sizeof(MicrofacetBsdf), "MicrofacetBsdf is too large!");
126
127struct Coat {
129 float ior;
131 float roughness;
133};
134
135/* -------------------------------------------------------------------- */
141
142ccl_device_forceinline float alpha_to_roughness_index(const float alpha_x, const float alpha_y)
143{
144 return sqrtf(sqrtf(alpha_x * alpha_y));
145}
146
148{
149 return sqrtf(fabsf((ior - 1.0f) / (ior + 1.0f)));
150}
151
153{
154 return safe_sqrtf(mu);
155}
156
158
160 const float inv_bulk_ior)
161{
162 /* The IOR configuration at the backface is
163 *
164 * bulk_ior
165 * ------------
166 * film_ior
167 * ------------
168 * 1
169 *
170 * this is equivalent to
171 *
172 * 1
173 * ------------
174 * film_ior / bulk_ior
175 * ------------
176 * 1 / bulk_ior
177 *
178 * Therefore, we divide `film_ior` by `bulk_ior` to have the correct configuration. */
179
180 film_ior *= inv_bulk_ior;
181}
182
185 const bool reflective_caustics,
186 const bool refractive_caustics,
187 const Spectrum reflection_tint,
189 FresnelThinFilm thinfilm)
190{
191 FresnelCoeff tint(reflective_caustics, refractive_caustics);
193 return {/* .thin_film = */ thinfilm,
194 /* .tint = */ tint,
195 /* .f0 = */ F0_from_ior(ior) * reflection_tint,
196 /* .f90 = */ one_spectrum(),
197 /* .exponent = */ -ior};
198}
199
200/* Beckmann VNDF importance sampling algorithm from:
201 * Importance Sampling Microfacet-Based BSDFs using the Distribution of Visible Normals.
202 * Eric Heitz and Eugene d'Eon, EGSR 2014.
203 * https://hal.inria.fr/hal-00996995v2/document */
204
206 const float alpha_x,
207 const float alpha_y,
208 const float2 rand)
209{
210 /* 1. stretch wi */
211 float3 wi_ = make_float3(alpha_x * wi.x, alpha_y * wi.y, wi.z);
212 wi_ = normalize(wi_);
213
214 /* 2. sample P22_{wi}(x_slope, y_slope, 1, 1) */
215 float2 slope;
216 float cos_phi_i = 1.0f;
217 float sin_phi_i = 0.0f;
218
219 if (wi_.z >= 0.99999f) {
220 /* Special case (normal incidence). */
221 const float r = sqrtf(-logf(rand.x));
222 const float phi = M_2PI_F * rand.y;
223 slope = polar_to_cartesian(r, phi);
224 }
225 else {
226 /* Precomputations. */
227 const float cos_theta_i = wi_.z;
228 const float sin_theta_i = sin_from_cos(cos_theta_i);
229 const float tan_theta_i = sin_theta_i / cos_theta_i;
230 const float cot_theta_i = 1.0f / tan_theta_i;
231 const float erf_a = fast_erff(cot_theta_i);
232 const float exp_a2 = expf(-cot_theta_i * cot_theta_i);
233 const float SQRT_PI_INV = 0.56418958354f;
234
235 const float invlen = 1.0f / sin_theta_i;
236 cos_phi_i = wi_.x * invlen;
237 sin_phi_i = wi_.y * invlen;
238
239 /* Based on paper from Wenzel Jakob
240 * An Improved Visible Normal Sampling Routine for the Beckmann Distribution
241 *
242 * http://www.mitsuba-renderer.org/~wenzel/files/visnormal.pdf
243 *
244 * Reformulation from OpenShadingLanguage which avoids using inverse
245 * trigonometric functions.
246 */
247
248 /* Sample slope X.
249 *
250 * Compute a coarse approximation using the approximation:
251 * `exp(-ierf(x)^2) ~= 1 - x * x`
252 * `solve y = 1 + b + K * (1 - b * b)`
253 */
254 const float K = tan_theta_i * SQRT_PI_INV;
255 const float y_approx = rand.x * (1.0f + erf_a + K * (1 - erf_a * erf_a));
256 const float y_exact = rand.x * (1.0f + erf_a + K * exp_a2);
257 const float b = K > 0 ? (0.5f - sqrtf(K * (K - y_approx + 1.0f) + 0.25f)) / K :
258 y_approx - 1.0f;
259
260 float inv_erf = fast_ierff(b);
261 float2 begin = make_float2(-1.0f, -y_exact);
262 float2 end = make_float2(erf_a, 1.0f + erf_a + K * exp_a2 - y_exact);
263 float2 current = make_float2(b, 1.0f + b + K * expf(-sqr(inv_erf)) - y_exact);
264
265 /* Find root in a monotonic interval using newton method, under given precision and maximal
266 * iterations. Falls back to bisection if newton step produces results outside of the valid
267 * interval. */
268 const float precision = 1e-6f;
269 const int max_iter = 3;
270 int iter = 0;
271 while (fabsf(current.y) > precision && iter++ < max_iter) {
272 if (signf(begin.y) == signf(current.y)) {
273 begin.x = current.x;
274 begin.y = current.y;
275 }
276 else {
277 end.x = current.x;
278 }
279 const float newton_x = current.x - current.y / (1.0f - inv_erf * tan_theta_i);
280 current.x = (newton_x >= begin.x && newton_x <= end.x) ? newton_x : 0.5f * (begin.x + end.x);
281 inv_erf = fast_ierff(current.x);
282 current.y = 1.0f + current.x + K * expf(-sqr(inv_erf)) - y_exact;
283 }
284
285 slope.x = inv_erf;
286 slope.y = fast_ierff(2.0f * rand.y - 1.0f);
287 }
288
289 /* 3. rotate */
290 slope = make_float2(cos_phi_i * slope.x - sin_phi_i * slope.y,
291 sin_phi_i * slope.x + cos_phi_i * slope.y);
292
293 /* 4. unstretch */
294 slope *= make_float2(alpha_x, alpha_y);
295
296 /* 5. compute normal */
297 return normalize(make_float3(-slope.x, -slope.y, 1.0f));
298}
299
300/* GGX VNDF importance sampling algorithm from:
301 * Sampling the GGX Distribution of Visible Normals.
302 * Eric Heitz, JCGT Vol. 7, No. 4, 2018.
303 * https://jcgt.org/published/0007/04/01/ */
305 const float alpha_x,
306 const float alpha_y,
307 const float2 rand)
308{
309 /* Section 3.2: Transforming the view direction to the hemisphere configuration. */
310 const float3 wi_ = normalize(make_float3(alpha_x * wi.x, alpha_y * wi.y, wi.z));
311
312 /* Section 4.1: Orthonormal basis. */
313 const float lensq = sqr(wi_.x) + sqr(wi_.y);
314 float3 T1;
315 float3 T2;
316 if (lensq > 1e-7f) {
317 T1 = make_float3(-wi_.y, wi_.x, 0.0f) * inversesqrtf(lensq);
318 T2 = cross(wi_, T1);
319 }
320 else {
321 /* Normal incidence, any basis is fine. */
322 T1 = make_float3(1.0f, 0.0f, 0.0f);
323 T2 = make_float3(0.0f, 1.0f, 0.0f);
324 }
325
326 /* Section 4.2: Parameterization of the projected area. */
327 float2 t = sample_uniform_disk(rand);
328 t.y = mix(safe_sqrtf(1.0f - sqr(t.x)), t.y, 0.5f * (1.0f + wi_.z));
329
330 /* Section 4.3: Reprojection onto hemisphere. */
331 const float3 H_ = to_global(disk_to_hemisphere(t), T1, T2, wi_);
332
333 /* Section 3.4: Transforming the normal back to the ellipsoid configuration. */
334 return normalize(make_float3(alpha_x * H_.x, alpha_y * H_.y, max(0.0f, H_.z)));
335}
336
337/* Calculate ior of potentially dispersive materials, using Cauchy empirical formula. Input ior is
338 * the ior at the Fraunhofer d spectral line, after applying backface flipping. */
339ccl_device_inline float bsdf_glass_ior(ccl_private ShaderData *sd, float ior, const float inv_abbe)
340{
341#ifdef __SPECTRAL__
342 if (!(sd->shader_flag & SD_REQUIRES_WAVELENGTH) || (inv_abbe == 0.0f)) {
343 return ior;
344 }
345
346 const bool backfacing = sd->runtime_flag & SR_BACKFACING;
347
348 sd->runtime_flag |= SR_BSDF_HAS_DISPERSION;
349 ior = backfacing ? 1.0f / ior : ior;
350
351 /* Wavelengths of the Fraunhofer spectral lines in um. */
352 constexpr float lambda_d = 0.5876f;
353 constexpr float lambda_C = 0.6563f;
354 constexpr float lambda_F = 0.4861f;
355
356 constexpr float fac = 1.0f / (1.0f / (lambda_F * lambda_F) - 1.0f / (lambda_C * lambda_C));
357 constexpr float inv_lambda_d_sq = 1.0f / (lambda_d * lambda_d);
358
359 /* OpenPBR Surface specification v1.1.1, Eq. (56). */
360 const float B = (ior - 1.0f) * inv_abbe * fac;
361 const float A = ior - B * inv_lambda_d_sq;
362
363 const float wavelength = sample_wavelength(sd->rand_wavelength);
364
365 /* OpenPBR Surface specification v1.1.1, Eq. (55). */
366 ior = A + B / sqr(wavelength);
367 return backfacing ? 1.0f / ior : ior;
368#else
369 (void)sd;
370 (void)inv_abbe;
371 return ior;
372#endif
373}
374
375/* Computes Fresnel reflectance and transmittance of the Generalized Schlick Model. */
379 const float ior,
380 const float cos_theta_i,
381 ccl_private float *r_cos_theta_t)
382{
383 Spectrum F;
384 if (fresnel->thin_film.thickness > THINFILM_THICKNESS_CUTOFF) {
385 /* Iridescence doesn't combine well with the general case. We only expose it through the
386 * Principled BSDF for now, so it's fine to not support custom exponents and F90. */
387 kernel_assert(fresnel->exponent < 0.0f);
388 kernel_assert(fresnel->f90 == one_spectrum());
389 /* One channel at a time to reduce GPU register pressure. */
392 kg, i, 1.0f, fresnel->thin_film, ior, 0.0f, -1.0f, cos_theta_i, r_cos_theta_t);
393 }
394 /* Apply F0 scaling (here per-channel, since iridescence produces colored output).
395 * Note that the usual approach (as used below) cannot be used here, since F may be below
396 * F0_real. Therefore, use a different approach: Scale the result by (F0 / F0_real), with the
397 * strength of the scaling depending on how close F is to F0_real.
398 * There isn't one single "correct" way to do this, it's just for artistic control anyways.
399 */
400 const float F0_real = F0_from_ior(ior);
401 if (F0_real > 1e-5f && !isequal(F, one_spectrum())) {
403 const float s = saturatef(inverse_lerp(1.0f, F0_real, GET_SPECTRUM_CHANNEL(F, i)));
404 const float factor = GET_SPECTRUM_CHANNEL(fresnel->f0, i) / F0_real;
405 GET_SPECTRUM_CHANNEL(F, i) *= mix(1.0f, factor, s);
406 }
407 }
408 }
409 else if (fresnel->exponent < 0.0f) {
410 /* Special case: Use real Fresnel curve to determine the interpolation between F0 and F90.
411 * Used by Principled BSDF. */
412 const float F_real = fresnel_dielectric(cos_theta_i, ior, r_cos_theta_t);
413 const float F0_real = F0_from_ior(ior);
414 const float s = saturatef(inverse_lerp(F0_real, 1.0f, F_real));
415 F = mix(fresnel->f0, fresnel->f90, s);
416 }
417 else {
418 /* Regular case: Generalized Schlick term. */
419 const float cos_theta_t_sq = 1.0f - (1.0f - sqr(cos_theta_i)) / sqr(ior);
420 if (cos_theta_t_sq <= 0.0f) {
421 /* Total internal reflection */
422 return {fresnel->tint.reflectance, zero_spectrum()};
423 }
424 const float cos_theta_t = sqrtf(cos_theta_t_sq);
425 if (r_cos_theta_t) {
426 *r_cos_theta_t = cos_theta_t;
427 }
428
429 /* TODO(lukas): Is a special case for exponent==5 worth it? */
430 /* When going from a higher to a lower IOR, we must use the transmitted angle. */
431 const float fresnel_angle = (ior < 1.0f) ? cos_theta_t : cos_theta_i;
432 const float s = powf(1.0f - fresnel_angle, fresnel->exponent);
433 F = mix(fresnel->f0, fresnel->f90, s);
434 }
435 return fresnel->tint * F;
436}
437
438/* Computes the Fresnel reflectance and transmittance given the Microfacet BSDF and the cosine of
439 * the incoming angle `cos_theta_i`.
440 * Also returns the cosine of the angle between the normal and the refracted ray as `r_cos_theta_t`
441 * if provided. */
443 const ccl_private MicrofacetBsdf *bsdf,
444 const float cos_theta_i,
445 ccl_private float *r_cos_theta_t)
446{
447 /* Whether the closure has reflective or transmissive lobes. */
448 const bool has_reflection = !CLOSURE_IS_REFRACTION(bsdf->type);
449 const bool has_transmission = CLOSURE_IS_GLASS(bsdf->type) || !has_reflection;
450
451 FresnelCoeff coeff(has_reflection, has_transmission);
452
453 if (bsdf->fresnel_type == MicrofacetFresnel::CONDUCTOR) {
454 if (!has_reflection) {
455 return {zero_spectrum(), zero_spectrum()};
456 }
457 ccl_private FresnelConductor *fresnel = (ccl_private FresnelConductor *)bsdf->fresnel;
458 if (fresnel->thin_film.thickness > THINFILM_THICKNESS_CUTOFF) {
459 /* One channel at a time to reduce GPU register pressure. */
462 kg,
463 i,
464 1.0f,
465 fresnel->thin_film,
466 GET_SPECTRUM_CHANNEL(fresnel->ior.re, i),
467 GET_SPECTRUM_CHANNEL(fresnel->ior.im, i),
468 -1.0f,
469 cos_theta_i,
470 r_cos_theta_t);
471 }
472 }
473 else {
474 coeff.reflectance = fresnel_conductor(cos_theta_i, fresnel->ior);
475 }
476 }
477 else if (bsdf->fresnel_type == MicrofacetFresnel::F82_TINT) {
478 if (!has_reflection) {
479 return {zero_spectrum(), zero_spectrum()};
480 }
481 /* F82-Tint model, described in "Novel aspects of the Adobe Standard Material" by Kutz et al.
482 * Essentially, this is the usual Schlick Fresnel with an additional cosI*(1-cosI)^6
483 * term which modulates the reflectivity around acos(1/7) degrees (ca. 82°). */
484 ccl_private FresnelF82Tint *fresnel = (ccl_private FresnelF82Tint *)bsdf->fresnel;
485
486 if (fresnel->thin_film.thickness > THINFILM_THICKNESS_CUTOFF) {
487 /* Estimate n and k by reinterpreting F0 and F82 as r and g from "Artist Friendly Metallic
488 * Fresnel" by Ole Gulbrandsen.
489 * One channel at a time to reduce GPU register pressure. */
491 const float f0 = GET_SPECTRUM_CHANNEL(fresnel->f0, i);
492 const float r = min(f0, 0.999f);
493 const float g = fresnel_f82(1.0f / 7.0f, f0, GET_SPECTRUM_CHANNEL(fresnel->b, i));
494
495 const float sqrt_r = sqrtf(r);
496 const float n = mix((1.0f + sqrt_r) / (1.0f - sqrt_r), (1.0f - r) / (1.0f + r), g);
497 const float k = safe_sqrtf((r * sqr(n + 1.0f) - sqr(n - 1.0f)) / (1.0f - r));
498
500 kg, i, 1.0f, fresnel->thin_film, n, k, g, cos_theta_i, r_cos_theta_t);
501 }
502 }
503 else {
504 coeff.reflectance = fresnel_f82(cos_theta_i, fresnel->f0, fresnel->b);
505 }
506 }
507 else if (bsdf->fresnel_type == MicrofacetFresnel::GENERALIZED_SCHLICK) {
509 bsdf->fresnel;
510 coeff *= generalized_schlick_fresnel(kg, fresnel, bsdf->ior, cos_theta_i, r_cos_theta_t);
511 }
512 else if (bsdf->fresnel_type == MicrofacetFresnel::NONE) {
513 /* No Fresnel used, this is either purely reflective or purely refractive closure. */
514 /* Exclude total internal reflection. */
515 if (has_transmission && fresnel_dielectric(cos_theta_i, bsdf->ior, r_cos_theta_t) == 1.0f) {
517 }
518 }
519 else if (bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC_TINT) {
520 Spectrum F;
522 bsdf->fresnel;
523 if (fresnel->thin_film.thickness > THINFILM_THICKNESS_CUTOFF) {
526 kg, i, 1.0f, fresnel->thin_film, bsdf->ior, 0.0f, -1.0f, cos_theta_i, r_cos_theta_t);
527 }
528 }
529 else {
530 F = make_spectrum(fresnel_dielectric(cos_theta_i, bsdf->ior, r_cos_theta_t));
531 }
532 coeff *= F;
533 coeff *= ((ccl_private FresnelDielectricTint *)bsdf->fresnel)->tint;
534 }
535 else {
536 /* Transmissive dielectric. */
537 coeff *= fresnel_dielectric(cos_theta_i, bsdf->ior, r_cos_theta_t);
538 kernel_assert(bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC);
539 }
540
541 return coeff;
542}
543
546 const float3 wi,
547 const Spectrum Fss)
548{
549 const float mu = dot(wi, bsdf->N);
550 const float y = mu_to_y_index(mu);
551 const float rough = alpha_to_roughness_index(bsdf->alpha_x, bsdf->alpha_y);
552
553 float E;
554 float E_avg;
555 if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_ID ||
557 {
559 kg, rough, y, kernel_data.tables.ggx_E, GGX_E_RES_ROUGH, GGX_E_RES_MU);
560 E_avg = lookup_table_read(kg, rough, kernel_data.tables.ggx_Eavg, GGX_E_RES_ROUGH);
561 }
562 else if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID) {
563 int ofs = kernel_data.tables.ggx_glass_E;
564 int avg_ofs = kernel_data.tables.ggx_glass_Eavg;
565 float ior = bsdf->ior;
566 if (ior < 1.0f) {
567 ior = 1.0f / ior;
568 ofs = kernel_data.tables.ggx_glass_inv_E;
569 avg_ofs = kernel_data.tables.ggx_glass_inv_Eavg;
570 }
571 const float z = ior_to_z_index(ior);
574 E_avg = lookup_table_read_2D(
575 kg, rough, z, avg_ofs, GGX_GLASS_E_RES_ROUGH, GGX_GLASS_E_RES_IOR);
576 }
577 else {
578 kernel_assert(false);
579 E = 1.0f;
580 E_avg = 1.0f;
581 }
582
583 const float missing_factor = ((1.0f - E) / E);
584 bsdf->energy_scale = 1.0f + missing_factor;
585
586 /* Check if we need to account for extra darkening/saturation due to multi-bounce Fresnel. */
587 if (!isequal(Fss, one_spectrum())) {
588 /* Fms here is based on the appendix of "Revisiting Physically Based Shading at Imageworks"
589 * by Christopher Kulla and Alejandro Conty,
590 * with one Fss cancelled out since this is just a multiplier on top of
591 * the single-scattering BSDF, which already contains one bounce of Fresnel. */
592 const Spectrum Fms = Fss * E_avg / (one_spectrum() - Fss * (1.0f - E_avg));
593 /* Since we already include the energy compensation in bsdf->energy_scale,
594 * this term is what's needed to make the full BSDF * weight * energy_scale
595 * computation work out to the correct value. */
596 const Spectrum darkening = (one_spectrum() + Fms * missing_factor) / bsdf->energy_scale;
597 bsdf->weight *= darkening;
598 bsdf->sample_weight *= average(darkening);
599 }
600}
601
602/* This function estimates the albedo of the BSDF (NOT including the bsdf->weight) as caused by
603 * the applied Fresnel model for the given view direction.
604 * The base microfacet model is assumed to have an albedo of 1 (we have the energy preservation
605 * code for that), but e.g. a reflection-only closure with Fresnel applied can end up having
606 * a very low overall albedo.
607 * This is used to adjust the sample weight, as well as for the Diff/Gloss/Trans Color pass
608 * and the Denoising Albedo pass.
609 *
610 * TODO: The Schlick LUT seems to assume energy preservation, which is not true for GGX. if
611 * energy-preserving then transmission should just be `1 - reflection`. For dielectric we could
612 * probably split the LUT for multiGGX if smooth assumption is not good enough. */
614 const float3 wi,
615 const ccl_private MicrofacetBsdf *bsdf,
616 const bool eval_reflection,
617 const bool eval_transmission)
618{
619 const float cos_NI = dot(wi, bsdf->N);
620 FresnelCoeff coeff(eval_reflection, eval_transmission);
621
622 /* Use lookup tables for generalized Schlick reflection, otherwise assume smooth surface.
623 * Note that even if the reflectance or transmittance would evaluate to zero for
624 * #microfacet_fresnel, we still compute it because this contributes to albedo passes. */
625 if (bsdf->fresnel_type == MicrofacetFresnel::GENERALIZED_SCHLICK) {
627 bsdf->fresnel;
628
629 if (fresnel->thin_film.thickness > THINFILM_THICKNESS_CUTOFF) {
630 /* Precomputing LUTs for thin-film iridescence isn't viable, so fall back to the specular
631 * reflection approximation from the microfacet_fresnel call above in that case. */
632 }
633 else {
634 const float rough = alpha_to_roughness_index(bsdf->alpha_x, bsdf->alpha_y);
635 float s;
636 if (fresnel->exponent < 0.0f) {
637 const float z = ior_to_z_index(bsdf->ior);
638 const float y = mu_to_y_index(cos_NI);
640 rough,
641 y,
642 z,
643 kernel_data.tables.ggx_gen_schlick_ior_s,
647 }
648 else {
649 const float z = 1.0f / (0.2f * fresnel->exponent + 1.0f);
650 const float y = mu_to_y_index(cos_NI);
652 rough,
653 y,
654 z,
655 kernel_data.tables.ggx_gen_schlick_s,
659 }
660 coeff *= fresnel->tint * mix(fresnel->f0, fresnel->f90, s);
661 return coeff.sum();
662 }
663 }
664 else if (bsdf->fresnel_type == MicrofacetFresnel::F82_TINT) {
665 ccl_private FresnelF82Tint *fresnel = (ccl_private FresnelF82Tint *)bsdf->fresnel;
666
667 if (fresnel->thin_film.thickness > THINFILM_THICKNESS_CUTOFF) {
668 /* Precomputing LUTs for thin-film iridescence isn't viable, so fall back to the specular
669 * reflection approximation from the microfacet_fresnel call above in that case. */
670 }
671 else {
672 const float rough = alpha_to_roughness_index(bsdf->alpha_x, bsdf->alpha_y);
673 const float y = mu_to_y_index(cos_NI);
674 const float s = lookup_table_read_3D(kg,
675 rough,
676 y,
677 0.5f,
678 kernel_data.tables.ggx_gen_schlick_s,
682 /* TODO: Precompute B factor term and account for it here. */
683 const Spectrum reflectance = mix(fresnel->f0, one_spectrum(), s) * float(eval_reflection);
684 return reflectance;
685 }
686 }
687 if (bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC_TINT &&
688 ((ccl_private FresnelDielectricTint *)bsdf->fresnel)->thin_film.thickness >
690 {
691 /* Precomputing LUTs for thin-film iridescence isn't viable, so fall back to the specular
692 * reflection approximation from the microfacet_fresnel call above in that case. */
693 }
694 else if ((bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC ||
695 bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC_TINT) &&
696 bsdf->ior > 1.0f)
697 {
698 /* We can re-use the ggx_gen_schlick_ior_s table here, since it's already precomputed for our
699 * exponent<0 corner case where we use the real dielectric Fresnel. */
700 const float rough = alpha_to_roughness_index(bsdf->alpha_x, bsdf->alpha_y);
701 const float z = ior_to_z_index(bsdf->ior);
702 const float y = mu_to_y_index(cos_NI);
703 const float s = lookup_table_read_3D(kg,
704 rough,
705 y,
706 z,
707 kernel_data.tables.ggx_gen_schlick_ior_s,
711
712#if defined(__KERNEL_HIP__)
713 /* Temporary workaround for a HIP compiler bug under Windows in combination with AMD 6800 XT
714 * GPUs */
715 const float F = mix(F0_from_ior(bsdf->ior), 1.0f, s);
716 coeff.reflectance = make_spectrum(F) * float(eval_reflection);
717 coeff.transmittance = make_spectrum(1.0f - F) * float(eval_transmission);
718#else
719 coeff *= mix(F0_from_ior(bsdf->ior), 1.0f, s);
720#endif
721
722 /* Tinted dielectric. */
723 if (bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC_TINT) {
724 coeff *= ((ccl_private FresnelDielectricTint *)bsdf->fresnel)->tint;
725 return coeff.sum();
726 }
727
728 /* Untinted dielectric. */
729 if (CLOSURE_IS_GLASS(bsdf->type)) {
730 return coeff.sum();
731 }
732 return coeff.reflectance;
733 }
734 else if (bsdf->type == CLOSURE_BSDF_THIN_GLASS_TRANSMISSION_ID) {
735 return eval_transmission ? one_spectrum() : zero_spectrum();
736 }
737
738 /* Simpler case without the lookup tables. */
739 coeff *= microfacet_fresnel(kg, bsdf, cos_NI, nullptr);
740
741 return coeff.sum();
742}
743
744/* Smith shadowing-masking term, here in the non-separable form.
745 * For details, see:
746 * Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs.
747 * Eric Heitz, JCGT Vol. 3, No. 2, 2014.
748 * https://jcgt.org/published/0003/02/03/ */
749template<MicrofacetType m_type>
750ccl_device_inline float bsdf_lambda_from_sqr_alpha_tan_n(const float sqr_alpha_tan_n)
751{
753 /* Equation 72. */
754 return 0.5f * (sqrtf(1.0f + sqr_alpha_tan_n) - 1.0f);
755 }
757 /* Approximation from below Equation 69. */
758 if (sqr_alpha_tan_n < 0.39f) {
759 /* Equivalent to a >= 1.6f, but also handles sqr_alpha_tan_n == 0.0f cleanly. */
760 return 0.0f;
761 }
762
763 const float a = inversesqrtf(sqr_alpha_tan_n);
764 return ((0.396f * a - 1.259f) * a + 1.0f) / ((2.181f * a + 3.535f) * a);
765}
766
767template<MicrofacetType m_type>
768ccl_device_inline float bsdf_lambda(const float alpha2, const float cos_N)
769{
770 return bsdf_lambda_from_sqr_alpha_tan_n<m_type>(alpha2 * fmaxf(1.0f / sqr(cos_N) - 1.0f, 0.0f));
771}
772
773template<MicrofacetType m_type>
774ccl_device_inline float bsdf_aniso_lambda(const float alpha_x, const float alpha_y, const float3 V)
775{
776 const float sqr_alpha_tan_n = (sqr(alpha_x * V.x) + sqr(alpha_y * V.y)) / sqr(V.z);
777 return bsdf_lambda_from_sqr_alpha_tan_n<m_type>(sqr_alpha_tan_n);
778}
779
780/* Mono-directional shadowing-masking term. */
781template<MicrofacetType m_type>
782ccl_device_inline float bsdf_G(const float alpha2, const float cos_N)
783{
784 return 1.0f / (1.0f + bsdf_lambda<m_type>(alpha2, cos_N));
785}
786
787/* Combined shadowing-masking term. */
788template<MicrofacetType m_type>
789ccl_device_inline float bsdf_G(const float alpha2, const float cos_NI, const float cos_NO)
790{
791 return 1.0f / (1.0f + bsdf_lambda<m_type>(alpha2, cos_NI) + bsdf_lambda<m_type>(alpha2, cos_NO));
792}
793
794/* Normal distribution function. */
795template<MicrofacetType m_type>
796ccl_device_inline float bsdf_D(const float alpha2, const float cos_NH)
797{
798 const float cos_NH2 = min(sqr(cos_NH), 1.0f);
799 const float one_minus_cos_NH2 = 1.0f - cos_NH2;
800
802 return 1.0f / (expf(one_minus_cos_NH2 / (cos_NH2 * alpha2)) * M_PI_F * alpha2 * sqr(cos_NH2));
803 }
805 return alpha2 / (M_PI_F * sqr(one_minus_cos_NH2 + alpha2 * cos_NH2));
806}
807
808template<MicrofacetType m_type>
809ccl_device_inline float bsdf_aniso_D(const float alpha_x, const float alpha_y, float3 H)
810{
811 H /= make_float3(alpha_x, alpha_y, 1.0f);
812
813 const float cos_NH2 = sqr(H.z);
814 const float alpha2 = alpha_x * alpha_y;
815
817 return expf(-(sqr(H.x) + sqr(H.y)) / cos_NH2) / (M_PI_F * alpha2 * sqr(cos_NH2));
818 }
820 return M_1_PI_F / (alpha2 * sqr(len_squared(H)));
821}
822
823/* Below certain roughness threshold we can treat closures as perfectly specular. */
824ccl_device_forceinline bool alpha_is_almost_specular(const float alpha_x, const float alpha_y)
825{
826 return (alpha_x * alpha_y) <= 2e-10f;
827}
828
829/* A specular BSDF has no eval. */
831{
832 return alpha_is_almost_specular(bsdf->alpha_x, bsdf->alpha_y) ? 0 : SR_BSDF_HAS_EVAL;
833}
834
835template<MicrofacetType m_type>
837 const ccl_private ShaderClosure *sc,
838 const float3 wi,
839 const float3 wo,
840 ccl_private float *pdf)
841{
842 const ccl_private MicrofacetBsdf *bsdf = (const ccl_private MicrofacetBsdf *)sc;
843
844 /* Whether the closure has reflective or transmissive lobes. */
845 const bool has_reflection = !CLOSURE_IS_REFRACTION(bsdf->type);
846 const bool has_transmission = CLOSURE_IS_GLASS(bsdf->type) || !has_reflection;
847
848 const float3 N = bsdf->N;
849 const float cos_NI = dot(N, wi);
850 const float cos_NO = dot(N, wo);
851
852 const float alpha_x = bsdf->alpha_x;
853 const float alpha_y = bsdf->alpha_y;
854
855 const bool is_transmission = (cos_NO < 0.0f);
856
857 /* Check whether the pair of directions is valid for evaluation:
858 * - Incoming direction has to be in the upper hemisphere (Cycles convention)
859 * - Specular cases can't be evaluated, only sampled.
860 * - Purely reflective closures can't have refraction.
861 * - Purely refractive closures can't have reflection.
862 */
863 if ((cos_NI <= 0) || !bsdf_microfacet_eval_flag(bsdf) ||
864 (is_transmission && !has_transmission) || (!is_transmission && !has_reflection))
865 {
866 return zero_spectrum();
867 }
868
869 /* Compute half vector. */
870 /* TODO: deal with the case when `bsdf->ior` is close to one. */
871 /* TODO: check if the refraction configuration is valid. See `btdf_ggx()` in
872 * `eevee_bxdf_lib.glsl`. */
873 float3 H = is_transmission ? -(bsdf->ior * wo + wi) : (wi + wo);
874 const float inv_len_H = safe_divide(1.0f, len(H));
875 H *= inv_len_H;
876
877 /* Compute Fresnel coefficients. */
878 const float cos_HI = dot(H, wi);
879 const FresnelCoeff coeff = microfacet_fresnel(kg, bsdf, cos_HI, nullptr);
880
881 if (iszero(coeff)) {
882 return zero_spectrum();
883 }
884
885 const float cos_NH = dot(N, H);
886 float D;
887 float lambdaI;
888 float lambdaO;
889
890 if (alpha_x == alpha_y) {
891 /* Isotropic. */
892 const float alpha2 = alpha_x * alpha_y;
893 D = bsdf_D<m_type>(alpha2, cos_NH);
894 lambdaI = bsdf_lambda<m_type>(alpha2, cos_NI);
895 lambdaO = bsdf_lambda<m_type>(alpha2, cos_NO);
896 }
897 else {
898 /* Anisotropic. */
899 float3 X;
900 float3 Y;
901 make_orthonormals_tangent(N, bsdf->T, &X, &Y);
902
903 const float3 local_H = make_float3(dot(X, H), dot(Y, H), cos_NH);
904 const float3 local_I = make_float3(dot(X, wi), dot(Y, wi), cos_NI);
905 const float3 local_O = make_float3(dot(X, wo), dot(Y, wo), cos_NO);
906
907 D = bsdf_aniso_D<m_type>(alpha_x, alpha_y, local_H);
908
909 lambdaI = bsdf_aniso_lambda<m_type>(alpha_x, alpha_y, local_I);
910 lambdaO = bsdf_aniso_lambda<m_type>(alpha_x, alpha_y, local_O);
911 }
912
913 const float common = D / cos_NI *
914 (is_transmission ? sqr(bsdf->ior * inv_len_H) * fabsf(cos_HI * dot(H, wo)) :
915 0.25f);
916
917 const float pdf_reflect = average(coeff.reflectance) / average(coeff.sum());
918 const float lobe_pdf = is_transmission ? 1.0f - pdf_reflect : pdf_reflect;
919
920 *pdf = common * lobe_pdf / (1.0f + lambdaI);
921 return (is_transmission ? coeff.transmittance : coeff.reflectance) * common /
922 (1.0f + lambdaO + lambdaI);
923}
924
925template<MicrofacetType m_type>
927 const ccl_private ShaderClosure *sc,
928 const float3 Ng,
929 const float3 wi,
930 const float3 rand,
931 ccl_private Spectrum *eval,
933 ccl_private float *pdf,
934 ccl_private float2 *sampled_roughness,
935 ccl_private float *eta)
936{
937 const ccl_private MicrofacetBsdf *bsdf = (const ccl_private MicrofacetBsdf *)sc;
938
939 const float3 N = bsdf->N;
940 const float cos_NI = dot(N, wi);
941 if (cos_NI <= 0) {
942 /* Incident angle from the lower hemisphere is invalid. */
943 return LABEL_NONE;
944 }
945
946 const float m_eta = bsdf->ior;
947 const float m_inv_eta = safe_divide(1.0f, bsdf->ior);
948 const float alpha_x = bsdf->alpha_x;
949 const float alpha_y = bsdf->alpha_y;
950 bool m_singular = alpha_is_almost_specular(alpha_x, alpha_y);
951
952 /* Half vector. */
953 float3 H;
954 /* Needed for anisotropic microfacets later. */
955 float3 local_H, local_I, X, Y;
956 if (m_singular) {
957 H = N;
958 }
959 else {
960 if (alpha_x == alpha_y) {
961 make_orthonormals(N, &X, &Y);
962 }
963 else {
964 make_orthonormals_tangent(N, bsdf->T, &X, &Y);
965 }
966
967 /* Importance sampling with distribution of visible normals. Vectors are transformed to local
968 * space before and after sampling. */
969 local_I = make_float3(dot(X, wi), dot(Y, wi), cos_NI);
971 local_H = microfacet_ggx_sample_vndf(local_I, alpha_x, alpha_y, make_float2(rand));
972 }
973 else {
974 /* m_type == MicrofacetType::BECKMANN */
975 local_H = microfacet_beckmann_sample_vndf(local_I, alpha_x, alpha_y, make_float2(rand));
976 }
977
978 H = to_global(local_H, X, Y, N);
979 }
980 const float cos_HI = dot(H, wi);
981
982 /* The angle between the half vector and the refracted ray. Not used when sampling reflection. */
983 float cos_HO;
984 /* Compute Fresnel coefficients. */
985 const FresnelCoeff coeff = microfacet_fresnel(kg, bsdf, cos_HI, &cos_HO);
986
987 if (iszero(coeff)) {
988 return LABEL_NONE;
989 }
990
991 /* Decide between refraction and reflection based on the energy. */
992 const float pdf_reflect = average(coeff.reflectance) / average(coeff.sum());
993 const bool do_refract = (rand.z >= pdf_reflect);
994
995 /* Compute actual reflected or refracted direction. */
996 *wo = do_refract ? refract_angle(wi, H, cos_HO, m_inv_eta) : 2.0f * cos_HI * H - wi;
997
998 /* Ensure that the sampled direction lies in the correct hemisphere.
999 * Note that the check against Ng is only performed in the sampling code, not the evaluation.
1000 * This is technically inconsistent, but required in order to avoid shadow terminator artifacts
1001 * on smooth geometry (which we'd get if we checked Ng in evaluation) while ensuring that
1002 * sampling doesn't return supposed reflection rays going into the geometry and vice versa.
1003 * The same is done for other closures as well. */
1004 const float cos_NO = dot(N, *wo);
1005 const float cos_NgO = dot(Ng, *wo);
1006 if ((cos_NgO < 0) != do_refract || (cos_NO < 0) != do_refract) {
1007 return LABEL_NONE;
1008 }
1009
1010 if (do_refract) {
1011 *eval = coeff.transmittance;
1012 *pdf = 1.0f - pdf_reflect;
1013 /* If the IOR is close enough to 1.0, just treat the interaction as specular. */
1014 m_singular = m_singular || (fabsf(m_eta - 1.0f) < 1e-4f);
1015 }
1016 else {
1017 *eval = coeff.reflectance;
1018 *pdf = pdf_reflect;
1019 }
1020
1021 if (m_singular) {
1022 /* Some high number for MIS. */
1023 *pdf *= 1e6f;
1024 *eval *= 1e6f;
1025 }
1026 else {
1027 float D;
1028 float lambdaI;
1029 float lambdaO;
1030
1031 if (alpha_x == alpha_y) {
1032 /* Isotropic. */
1033 const float alpha2 = alpha_x * alpha_y;
1034 const float cos_NH = local_H.z;
1035 const float cos_NO = dot(N, *wo);
1036
1037 D = bsdf_D<m_type>(alpha2, cos_NH);
1038 lambdaO = bsdf_lambda<m_type>(alpha2, cos_NO);
1039 lambdaI = bsdf_lambda<m_type>(alpha2, cos_NI);
1040 }
1041 else {
1042 /* Anisotropic. */
1043 const float3 local_O = make_float3(dot(X, *wo), dot(Y, *wo), cos_NO);
1044
1045 D = bsdf_aniso_D<m_type>(alpha_x, alpha_y, local_H);
1046
1047 lambdaO = bsdf_aniso_lambda<m_type>(alpha_x, alpha_y, local_O);
1048 lambdaI = bsdf_aniso_lambda<m_type>(alpha_x, alpha_y, local_I);
1049 }
1050
1051 const float common = D / cos_NI *
1052 (do_refract ? fabsf(cos_HI * cos_HO) / sqr(cos_HO + cos_HI * m_inv_eta) :
1053 0.25f);
1054
1055 *pdf *= common / (1.0f + lambdaI);
1056 *eval *= common / (1.0f + lambdaI + lambdaO);
1057 }
1058
1059 *sampled_roughness = make_float2(alpha_x, alpha_y);
1060 *eta = do_refract ? m_eta : 1.0f;
1061
1062 return (do_refract ? LABEL_TRANSMIT : LABEL_REFLECT) |
1063 (m_singular ? LABEL_SINGULAR : LABEL_GLOSSY);
1064}
1065
1066/* Fresnel term setup functions. These get called after the distribution-specific setup functions
1067 * like bsdf_microfacet_ggx_setup. */
1068
1071 const float3 wi,
1073 const bool preserve_energy)
1074{
1075 bsdf->fresnel_type = MicrofacetFresnel::CONDUCTOR;
1076 bsdf->fresnel = fresnel;
1077 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, wi, bsdf, true, true));
1078
1079 if (preserve_energy) {
1080 microfacet_ggx_preserve_energy(kg, bsdf, wi, fresnel_conductor_Fss(fresnel->ior));
1081 }
1082}
1083
1085 KernelGlobals kg,
1087 const float3 wi,
1089 const bool preserve_energy)
1090{
1091 fresnel->f0 = saturate(fresnel->f0);
1092 bsdf->fresnel_type = MicrofacetFresnel::GENERALIZED_SCHLICK;
1093 bsdf->fresnel = fresnel;
1094 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, wi, bsdf, true, true));
1095
1096 if (preserve_energy) {
1097 Spectrum Fss = one_spectrum();
1098 /* Multi-bounce Fresnel is only supported for reflective lobes here. */
1099 if (is_zero(fresnel->tint.transmittance)) {
1100 float s;
1101 if (fresnel->exponent < 0.0f) {
1102 const float F0 = F0_from_ior(bsdf->ior);
1103 const float Fss = fresnel_dielectric_Fss(bsdf->ior);
1104 s = saturatef(inverse_lerp(F0, 1.0f, Fss));
1105 }
1106 else {
1107 /* Integral of 2*cosI * (1 - cosI)^exponent over 0...1. */
1108 s = 2.0f / ((fresnel->exponent + 3.0f) * fresnel->exponent + 2.0f);
1109 }
1110 /* Due to the linearity of the generalized model, this ends up working. */
1111 Fss = fresnel->tint.reflectance * mix(fresnel->f0, fresnel->f90, s);
1112 }
1113 else {
1114 /* For transmissive BSDFs, assume that the transmissive tint makes up most of the overall
1115 * color. */
1116 Fss = fresnel->tint.transmittance;
1117 }
1118
1119 microfacet_ggx_preserve_energy(kg, bsdf, wi, Fss);
1120 }
1121}
1122
1125 const float3 wi,
1126 ccl_private FresnelF82Tint *fresnel,
1127 const Spectrum f82_tint,
1128 const bool preserve_energy)
1129{
1130 if (isequal(f82_tint, one_spectrum())) {
1131 fresnel->b = zero_spectrum();
1132 }
1133 else {
1134 fresnel->b = fresnel_f82tint_B(fresnel->f0, f82_tint);
1135 }
1136
1137 bsdf->fresnel_type = MicrofacetFresnel::F82_TINT;
1138 bsdf->fresnel = fresnel;
1139 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, wi, bsdf, true, true));
1140
1141 if (preserve_energy) {
1142 microfacet_ggx_preserve_energy(kg, bsdf, wi, fresnel_f82_Fss(fresnel->f0, fresnel->b));
1143 }
1144}
1145
1148 const float3 wi,
1149 const Spectrum color)
1150{
1151 /* Constant Fresnel is a special case - the color is already baked into the closure's
1152 * weight, so we just need to perform the energy preservation. */
1153 kernel_assert(bsdf->fresnel_type == MicrofacetFresnel::NONE ||
1154 bsdf->fresnel_type == MicrofacetFresnel::DIELECTRIC);
1155
1156 microfacet_ggx_preserve_energy(kg, bsdf, wi, color);
1157}
1158
1161 const float3 wi)
1162{
1163 bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC;
1164 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, wi, bsdf, true, true));
1165
1166 const float Fss = fresnel_dielectric_Fss(bsdf->ior);
1168}
1169
1170/* GGX microfacet with Smith shadow-masking from:
1171 *
1172 * Microfacet Models for Refraction through Rough Surfaces
1173 * B. Walter, S. R. Marschner, H. Li, K. E. Torrance, EGSR 2007
1174 *
1175 * Anisotropic from:
1176 *
1177 * Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs
1178 * E. Heitz, Research Report 2014
1179 */
1180
1182{
1183 bsdf->alpha_x = saturatef(bsdf->alpha_x);
1184 bsdf->alpha_y = saturatef(bsdf->alpha_y);
1185
1186 bsdf->fresnel_type = MicrofacetFresnel::NONE;
1187 bsdf->energy_scale = 1.0f;
1188 bsdf->type = CLOSURE_BSDF_MICROFACET_GGX_ID;
1189
1190 return SR_BSDF | bsdf_microfacet_eval_flag(bsdf);
1191}
1192
1194{
1195 bsdf->alpha_x = saturatef(bsdf->alpha_x);
1196 bsdf->alpha_y = saturatef(bsdf->alpha_y);
1197
1198 bsdf->fresnel_type = MicrofacetFresnel::NONE;
1199 bsdf->energy_scale = 1.0f;
1201
1203}
1204
1206{
1207 bsdf->alpha_x = saturatef(bsdf->alpha_x);
1208 bsdf->alpha_y = saturatef(bsdf->alpha_y);
1209
1210 bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC;
1211 bsdf->energy_scale = 1.0f;
1213
1215}
1216
1217ccl_device void bsdf_microfacet_blur(ccl_private ShaderClosure *sc, const float roughness)
1218{
1220
1221 bsdf->alpha_x = fmaxf(roughness, bsdf->alpha_x);
1222 bsdf->alpha_y = fmaxf(roughness, bsdf->alpha_y);
1223}
1224
1226 const ccl_private ShaderClosure *sc,
1227 const float3 wi,
1228 const float3 wo,
1229 ccl_private float *pdf)
1230{
1231 const ccl_private MicrofacetBsdf *bsdf = (const ccl_private MicrofacetBsdf *)sc;
1232 return bsdf->energy_scale * bsdf_microfacet_eval<MicrofacetType::GGX>(kg, sc, wi, wo, pdf);
1233}
1234
1236 const ccl_private ShaderClosure *sc,
1237 const float3 Ng,
1238 const float3 wi,
1239 const float3 rand,
1240 ccl_private Spectrum *eval,
1241 ccl_private float3 *wo,
1242 ccl_private float *pdf,
1243 ccl_private float2 *sampled_roughness,
1244 ccl_private float *eta)
1245{
1247 kg, sc, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
1248 *eval *= ((const ccl_private MicrofacetBsdf *)sc)->energy_scale;
1249 return label;
1250}
1251
1252/* Beckmann microfacet with Smith shadow-masking from:
1253 *
1254 * Microfacet Models for Refraction through Rough Surfaces
1255 * B. Walter, S. R. Marschner, H. Li, K. E. Torrance, EGSR 2007 */
1256
1258{
1259 bsdf->alpha_x = saturatef(bsdf->alpha_x);
1260 bsdf->alpha_y = saturatef(bsdf->alpha_y);
1261
1262 bsdf->fresnel_type = MicrofacetFresnel::NONE;
1264
1265 return SR_BSDF | bsdf_microfacet_eval_flag(bsdf);
1266}
1267
1269{
1270 bsdf->alpha_x = saturatef(bsdf->alpha_x);
1271 bsdf->alpha_y = saturatef(bsdf->alpha_y);
1272
1273 bsdf->fresnel_type = MicrofacetFresnel::NONE;
1275
1277}
1278
1280{
1281 bsdf->alpha_x = saturatef(bsdf->alpha_x);
1282 bsdf->alpha_y = saturatef(bsdf->alpha_y);
1283
1284 bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC;
1286
1288}
1289
1291 const ccl_private ShaderClosure *sc,
1292 const float3 wi,
1293 const float3 wo,
1294 ccl_private float *pdf)
1295{
1296 return bsdf_microfacet_eval<MicrofacetType::BECKMANN>(kg, sc, wi, wo, pdf);
1297}
1298
1300 const ccl_private ShaderClosure *sc,
1301 const float3 Ng,
1302 const float3 wi,
1303 const float3 rand,
1304 ccl_private Spectrum *eval,
1305 ccl_private float3 *wo,
1306 ccl_private float *pdf,
1307 ccl_private float2 *sampled_roughness,
1308 ccl_private float *eta)
1309{
1311 kg, sc, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
1312}
1313
1316 ccl_private ShaderData *sd,
1318 const bool is_beckmann = false,
1319 const bool preserve_energy = true)
1320{
1321 const bool has_reflection = !is_zero(fresnel->tint.reflectance);
1322 const bool has_transmission = !is_zero(fresnel->tint.transmittance);
1323
1324 if (has_reflection && has_transmission) {
1325 sd->runtime_flag |= is_beckmann ? bsdf_microfacet_beckmann_glass_setup(bsdf) :
1327 }
1328 else if (has_transmission) {
1329 sd->runtime_flag |= is_beckmann ? bsdf_microfacet_beckmann_refraction_setup(bsdf) :
1331 }
1332 else {
1333 sd->runtime_flag |= is_beckmann ? bsdf_microfacet_beckmann_setup(bsdf) :
1335 }
1336
1337 bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC_TINT;
1338 bsdf->fresnel = fresnel;
1339 bsdf->sample_weight *= average(bsdf_microfacet_estimate_albedo(kg, sd->wi, bsdf, true, true));
1340
1341 if (!preserve_energy) {
1342 return;
1343 }
1344
1345 Spectrum Fss;
1346 if (has_transmission) {
1347 /* Assume that the transmissive tint makes up most of the overall color. */
1348 Fss = fresnel->tint.transmittance;
1349 }
1350 else {
1351 /* For purely reflective closures, use the reflection component. */
1352 Fss = fresnel_dielectric_Fss(bsdf->ior) * fresnel->tint.reflectance;
1353 }
1354
1355 microfacet_ggx_preserve_energy(kg, bsdf, sd->wi, Fss);
1356}
1357
1358/* ------------------------------------------------------------------------------------------ */
1372
1374 const bool reflective,
1375 const bool refractive,
1376 const FresnelCoeff tint,
1377 FresnelThinFilm thinfilm,
1378 const float ior,
1379 const float cos_theta_i)
1380{
1381 /* Fresnel coefficients at the front side. */
1382 float cos_theta_t;
1384 ior, reflective, refractive, tint.reflectance, one_spectrum(), thinfilm);
1386 kg, &fresnel, ior, cos_theta_i, &cos_theta_t);
1387 if (iszero(front)) {
1388 return front;
1389 }
1390
1391 /* transmission_tint gives the transmittance through the thin glass at normal incidence due to
1392 * absorption. Compute the transmittance at oblique angle according to Beer-Lambert law. */
1393 const Spectrum color = is_zero(cos_theta_t) ? zero_spectrum() :
1394 power(tint.transmittance, -1.0f / cos_theta_t);
1395
1396 /* Fresnel coefficients at the back side. */
1397 FresnelCoeff back;
1398 if (thinfilm.thickness > THINFILM_THICKNESS_CUTOFF) {
1399 const float inv_ior = 1.0f / ior;
1400 adjust_thin_film_ior_at_backface(thinfilm.ior, inv_ior);
1402 ior, reflective, refractive, tint.reflectance, one_spectrum(), thinfilm);
1403 back = generalized_schlick_fresnel(kg, &fresnel2, inv_ior, -cos_theta_t, &cos_theta_t);
1404 }
1405 else {
1406 back = front;
1407 }
1408
1409 /* Account for internal reflections, t' = ct1t2 + ct1(r2c)^2t2 + ct1(r2c)^4t2 + ... */
1410 const Spectrum transmittance = safe_divide(color * front.transmittance * back.transmittance,
1411 1.0f - sqr(back.reflectance * color));
1412 /* r' = r1 + ct1r2ct2 + ct1(r2c)^3t2 + ... */
1413 const Spectrum reflectance = front.reflectance + transmittance * back.reflectance * color;
1414
1415 return {reflectance, transmittance};
1416}
1417
1419 ccl_private ShaderData *sd,
1420 const Spectrum color,
1421 const Spectrum weight,
1422 const float3 N,
1423 const float alpha)
1424{
1426 sd, sizeof(MicrofacetBsdf), weight);
1427 if (bsdf) {
1428 bsdf->N = N;
1429 bsdf->T = zero_float3();
1430 bsdf->alpha_x = bsdf->alpha_y = alpha;
1431 bsdf->ior = 1.0f;
1432 sd->runtime_flag |= bsdf_microfacet_ggx_setup(bsdf);
1433 bsdf_microfacet_setup_fresnel_constant(kg, bsdf, sd->wi, color);
1434 }
1435}
1436
1437/* Roughen the transmission lobe since it undergoes two refraction events.
1438 * From "Revisiting Physically Based Shading at Imageworks" by Christopher Kulla and Alejandro
1439 * Conty, Page 40.
1440 * NOTE:
1441 * 1. the number 3.7 in the slides is a typo, it should be 1.7 * 2, which is 3.4.
1442 * 2. `sqrt()` is removed because the original mapping applies on roughness, but we apply on alpha.
1443 */
1444ccl_device_inline float bsdf_thin_glass_transmission_alpha(const float alpha, const float eta)
1445{
1446 return saturatef(alpha * 3.4f * (eta - 1.0f) * sqr(eta - 0.5f) / (sqr(eta) * eta));
1447}
1448
1450 ccl_private ShaderData *sd,
1451 const Spectrum weight,
1452 const float3 N,
1453 const float alpha,
1454 const float ior,
1455 const PathRayVisibility ray_visibility,
1456 const uint32_t path_flag)
1457{
1458 const float transmission_alpha = bsdf_thin_glass_transmission_alpha(alpha, ior);
1459 if (!(ray_visibility & PATH_RAY_VISIBILITY_CAMERA) &&
1460 alpha_is_almost_specular(transmission_alpha, transmission_alpha))
1461 {
1462 /* Smooth thin glass does not bend the ray and is effectively transparent, allocate transparent
1463 * closures for non-camera rays to improve sampling and keep render passes intact. */
1464 bsdf_transparent_setup(sd, weight, path_flag);
1465 return;
1466 }
1467
1468 /* Model double refraction events as one reflection event with the incident ray mirrored along
1469 * the surface. */
1471 sd, sizeof(MicrofacetBsdf), weight);
1472 if (bsdf) {
1473 bsdf->N = -N;
1474 bsdf->T = zero_float3();
1475 bsdf->alpha_x = bsdf->alpha_y = transmission_alpha;
1476 bsdf->ior = 1.0f;
1477 bsdf->fresnel_type = MicrofacetFresnel::NONE;
1478 bsdf->energy_scale = 1.0f;
1480 sd->runtime_flag |= (SR_BSDF | SR_BSDF_HAS_TRANSMISSION | bsdf_microfacet_eval_flag(bsdf));
1482 }
1483}
1484
1486 const ccl_private ShaderClosure *sc,
1487 const float3 wi,
1488 const float3 wo,
1489 ccl_private float *pdf)
1490{
1491 return bsdf_microfacet_ggx_eval(kg, sc, reflect(wi, sc->N), wo, pdf);
1492}
1493
1495 const ccl_private ShaderClosure *sc,
1496 const float3 Ng,
1497 const float3 wi,
1498 const float3 rand,
1499 ccl_private Spectrum *eval,
1500 ccl_private float3 *wo,
1501 ccl_private float *pdf,
1502 ccl_private float2 *sampled_roughness,
1503 ccl_private float *eta)
1504{
1505 const ccl_private MicrofacetBsdf *bsdf = (const ccl_private MicrofacetBsdf *)sc;
1506 if (alpha_is_almost_specular(bsdf->alpha_x, bsdf->alpha_y)) {
1507 /* Effectively transparent. */
1508 *wo = -wi;
1509
1510 /* Some high number for MIS. */
1511 /* TODO(weizhen): the magic number 1e6f is used in various places, either change it to a define
1512 * or extract a function. */
1513 *pdf = 1e6f;
1514 *eval = one_spectrum() * 1e6f;
1515
1516 *sampled_roughness = zero_float2();
1517 *eta = 1.0f;
1519 }
1520
1521 const int label = bsdf_microfacet_ggx_sample(
1522 kg, sc, -Ng, reflect(wi, sc->N), rand, eval, wo, pdf, sampled_roughness, eta);
1523 if (label == LABEL_NONE) {
1524 return LABEL_NONE;
1525 }
1527}
1528
1530 ccl_private ShaderData *sd,
1531 const bool reflective,
1532 const bool refractive,
1533 const FresnelCoeff tint,
1534 const Spectrum weight,
1535 const float3 N,
1536 const float alpha,
1537 const float ior,
1538 const FresnelThinFilm thinfilm,
1539 const PathRayVisibility ray_visibility,
1540 const uint32_t path_flag)
1541{
1542 const float cos_theta_i = dot(N, sd->wi);
1543 const FresnelCoeff fresnel = bsdf_thin_glass_fresnel(
1544 kg, reflective, refractive, tint, thinfilm, ior, cos_theta_i);
1545
1547 kg, sd, tint.reflectance, fresnel.reflectance * weight, N, alpha);
1549 kg, sd, fresnel.transmittance * weight, N, alpha, ior, ray_visibility, path_flag);
1550
1551 return fresnel;
1552}
1553
1555
1556/* Given the transmittance through a slab at normal incidence, compute the transmittance at a
1557 * certain incident angle, based on Beer-Lambert law. */
1559 const float cos_theta_i,
1560 const float ior)
1561{
1562 const float optical_depth = ior * inversesqrtf(sqr(ior) - (1.0f - sqr(cos_theta_i)));
1563 return power(color, optical_depth);
1564}
1565
1566/* Set up coat BSDF, and return the coat albedo for layering. */
1568 ccl_private ShaderData *sd,
1569 const PathRayVisibility ray_visibility,
1570 ccl_private Coat &coat)
1571
1572{
1573#ifdef __CAUSTICS_TRICKS__
1574 const bool reflective_caustics = (kernel_data.integrator.caustics_reflective ||
1575 (ray_visibility & PATH_RAY_VISIBILITY_DIFFUSE) == 0);
1576#else
1577 const bool reflective_caustics = true;
1578#endif
1579
1580 coat.N = maybe_ensure_valid_specular_reflection(sd, coat.N);
1581
1582 if (!isequal(coat.tint, one_spectrum())) {
1583 /* Compute the color at viewing angle, based on the given tint at normal incidence.
1584 * OpenPBR Surface Specification v1.1.1, Section 3.4.2.
1585 * NOTE(OpenPBR): Eq. (77) requires the cosines of both the incoming and the outgoing
1586 * directions, but we only have access to the incoming direction. We therefore assume that the
1587 * refracted cosine of both directions are the same. The same approximation is done in Adobe's
1588 * implementation. */
1589 const float cosNI = dot(sd->wi, coat.N);
1590 coat.tint = slab_color_at_angle(coat.tint, cosNI, coat.ior);
1591 }
1592
1593 Spectrum albedo = zero_spectrum();
1594 if (reflective_caustics) {
1597 if (bsdf) {
1598 bsdf->N = coat.N;
1599 bsdf->T = zero_float3();
1600 bsdf->ior = coat.ior;
1601 bsdf->alpha_x = bsdf->alpha_y = sqr(coat.roughness);
1602
1603 const int runtime_flag = bsdf_microfacet_ggx_setup(bsdf);
1604 if (bsdf != &coat_bsdf) {
1605 /* Add flag only if the closure is actually allocated in `sd->closure`. */
1606 sd->runtime_flag |= runtime_flag;
1607 }
1609
1610 albedo = bsdf_microfacet_estimate_albedo(kg, sd->wi, bsdf, true, false);
1611 }
1612 }
1613
1614 /* Attenuate lower layers. */
1615 return (1.0f - coat.tint * (1.0f - albedo)) * coat.weight;
1616}
1617
#define D
#define Y
ccl_device_inline ccl_private ShaderClosure * bsdf_alloc(ccl_private ShaderData *sd, const int size, Spectrum weight)
Definition alloc.h:76
ccl_device_inline ccl_private Bsdf * bsdf_alloc_maybe_emission(ccl_private ShaderData *sd, ccl_private Bsdf *bsdf, Spectrum weight)
Definition alloc.h:97
#define A
ccl_device_forceinline float3 microfacet_beckmann_sample_vndf(const float3 wi, const float alpha_x, const float alpha_y, const float2 rand)
ccl_device_inline bool iszero(ccl_private const FresnelCoeff &coeff)
ccl_device void bsdf_microfacet_setup_fresnel_conductor(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const float3 wi, ccl_private FresnelConductor *fresnel, const bool preserve_energy)
ccl_device void bsdf_microfacet_setup_fresnel_generalized_schlick(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const float3 wi, ccl_private FresnelGeneralizedSchlick *fresnel, const bool preserve_energy)
ccl_device_forceinline FresnelCoeff generalized_schlick_fresnel(KernelGlobals kg, const ccl_private FresnelGeneralizedSchlick *fresnel, const float ior, const float cos_theta_i, ccl_private float *r_cos_theta_t)
ccl_device_inline void bsdf_thin_glass_transmission_setup(KernelGlobals kg, ccl_private ShaderData *sd, const Spectrum weight, const float3 N, const float alpha, const float ior, const PathRayVisibility ray_visibility, const uint32_t path_flag)
ccl_device Spectrum bsdf_microfacet_ggx_eval(KernelGlobals kg, const ccl_private ShaderClosure *sc, 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_coat_setup(KernelGlobals kg, ccl_private ShaderData *sd, const PathRayVisibility ray_visibility, ccl_private Coat &coat)
ccl_device Spectrum bsdf_microfacet_eval(KernelGlobals kg, const ccl_private ShaderClosure *sc, const float3 wi, const float3 wo, ccl_private float *pdf)
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_inline void microfacet_ggx_preserve_energy(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const float3 wi, const Spectrum Fss)
ccl_device_inline FresnelCoeff bsdf_thin_glass_fresnel(KernelGlobals kg, const bool reflective, const bool refractive, const FresnelCoeff tint, FresnelThinFilm thinfilm, const float ior, const float cos_theta_i)
ccl_device_forceinline FresnelGeneralizedSchlick generalized_schlick_setup(const float ior, const bool reflective_caustics, const bool refractive_caustics, const Spectrum reflection_tint, const Spectrum transmission_tint, FresnelThinFilm thinfilm)
ccl_device void bsdf_microfacet_setup_fresnel_f82_tint(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const float3 wi, ccl_private FresnelF82Tint *fresnel, const Spectrum f82_tint, const bool preserve_energy)
ccl_device_forceinline float mu_to_y_index(const float mu)
ccl_device_forceinline int bsdf_microfacet_eval_flag(const ccl_private MicrofacetBsdf *bsdf)
ccl_device_inline float bsdf_thin_glass_transmission_alpha(const float alpha, const float eta)
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_dielectric(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const float3 wi)
ccl_device void bsdf_dielectric_tint_setup(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, ccl_private ShaderData *sd, ccl_private FresnelDielectricTint *fresnel, const bool is_beckmann=false, const bool preserve_energy=true)
ccl_device Spectrum bsdf_thin_glass_transmission_eval(KernelGlobals kg, const ccl_private ShaderClosure *sc, const float3 wi, const float3 wo, ccl_private float *pdf)
ccl_device_inline float bsdf_D(const float alpha2, const float cos_NH)
ccl_device_forceinline float alpha_to_roughness_index(const float alpha_x, const float alpha_y)
ccl_device Spectrum bsdf_microfacet_estimate_albedo(KernelGlobals kg, const float3 wi, const ccl_private MicrofacetBsdf *bsdf, const bool eval_reflection, const bool eval_transmission)
ccl_device_inline float bsdf_lambda(const float alpha2, const float cos_N)
ccl_device Spectrum bsdf_microfacet_beckmann_eval(KernelGlobals kg, const ccl_private ShaderClosure *sc, const float3 wi, const float3 wo, ccl_private float *pdf)
ccl_device int bsdf_thin_glass_transmission_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_inline float bsdf_G(const float alpha2, const float cos_N)
ccl_device void bsdf_microfacet_setup_fresnel_constant(KernelGlobals kg, ccl_private MicrofacetBsdf *bsdf, const float3 wi, const Spectrum color)
ccl_device_forceinline bool alpha_is_almost_specular(const float alpha_x, const float alpha_y)
ccl_device FresnelCoeff bsdf_thin_glass_setup(KernelGlobals kg, ccl_private ShaderData *sd, const bool reflective, const bool refractive, const FresnelCoeff tint, const Spectrum weight, const float3 N, const float alpha, const float ior, const FresnelThinFilm thinfilm, const PathRayVisibility ray_visibility, const uint32_t path_flag)
ccl_device_inline void bsdf_thin_glass_reflection_setup(KernelGlobals kg, ccl_private ShaderData *sd, const Spectrum color, const Spectrum weight, const float3 N, const float alpha)
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)
ccl_device_inline float bsdf_glass_ior(ccl_private ShaderData *sd, float ior, const float inv_abbe)
ccl_device_inline void adjust_thin_film_ior_at_backface(ccl_private float &film_ior, const float inv_bulk_ior)
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_forceinline float ior_to_z_index(const float ior)
ccl_device int bsdf_microfacet_ggx_setup(ccl_private MicrofacetBsdf *bsdf)
ccl_device_forceinline FresnelCoeff microfacet_fresnel(KernelGlobals kg, const ccl_private MicrofacetBsdf *bsdf, const float cos_theta_i, ccl_private float *r_cos_theta_t)
ccl_device_inline Spectrum slab_color_at_angle(const float3 color, const float cos_theta_i, const float ior)
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_NAMESPACE_BEGIN ccl_device void bsdf_transparent_setup(ccl_private ShaderData *sd, const Spectrum weight, const uint32_t path_flag)
ccl_device_inline Spectrum fresnel_conductor_Fss(const complex< Spectrum > ior)
Definition bsdf_util.h:275
ccl_device float3 maybe_ensure_valid_specular_reflection(ccl_private ShaderData *sd, const float3 N)
Definition bsdf_util.h:399
ccl_device_inline Spectrum fresnel_f82_Fss(const Spectrum F0, const Spectrum B)
Definition bsdf_util.h:140
ccl_device_inline float fresnel_dielectric_Fss(const float eta)
Definition bsdf_util.h:131
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:103
ccl_device_inline Spectrum fresnel_f82(const float cosi, const Spectrum F0, const Spectrum B)
Definition bsdf_util.h:178
ccl_device float fresnel_iridescence_channel(KernelGlobals kg, const int channel, const float ambient_ior, const FresnelThinFilm thin_film, const float substrate_n, const float substrate_k, const float F82, const float cos_theta_1, ccl_private float *r_cos_theta_3)
Definition bsdf_util.h:499
ccl_device_inline Spectrum fresnel_f82tint_B(const Spectrum F0, const Spectrum tint)
Definition bsdf_util.h:146
btScalar max
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
transmission_tint
#define GGX_GLASS_E_RES_MU
Definition constants.h:13
#define GGX_GEN_SCHLICK_IOR_S_RES_IOR
Definition constants.h:22
#define GGX_GEN_SCHLICK_IOR_S_RES_MU
Definition constants.h:21
#define GGX_GEN_SCHLICK_S_RES_MU
Definition constants.h:17
#define GGX_GLASS_E_RES_ROUGH
Definition constants.h:12
#define GGX_E_RES_MU
Definition constants.h:10
#define GGX_GEN_SCHLICK_S_RES_ROUGH
Definition constants.h:16
#define GGX_GLASS_E_RES_IOR
Definition constants.h:14
#define GGX_GEN_SCHLICK_IOR_S_RES_ROUGH
Definition constants.h:20
#define GGX_GEN_SCHLICK_S_RES_IOR
Definition constants.h:18
#define GGX_E_RES_ROUGH
Definition constants.h:9
ccl_device_inline float3 disk_to_hemisphere(const float2 p)
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 THINFILM_THICKNESS_CUTOFF
#define ccl_device_forceinline
#define one_spectrum
#define zero_spectrum
#define make_spectrum(f)
#define ccl_private
#define ccl_device_inline
#define M_1_PI_F
#define FOREACH_SPECTRUM_CHANNEL(counter)
#define CLOSURE_IS_REFRACTION(type)
#define GET_SPECTRUM_CHANNEL(v, i)
#define ccl_device_inline_method
#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)
float F0_from_ior(float eta)
VecBase< T, D > reflect(VecOp< T, D >, VecOp< T, D >) RET
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
float fresnel_dielectric(float3 Incoming, float3 Normal, float eta)
float3 fresnel_conductor(float cosi, float3 eta, float3 k)
float sin_from_cos(float c)
bool is_zero(float3x3 a)
float safe_divide(float a, float b)
float average(float2 a)
@ 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_THIN_GLASS_TRANSMISSION_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_ID
uint32_t PathRayVisibility
@ SR_BSDF_HAS_TRANSMISSION
@ SR_BACKFACING
@ SR_BSDF_HAS_EVAL
@ SR_BSDF_HAS_DISPERSION
@ SR_BSDF
@ SD_REQUIRES_WAVELENGTH
@ PATH_RAY_VISIBILITY_CAMERA
@ PATH_RAY_VISIBILITY_DIFFUSE
@ 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 signf(const float f)
Definition math_base.h:502
ccl_device_inline float inversesqrtf(const float f)
Definition math_base.h:576
ccl_device_inline float safe_sqrtf(const float f)
Definition math_base.h:571
ccl_device_inline float inverse_lerp(const float a, const float b, const float x)
Definition math_base.h:554
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline dual1 len_squared(const ccl_private dual< T > &a)
Definition math_dual.h:273
ccl_device_inline float fast_erff(const float x)
Definition math_fast.h:568
ccl_device_inline float fast_ierff(const float x)
Definition math_fast.h:603
ccl_device_inline float2 power(const float2 v, const float e)
CCL_NAMESPACE_BEGIN ccl_device_inline float2 zero_float2()
Definition math_float2.h:13
ccl_device_inline bool isequal(const float2 a, const float2 b)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)
#define N
#define T
#define B
#define F
#define T2
Definition md5.cpp:21
#define T1
Definition md5.cpp:20
#define H(x, y, z)
#define X(TYPE)
#define mix
#define sqr
#define fabsf
#define sqrtf
#define ccl_device
#define M_2PI_F
#define fmaxf
#define make_float2
#define M_PI_F
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)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define saturate(a)
Definition smaa.cc:319
#define min(a, b)
Definition sort.cc:38
closure color coat_bsdf(color C, float ior, float roughness, normal N) BUILTIN
Spectrum reflectance
ccl_device_inline_method FresnelCoeff(Spectrum r_, Spectrum t_)
ccl_device_inline_method FresnelCoeff operator*(ccl_private const FresnelCoeff &other) const
ccl_device_inline_method FresnelCoeff operator*=(const T other)
FresnelCoeff()=default
ccl_device_inline_method Spectrum sum() const
ccl_device_inline_method FresnelCoeff operator*(const T reflectance_) const
ccl_device_inline_method FresnelCoeff(bool reflective, bool refractive)
Spectrum transmittance
complex< Spectrum > ior
FresnelThinFilm thin_film
FresnelThinFilm thin_film
FresnelThinFilm thin_film
ccl_private void * fresnel
float x
float y
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
CCL_NAMESPACE_BEGIN ccl_device_inline T to_global(const float2 p, const T X, const T Y)
Definition transform.h:21
float3 Spectrum
packed_float3 PackedSpectrum
CCL_NAMESPACE_BEGIN struct Window V