Antkeeper  0.0.1
phase.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_PHYSICS_LIGHT_PHASE_HPP
21 #define ANTKEEPER_PHYSICS_LIGHT_PHASE_HPP
22 
23 #include <engine/math/numbers.hpp>
24 #include <cmath>
25 
26 namespace physics {
27 namespace light {
28 
30 namespace phase {
31 
38 template <class T>
39 T cornette_shanks(T mu, T g);
40 
49 template <class T>
50 T henyey_greenstein(T mu, T g);
51 
55 template <class T>
56 constexpr T isotropic()
57 {
58  return T(1) / (T(4) * math::pi<T>);
59 }
60 
66 template <class T>
67 T rayleigh(T mu);
68 
69 template <class T>
70 T cornette_shanks(T mu, T g)
71 {
72  static const T k = T(3) / (T(8) * math::pi<T>);
73  const T gg = g * g;
74  const T num = (T(1) - gg) * (T(1) + mu * mu);
75  const T den = (T(2) + gg) * std::pow(T(1) + gg - T(2) * g * mu, T(1.5));
76  return k * num / den;
77 }
78 
79 template <class T>
80 T henyey_greenstein(T mu, T g)
81 {
82  const T gg = g * g;
83  return (T(1) - gg) / (T(4) * math::pi<T> * std::pow(T(1) + gg - T(2) * g * mu, T(1.5)));
84 }
85 
86 template <class T>
87 T rayleigh(T mu)
88 {
89  static const T k = T(3) / (T(16) * math::pi<T>);
90  return k * (1.0 + mu * mu);
91 }
92 
93 } // namespace phase
94 
95 } // namespace light
96 } // namespace physics
97 
98 #endif // ANTKEEPER_PHYSICS_LIGHT_PHASE_HPP
consteval T pow(T x, T e) noexcept
Compile-time pow for unsigned integrals.
Definition: compile.hpp:65
T henyey_greenstein(T mu, T g)
Henyey–Greenstein phase function.
Definition: phase.hpp:80
T cornette_shanks(T mu, T g)
Cornette-Shanks phase function.
Definition: phase.hpp:70
T rayleigh(T mu)
Rayleigh phase function.
Definition: phase.hpp:87
constexpr T isotropic()
Isotropic phase function.
Definition: phase.hpp:56
Physics.
Definition: constants.hpp:23