Wayverb
structs.h
1 #pragma once
2 
3 #include "raytracer/cl/reflection.h"
4 
5 #include "core/cl/representation.h"
6 #include "core/cl/scene_structs.h"
7 #include "core/cl/traits.h"
8 
9 namespace wayverb {
10 namespace raytracer {
11 
12 struct alignas(1 << 5) stochastic_path_info final {
13  core::bands_type volume; // product of previous specular components
14  cl_float3 position; // because otherwise we won't be able to
15  // calculate a new distance
16  cl_float distance; // total distance travelled
17 };
18 
19 constexpr auto to_tuple(const stochastic_path_info& x) {
20  return std::tie(x.volume, x.position, x.distance);
21 }
22 
23 constexpr bool operator==(const stochastic_path_info& a,
24  const stochastic_path_info& b) {
25  return to_tuple(a) == to_tuple(b);
26 }
27 
28 constexpr bool operator!=(const stochastic_path_info& a,
29  const stochastic_path_info& b) {
30  return !(a == b);
31 }
32 
34 
37 template <size_t channels>
38 struct alignas(1 << 5) impulse final {
39  detail::cl_vector_constructor_t<float, channels>
40  volume; // actual per-band volume of the impulse
41  cl_float3 position; // position of the secondary source (used for
42  // attenuation)
43  cl_float distance; // distance that the carrier ray has travelled
44 };
45 
46 template <typename T>
47 constexpr auto make_impulse(T volume, cl_float3 position, cl_float distance) {
48  return impulse<detail::components_v<T>>{volume, position, distance};
49 }
50 
51 template <size_t channels>
52 constexpr auto to_tuple(const impulse<channels>& x) {
53  return std::tie(x.volume, x.position, x.distance);
54 }
55 
56 template <size_t channels>
57 constexpr bool operator==(const impulse<channels>& a,
58  const impulse<channels>& b) {
59  return to_tuple(a) == to_tuple(b);
60 }
61 
62 template <size_t channels>
63 constexpr bool operator!=(const impulse<channels>& a,
64  const impulse<channels>& b) {
65  return !(a == b);
66 }
67 
69 
70 template <size_t channels>
71 struct alignas(1 << 5) attenuated_impulse final {
72  detail::cl_vector_constructor_t<float, channels> volume;
73  cl_float distance;
74 };
75 
76 template <typename T>
77 constexpr auto make_attenuated_impulse(T volume, cl_float distance) {
78  return attenuated_impulse<detail::components_v<T>>{volume, distance};
79 }
80 
81 template <size_t channels>
82 constexpr auto to_tuple(const attenuated_impulse<channels>& x) {
83  return std::tie(x.volume, x.distance);
84 }
85 
86 template <size_t channels>
87 constexpr bool operator==(const attenuated_impulse<channels>& a,
89  return to_tuple(a) == to_tuple(b);
90 }
91 
92 template <size_t channels>
93 constexpr bool operator!=(const attenuated_impulse<channels>& a,
95  return !(a == b);
96 }
97 
98 } // namespace raytracer
99 
100 template <>
101 struct core::cl_representation<raytracer::reflection> final {
102  static constexpr auto value = R"(
103 typedef struct {
104  float3 position;
105  uint triangle;
106  char keep_going;
107  char receiver_visible;
108 } reflection;
109 )";
110 };
111 
112 template <>
113 struct core::cl_representation<raytracer::stochastic_path_info> final {
114  static constexpr auto value = R"(
115 typedef struct {
116  bands_type volume;
117  float3 position;
118  float distance;
119 } stochastic_path_info;
120 )";
121 };
122 
123 template <>
124 struct core::cl_representation<raytracer::impulse<8>> final {
125  static constexpr auto value = R"(
126 typedef struct {
127  bands_type volume;
128  float3 position;
129  float distance;
130 } impulse;
131 )";
132 };
133 
134 template <>
135 struct core::cl_representation<raytracer::attenuated_impulse<8>> final {
136  static constexpr auto value = R"(
137 typedef struct {
138  bands_type volume;
139  float distance;
140 } attenuated_impulse;
141 )";
142 };
143 
144 } // namespace wayverb
Definition: representation.h:7
Definition: structs.h:38
Definition: pressure.h:22
Definition: capsule_base.h:9