Ocean
RayIntersection.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_RENDERING_GI_RAY_INTERSECTION_H
9 #define META_OCEAN_RENDERING_GI_RAY_INTERSECTION_H
10 
13 
14 #include "ocean/math/Line3.h"
15 
18 
19 namespace Ocean
20 {
21 
22 namespace Rendering
23 {
24 
25 namespace GlobalIllumination
26 {
27 
28 // Forward declaration.
29 class TracingObject;
30 
31 // Forward declaration.
32 class RayIntersection;
33 
34 /**
35  * Definition of a vector holding ray intersection objects.
36  */
37 typedef std::vector<RayIntersection> RayIntersections;
38 
39 /**
40  * This class implements a ray intersection object.
41  * @ingroup renderinggi
42  */
44 {
45  public:
46 
47  /**
48  * Creates an empty ray intersection object.
49  */
50  inline RayIntersection();
51 
52  /**
53  * Creates a new ray intersection object.
54  * @param position Intersection position
55  * @param direction Intersection direction
56  * @param normal Intersection normal
57  * @param textureCoordinate Intersection texture coordinate
58  * @param distance Intersection distance
59  * @param tracingObject Tracing object pointer
60  * @param lightSources Light sources
61  */
63 
64  /**
65  * Returns the intersection position.
66  * @return Intersection position
67  */
68  inline const Vector3& position() const;
69 
70  /**
71  * Returns the intersection direction.
72  * @return Intersection direction
73  */
74  inline const Vector3& direction() const;
75 
76  /**
77  * Returns the normal.
78  * @return Intersection normal
79  */
80  inline const Normal& normal() const;
81 
82  /**
83  * Returns the intersection texture coordinate.
84  * @return Intersection texture coordinate
85  */
86  inline const TextureCoordinate& textureCoordinate() const;
87 
88  /**
89  * Returns the distance.
90  * @return Intersection distance
91  */
92  inline Scalar distance() const;
93 
94  /**
95  * Returns the renderable object.
96  * @return Renderable object
97  */
98  inline const TracingObject* tracingObject() const;
99 
100  /**
101  * Returns the light sources.
102  * @return Light sources
103  */
104  inline const LightSources& lightSources() const;
105 
106  /**
107  * Compares two objects.
108  * @param intersection Second object to compare
109  * @return True, if the second object has a small intersection distance
110  */
111  inline bool operator<(const RayIntersection& intersection) const;
112 
113  /**
114  * Returns whether this object holds a valid intersection.
115  * @return True, if so
116  */
117  explicit inline operator bool() const;
118 
119  private:
120 
121  /// Intersection position.
123 
124  /// Intersection direction.
126 
127  /// Intersection normal.
129 
130  /// Intersection texture coordinate.
132 
133  /// Intersection distance.
135 
136  /// Renderable object.
138 
139  /// Light sources.
141 };
142 
144  intersectionPosition(0, 0, 0),
145  intersectionDirection(0, 0, 0),
146  intersectionNormal(0, 0, 0),
147  intersectionTextureCoordinate(0, 0),
148  intersectionDistance(Numeric::maxValue()),
149  intersectionTracingObject(nullptr)
150 {
151  // nothing to do here
152 }
153 
154 inline RayIntersection::RayIntersection(const Vector3& position, const Vector3& direction, const Vector3& normal, const TextureCoordinate& textureCoordinate, const Scalar distance, const TracingObject* tracingObject, const LightSources& lightSources) :
155  intersectionPosition(position),
156  intersectionDirection(direction),
157  intersectionNormal(normal),
158  intersectionTextureCoordinate(textureCoordinate),
159  intersectionDistance(distance),
160  intersectionTracingObject(tracingObject),
161  intersectionLightSources(lightSources)
162 {
163  ocean_assert(Numeric::isEqual(normal.length(), 1));
164  ocean_assert(Numeric::isEqual(direction.length(), 1));
165 }
166 
167 inline const Vector3& RayIntersection::position() const
168 {
169  return intersectionPosition;
170 }
171 
172 inline const Vector3& RayIntersection::direction() const
173 {
174  return intersectionDirection;
175 }
176 
177 inline const Normal& RayIntersection::normal() const
178 {
179  return intersectionNormal;
180 }
181 
183 {
185 }
186 
188 {
189  return intersectionDistance;
190 }
191 
193 {
194  ocean_assert(intersectionTracingObject);
196 }
197 
199 {
201 }
202 
203 inline bool RayIntersection::operator<(const RayIntersection& intersection) const
204 {
205  return intersectionDistance < intersection.intersectionDistance;
206 }
207 
208 inline RayIntersection::operator bool() const
209 {
210  return intersectionDistance < Numeric::maxValue();
211 }
212 
213 }
214 
215 }
216 
217 }
218 
219 #endif // META_OCEAN_RENDERING_GI_RAY_INTERSECTION_H
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition: Numeric.h:2386
static constexpr T maxValue()
Returns the max scalar value.
Definition: Numeric.h:3244
This class implements a ray intersection object.
Definition: RayIntersection.h:44
const Normal & normal() const
Returns the normal.
Definition: RayIntersection.h:177
bool operator<(const RayIntersection &intersection) const
Compares two objects.
Definition: RayIntersection.h:203
TextureCoordinate intersectionTextureCoordinate
Intersection texture coordinate.
Definition: RayIntersection.h:131
const TracingObject * intersectionTracingObject
Renderable object.
Definition: RayIntersection.h:137
const Vector3 & position() const
Returns the intersection position.
Definition: RayIntersection.h:167
const Vector3 & direction() const
Returns the intersection direction.
Definition: RayIntersection.h:172
Normal intersectionNormal
Intersection normal.
Definition: RayIntersection.h:128
const LightSources & lightSources() const
Returns the light sources.
Definition: RayIntersection.h:198
const TextureCoordinate & textureCoordinate() const
Returns the intersection texture coordinate.
Definition: RayIntersection.h:182
Scalar intersectionDistance
Intersection distance.
Definition: RayIntersection.h:134
const TracingObject * tracingObject() const
Returns the renderable object.
Definition: RayIntersection.h:192
LightSources intersectionLightSources
Light sources.
Definition: RayIntersection.h:140
Vector3 intersectionDirection
Intersection direction.
Definition: RayIntersection.h:125
Scalar distance() const
Returns the distance.
Definition: RayIntersection.h:187
Vector3 intersectionPosition
Intersection position.
Definition: RayIntersection.h:122
RayIntersection()
Creates an empty ray intersection object.
Definition: RayIntersection.h:143
This class is the abstract base class for all tracing objects.
Definition: TracingObject.h:39
T length() const
Returns the length of the vector.
Definition: Vector3.h:664
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< LightPair > LightSources
Definition of a vector holding light pairs.
Definition: GILightSource.h:40
std::vector< RayIntersection > RayIntersections
Definition of a vector holding ray intersection objects.
Definition: RayIntersection.h:32
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15