Loading...
Searching...
No Matches
ior.h
Go to the documentation of this file.
1#ifndef _BBM_IOR_H_
2#define _BBM_IOR_H_
3
4#include <type_traits>
5
6#include "core/attribute.h"
7
8/***********************************************************************/
9/*! \file ior.h
10 \brief Defines 'ior' and 'reflectance' types
11
12 Index of refraction (ior) and reflectance at normal incidence are two
13 common methods for parameterizing Fresnel reflectance. Both are floats.
14 BBM defines both as an attribute variable with property 'tags':
15 reflectance_tag and ior_tag.
16
17 *************************************************************************/
18
19namespace bbm {
20
21 //! \brief Namespace for 'ior' and 'reflectance' types.
22 namespace ior {
23
24 //////////
25 // Tags //
26 //////////
27 template<typename T> struct ior_tag { using type = T; };
28 template<typename T> struct complex_ior_tag { using type = bbm::complex<T>; };
29 template<typename T> struct reflectance_tag { using type = T; };
30
31 ////////////////////////////////////
32 //! @{ \name Type definition
33 /////////////////////////////////////
34 template<typename T> using ior = attribute<ior_tag<T>>;
35 template<typename T> using complex_ior = attribute<complex_ior_tag<T>>;
36 template<typename T> using reflectance = attribute<reflectance_tag<T>>;
37 //! @}
38
39
40 /*******************************************************************/
41 /*! @{ \name type traits
42 *******************************************************************/
46
47 template<typename T> concept is_ior_type = is_ior_v<T> || is_complex_ior_v<T> || is_reflectance_v<T>;
48 //! @}
49
50
51 /*******************************************************************/
52 /*! @{ \name Conversion between 'ior' and 'reflectance'
53 \brief Conversion between 'ior' and 'reflectance' types
54
55 \param target = type to copy to.
56 \param source = which variable to copy from
57 *******************************************************************/
58 template<typename T>
59 void convert(reflectance<T>& target, const ior<T>& i)
60 {
61 // ior to reflectance
62 T temp = (T(i) - 1.0f) / (T(i) + 1.0f);
63 target = temp*temp;
64 }
65
66 template<typename T>
67 void convert(ior<T>& target, const reflectance<T>& r)
68 {
69 // reflectance to ior
70 T temp = bbm::safe_sqrt(T(r));
71 target = (1.0f + temp) / (1.0f - temp);
72 }
73
74 template<typename T>
75 void convert(complex<T>& target, const ior<T>& i)
76 {
77 target = complex<T>(T(i), T(0));
78 }
79 //! @}
80
81 } // end ior namespace
82
83} // end bbm namespace
84
85#endif /* _BBM_IOR_H_ */
has_attribute_property concept
Definition: attribute.h:65
Definition: ior.h:44
Definition: ior.h:47
Definition: ior.h:43
Definition: ior.h:45
A warpper class to attach a properties to a class via a property struct. The propert expects by defau...
void convert(reflectance< T > &target, const ior< T > &i)
Definition: ior.h:59
attribute< ior_tag< T > > ior
Definition: ior.h:34
T type
Definition: ior.h:27
Definition: ior.h:28
Definition: ior.h:27
Definition: ior.h:29
Definition: aggregatebsdf.h:29
Base declaration of attribute; further specialized below.
Definition: attribute.h:26
Complex numbers.
Definition: complex.h:22