Wayverb
surfaces.h
1 #pragma once
2 
3 #include "core/cl/scene_structs.h"
4 
5 namespace wayverb {
6 namespace core {
7 
8 // for both methods:
9 // define absorption coefficients per-band
10 // convert to absolute pressure-reflectance values
11 // should really be complex *shrug*
12 //
13 // waveguide:
14 // generate reflectance filter from pressure-reflectance per-band values
15 // convert to impedance filter
16 //
17 // image source:
18 // generate wall impedances from pressure reflectances
19 // convert back taking angle into account
20 //
21 // scattering:
22 // ???
23 
24 template <typename T>
25 constexpr T absorption_to_energy_reflectance(T t) {
26  return 1 - t;
27 }
28 
29 template <typename T>
30 T absorption_to_pressure_reflectance(T t) {
31  using std::sqrt;
32  return sqrt(absorption_to_energy_reflectance(t));
33 }
34 
35 template <typename T>
36 constexpr T pressure_reflectance_to_average_wall_impedance(T t) {
37  return (1 + t) / (1 - t);
38 }
39 
40 template <typename T>
41 constexpr T average_wall_impedance_to_pressure_reflectance(T t,
42  float cos_angle) {
43  if (cos_angle < 0 || 1 < cos_angle) {
44  throw std::runtime_error{"Cos angle is outside valid range."};
45  }
46  const T tmp = t * cos_angle;
47  const T ret = (tmp - 1) / (tmp + 1);
48  return ret;
49 }
50 
51 // vorlander2007 p. 45
52 // absorption = a, scattering = s
53 // total reflected energy = 1 - a
54 // scattered energy = s (1 - a)
55 // specular energy = (1 - s) (1 - a)
56 
57 template <typename T, typename U>
58 constexpr T scattered_pressure(T total_reflected, U scattering) {
59  return total_reflected * scattering;
60 }
61 
62 template <typename T, typename U>
63 constexpr T specular_pressure(T total_reflected, U scattering) {
64  return total_reflected * (1 - scattering);
65 }
66 
67 } // namespace core
68 } // namespace wayverb
Definition: traits.cpp:2
Definition: capsule_base.h:9