Loading...
Searching...
No Matches
heightcorrelated.h
Go to the documentation of this file.
1#ifndef _BBM_MASKINGSHADOWING_HEIGHT_CORRELATED_H_
2#define _BBM_MASKINGSHADOWING_HEIGHT_CORRELATED_H_
3
5
6/************************************************************************/
7/*! \file heightcorrelated.h
8
9 \brief Height correlated joint masking and shadowing. Follows Eq. 99 from
10 "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs"
11 [Heitz 2014]: https://jcgt.org/published/0003/02/03/
12*************************************************************************/
13
14namespace bbm {
15 namespace maskingshadowing {
16
17 /********************************************************************/
18 /*! \brief Height correlated joint masking and shadowing.
19
20 Follows Eq. 99 from "Understanding the Masking-Shadowing Function in
21 Microfacet-Based BRDFs" [Heitz 2014]:
22 https://jcgt.org/published/0003/02/03/
23 *********************************************************************/
24 template<typename CONF> requires concepts::config<CONF>
26 {
28
29 template<typename NDF> requires concepts::ndf<NDF> && concepts::matching_config<CONF, NDF>
30 static constexpr auto eval(const NDF& ndf, const Vec3d& in, const Vec3d& out, const Vec3d& m, Mask mask=true)
31 {
32 using return_t = decltype(ndf.G1(in, m, mask));
33
34 // check dot
35 mask &= (bbm::dot(in, m) > 0) && (bbm::dot(out, m) > 0);
36
37 // Quick bailout
38 if(bbm::none(mask)) return return_t(0);
39
40 // Compute Eq 99 = (1 + delta_i + delta_o)^-1
41 // = (1 + (1/g_i - 1) + (1/g_o - 1))^-1
42 // = (1/g_i + 1/g_o - 1)^-1
43 // = g_i*g_o / (g_i + g_o - g_i*g_o)
44 auto gi = ndf.G1(in, m, mask);
45 auto go = ndf.G1(out, m, mask);
46 auto gio = gi*go;
47 auto denom = gi + go - gio;
48
49 // check for division by zero
50 mask &= (denom > Constants::Epsilon());
51
52 // Done.
53 return bbm::select(mask, gio / denom, 0);
54 }
55 };
56
58
59 } // end maskingshadowing namespace
60} // end bbm namespace
61
62#endif /* _BBM_MASKINGSHADOWING_UNCORRELATED_H_ */
All necessary include files for defining new joint masking and shadowing functions.
config concept
Definition: config.h:31
maskingshadowing concept
Definition: maskingshadowing.h:24
matching_config concept
Definition: config.h:63
ndf concept
Definition: ndf.h:29
#define BBM_CHECK_CONCEPT(CONCEPTNAME, CLASSNAME,...)
Check a class for a concept with bbm::concepts::archetypes in the namespace.
Definition: macro.h:35
Definition: aggregatebsdf.h:29
constexpr auto select(MASK &&mask, const A &a, const A &b)
Definition: backbone.h:255
Height correlated joint masking and shadowing.
Definition: heightcorrelated.h:26
static constexpr auto eval(const NDF &ndf, const Vec3d &in, const Vec3d &out, const Vec3d &m, Mask mask=true)
Definition: heightcorrelated.h:30