Loading...
Searching...
No Matches
fresnel_complex.h
Go to the documentation of this file.
1#ifndef _BBM_FRESNEL_COMPLEX_H_
2#define _BBM_FRESNEL_COMPLEX_H_
3
4#include "concepts/fresnel.h"
5#include "bbm/config.h"
6
7namespace bbm {
8 namespace fresnel {
9
10 template<typename CONF, typename VALUE=Value_t<CONF>> requires concepts::config<CONF>
11 struct complex
12 {
14
15 //! \brief Fresnel Parameter Type
17
18 /******************************************************************/
19 /*! \brief
20
21 "Physically based Lighting Calculations for Computer Graphics"
22 [Shirley 1985]: https://dl.acm.org/doi/10.5555/124947
23
24 p15, Eqs. 2.4-2.7 for dielectric-conductor interfaces (assuming
25 dielitric is air with ior=1).
26
27 Implements: concepts::fresnel
28 ******************************************************************/
29 static constexpr VALUE eval(const parameter_type& param, const Value& cosTheta, Mask mask=true)
30 {
31 auto cosTheta2 = cosTheta*cosTheta;
32 auto sinTheta2 = 1 - cosTheta2;
33
34 auto n = real(param), n2 = n*n;
35 auto k = imag(param), k2 = k*k;
36
37 // Compute a, and a2 + b2 (Eqs. 2.6 & 2.7)
38 auto temp = n2 - k2 - sinTheta2;
39 auto a2b2 = bbm::safe_sqrt( temp*temp + 4*n2*k2 );
40 auto a = bbm::safe_sqrt(0.5 * (a2b2 + temp));
41
42 // Compute Rs (Eq. 2.4)
43 auto a2c = 2*a*cosTheta;
44 auto Rs = (a2b2 - a2c + cosTheta2) / (a2b2 + a2c + cosTheta2);
45
46 // Compute Rp (Eq. 2.5; replace tanTheta by sinTheta/cosTheta)
47 auto Rp = Rs * (cosTheta2*a2b2 - (a2c - sinTheta2)*sinTheta2) / (cosTheta2*a2b2 + (a2c + sinTheta2)*sinTheta2);
48
49 // Done.
50 return bbm::select(mask, 0.5*(Rs+Rp), 0.0);
51 }
52 };
53
56
57 } // end fresnel namespace
58} // end bbm namespace
59
60#endif /* _BBM_FRESNEL_COMPLEX_H_ */
All BBM methods are defined to operate on a variety of value types and spectrum types....
config concept
Definition: config.h:31
fresnel concept
Definition: fresnel.h:27
fresnel contract
#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
typename get_config< T >::Value Value_t
Definition: config.h:67
typename get_config< T >::Spectrum Spectrum_t
Definition: config.h:68
Base declaration of attribute; further specialized below.
Definition: attribute.h:26
Definition: fresnel_complex.h:12
static constexpr VALUE eval(const parameter_type &param, const Value &cosTheta, Mask mask=true)
"Physically based Lighting Calculations for Computer Graphics"
Definition: fresnel_complex.h:29