Loading...
Searching...
No Matches
fresnel_cook.h
Go to the documentation of this file.
1#ifndef _BBM_FRESNEL_COOK_H_
2#define _BBM_FRESNEL_COOK_H_
3
4#include "concepts/fresnel.h"
5#include "bbm/config.h"
6
7namespace bbm {
8 namespace fresnel {
9
10 /*******************************************************************/
11 /*! \brief Implements the Fresnel reflectance equation as proposed by Cook
12 and Torrance [SIGGRAPH'82]: https://doi.org/10.1145/357290.357293
13
14 \tparam CONF = bbm configuration
15 \tparam PARAM = parameter type (ior)
16
17 Implements: concepts::fresnel
18 ********************************************************************/
19 template<typename CONF, typename PARAM=ior::ior<Value_t<CONF>>> requires concepts::config<CONF>
20 struct cook
21 {
23
24 //! \brief Fresnel Parameter Type
25 using parameter_type = PARAM;
26
27 /*****************************************************************/
28 /*! \brief Evaluate Fresnel reflectance
29
30 This method follows Cook and Torrance's [SIGGRAPH' 82] suggested
31 evaluation of the Fresnel reflectance
32 (https://doi.org/10.1145/357290.357293). The method takes either ior
33 or reflectance (relies on auto-conversion to ior), as well as the dot
34 product between view and halfway vector (cosTheta) as input.
35
36 \param param = index of refraction
37 \param cosTheta = dot product between view and halfway.
38 \param mask = mask compute lines
39 \returns Fresnel reflectance with the type determined from the underlying type of the parameter.
40 *******************************************************************/
41 static constexpr typename std::decay_t<parameter_type>::type eval(const parameter_type& param, const Value& cosTheta, Mask mask=true)
42 {
43 // quick bail out
44 if(bbm::none(mask)) return 0;
45
46 // do computations with ior::ior
48
49 // compute
50 auto g = bbm::safe_sqrt( eta*eta + cosTheta*cosTheta - Scalar(1.0) );
51 auto a = (g - cosTheta) / (g + cosTheta);
52 auto b = (cosTheta*(g+cosTheta) - Scalar(1.0)) / (cosTheta*(g-cosTheta) + Scalar(1.0));
53
54 // Done.
55 return bbm::select(mask, bbm::max(Scalar(0.5) * (a*a) * (Scalar(1.0) + b*b), 0.0), 0.0);
56 }
57
58 };
59
60 // check Value_t variants
63
64 // check Spectrum_t variants
67
68 } // end fresnel namespace
69} // end bbm namespace
70
71
72#endif /* _BBM_FRESNEL_COOK_H_ */
All BBM methods are defined to operate on a variety of value types and spectrum types....
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
void fresnel(py::module &m, const std::string &prefix="")
Define a python interface for ior::ior and ior::reflectance given a value type T.
Definition: py_fresnel.h:22
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
Implements the Fresnel reflectance equation as proposed by Cook and Torrance [SIGGRAPH'82]: https://d...
Definition: fresnel_cook.h:21
PARAM parameter_type
Fresnel Parameter Type.
Definition: fresnel_cook.h:25
static constexpr std::decay_t< parameter_type >::type eval(const parameter_type &param, const Value &cosTheta, Mask mask=true)
Evaluate Fresnel reflectance.
Definition: fresnel_cook.h:41