Wayverb
geometry_structs.h
1 #pragma once
2 
3 #include "core/almost_equal.h"
4 #include "core/cl/scene_structs.h"
5 
6 #include <string>
7 
8 namespace wayverb {
9 namespace core {
10 
11 struct alignas(1 << 4) ray final {
12  cl_float3 position;
13  cl_float3 direction;
14 };
15 
16 template <>
17 struct cl_representation<ray> final {
18  static constexpr auto value = R"(
19 typedef struct {
20  float3 position;
21  float3 direction;
22 } ray;
23 )";
24 };
25 
26 constexpr auto to_tuple(const ray& x) {
27  return std::tie(x.position, x.direction);
28 }
29 
30 constexpr bool operator==(const ray& a, const ray& b) {
31  return to_tuple(a) == to_tuple(b);
32 }
33 
34 constexpr bool operator!=(const ray& a, const ray& b) { return !(a == b); }
35 
37 
38 struct alignas(1 << 2) triangle_inter final {
39  cl_float t; // the distance along the ray to the intersection
40  cl_float u; // barycentric coordinate u
41  cl_float v; // barycentric coordinate v
42 };
43 
44 template <>
46  static constexpr auto value = R"(
47 typedef struct {
48  float t;
49  float u;
50  float v;
51 } triangle_inter;
52 )";
53 };
54 
55 constexpr bool operator==(const triangle_inter& a, const triangle_inter& b) {
56  return std::tie(a.t, a.u, a.v) == std::tie(b.t, b.u, b.v);
57 }
58 
59 constexpr bool operator!=(const triangle_inter& a, const triangle_inter& b) {
60  return !(a == b);
61 }
62 
63 constexpr bool is_degenerate(const triangle_inter& i) {
64  const auto ulp = 10;
65  return almost_equal(i.u, 0.0f, ulp) || almost_equal(i.v, 0.0f, ulp) ||
66  almost_equal(i.u + i.v, 1.0f, ulp);
67 }
68 
70 
71 struct alignas(1 << 3) intersection final {
72  triangle_inter inter;
73  cl_uint index;
74 };
75 
76 template <>
78  static constexpr auto value = R"(
79 typedef struct {
80  triangle_inter inter;
81  uint index;
82 } intersection;
83 )";
84 };
85 
86 constexpr auto to_tuple(const intersection& x) {
87  return std::tie(x.inter, x.index);
88 }
89 
90 constexpr bool operator==(const intersection& a, const intersection& b) {
91  return to_tuple(a) == to_tuple(b);
92 }
93 
94 constexpr bool operator!=(const intersection& a, const intersection& b) {
95  return !(a == b);
96 }
97 
98 } // namespace core
99 } // namespace wayverb
Definition: geometry_structs.h:11
Definition: representation.h:7
Definition: traits.cpp:2
Definition: geometry_structs.h:71
Definition: geometry_structs.h:38
Definition: capsule_base.h:9