Ocean
TracingObject.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_THING_H
9 #define META_OCEAN_RENDERING_GI_THING_H
10 
16 
18 
20 
21 namespace Ocean
22 {
23 
24 namespace Rendering
25 {
26 
27 namespace GlobalIllumination
28 {
29 
30 // Forward declaration.
31 class TracingGroup;
32 
33 /**
34  * This class is the abstract base class for all tracing objects.
35  * A tracing object represents the geometry and appearance of a renderable and holds all data necessary during the actual ray-tracing process.
36  * @ingroup renderinggi
37  */
38 class OCEAN_RENDERING_GI_EXPORT TracingObject
39 {
40  public:
41 
42  /**
43  * Creates a new tracing object.
44  */
45  TracingObject() = default;
46 
47  /**
48  * Destructs this tracing object.
49  */
50  virtual ~TracingObject();
51 
52  /**
53  * Sets the light sources that will be used for rendering.
54  * @param lightSources The light sources
55  */
56  void setLightSources(const LightSources& lightSources);
57 
58  /**
59  * Sets the attributes that will defined the appearance of the object.
60  * @param attributes The set of attributes
61  */
62  void setAttributes(const AttributeSetRef& attributes);
63 
64  /**
65  * Determines the nearest intersection with between this tracing object and a given 3D ray.
66  * @param ray The 3D ray for which the nearest intersection will be determined, must be valid
67  * @param intersection The resulting nearest intersection with the provided ray
68  * @param frontFace True, to determine intersections with front faces; False, to determine intersections with back faces
69  * @param eps The maximal distance between the ray and the object so that a not perfectly hitting ray still counts as intersecting
70  * @param excludedObject An optional tracing object that will be excluded from the determination
71  */
72  virtual void findNearestIntersection(const Line3& ray, RayIntersection& intersection, const bool frontFace, const Scalar eps, const TracingObject* excludedObject = nullptr) const = 0;
73 
74  /**
75  * Determines whether this tracing object has an intersection with a provided 3D ray.
76  * @param ray The 3D ray for which the nearest intersection will be determined, must be valid
77  * @param maximalDistance The maximal distance between the object and the starting point of the ray, with range [0, infinity)
78  * @param excludedObject An optional tracing object that will be excluded from the determination
79  * @return True, if the provided ray has an intersection with this object within the specified maximal distance
80  */
81  virtual bool hasIntersection(const Line3& ray, const Scalar maximalDistance = Numeric::maxValue(), const TracingObject* excludedObject = nullptr) const = 0;
82 
83  /**
84  * Determines the amount of light that transmits trough this object in the case e.g., this object is transparent.
85  * @param ray The ray of the light for which the damped color/light is determined
86  * @param color The resulting color/light
87  * @param maximalDistance The maximal distance between the start position of the ray and the intersection of the object, with rang (0, infinity)
88  * @return True, if succeeded
89  */
90  virtual bool determineDampingColor(const Line3& ray, RGBAColor& color, const Scalar maximalDistance = Numeric::maxValue()) const = 0;
91 
92  /**
93  * Determines the light (the color) for a specified viewing ray this object does reflect.
94  * @param viewPosition The start position of the viewing ray
95  * @param viewObjectDirection The direction of the viewing ray
96  * @param intersection The already known intersection of the viewing ray with this object
97  * @param group All tracing objects of the entire scene
98  * @param bounces The number of reflection bounces to be used, with range [0, infinity)
99  * @param excludedObject An optional tracking object to be excluded during this iteration, nullptr to use every tracing object
100  * @param lightingModes The light lightingModes which will be used for the lighting
101  * @param color The resulting color/light for the defined viewing ray
102  * @return True, if succeeded
103  */
104  virtual bool determineColor(const Vector3& viewPosition, const Vector3& viewObjectDirection, const RayIntersection& intersection, const TracingGroup& group, const unsigned int bounces, const TracingObject* excludedObject, const Lighting::LightingModes lightingModes, RGBAColor& color) const = 0;
105 
106  protected:
107 
108  /**
109  * Sets the transformation transforming points located in the coordinate system of this tracing object to points located in the world coordinate system.
110  * @param objectTransformation The transformation to be set
111  */
112  inline void setObjectTransformation(const HomogenousMatrix4& objectTransformation);
113 
114  protected:
115 
116  /// The transformation transforming points located in the coordinate system of this tracing object to points located in the world coordinate system.
117  HomogenousMatrix4 objectTransformation_ = HomogenousMatrix4(false);
118 
119  /// The transformation transforming points located in the world coordinate system to points located in this tracing object's coordinate system.
120  HomogenousMatrix4 invertedObjectTransformation_ = HomogenousMatrix4(false);
121 
122  /// The material of the sphere, if any.
124 
125  /// The textures of the sphere, if any.
127 
128  /// The light sources which will be used for rendering.
130 
131  /// The set of attributes defining the appearance of the sphere.
133 };
134 
135 inline void TracingObject::setObjectTransformation(const HomogenousMatrix4& objectTransformation)
136 {
137  ocean_assert(objectTransformation.isValid());
138 
139  objectTransformation_ = objectTransformation;
140  invertedObjectTransformation_ = objectTransformation.inverted();
141 }
142 
143 }
144 
145 }
146 
147 }
148 
149 #endif // META_OCEAN_RENDERING_GI_THING_H
HomogenousMatrixT4< T > inverted() const noexcept
Returns the inverted of this matrix.
Definition: HomogenousMatrix4.h:1575
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition: HomogenousMatrix4.h:1806
This class implements an infinite line in 3D space.
Definition: Line3.h:70
static constexpr T maxValue()
Returns the max scalar value.
Definition: Numeric.h:3244
This class implements a color defined by red, green, blue and alpha parameters.
Definition: RGBAColor.h:41
This class implements a Global Illumination material object.
Definition: GIMaterial.h:33
This class implements a Global Illumination texture attributes object.
Definition: GITextures.h:34
LightingModes
Definition of individual lighting modes.
Definition: Lighting.h:47
This class implements a ray intersection object.
Definition: RayIntersection.h:44
This class implements a group of tracing objects.
Definition: TracingGroup.h:28
This class is the abstract base class for all tracing objects.
Definition: TracingObject.h:39
HomogenousMatrix4 invertedObjectTransformation_
The transformation transforming points located in the world coordinate system to points located in th...
Definition: TracingObject.h:120
virtual ~TracingObject()
Destructs this tracing object.
void setAttributes(const AttributeSetRef &attributes)
Sets the attributes that will defined the appearance of the object.
virtual void findNearestIntersection(const Line3 &ray, RayIntersection &intersection, const bool frontFace, const Scalar eps, const TracingObject *excludedObject=nullptr) const =0
Determines the nearest intersection with between this tracing object and a given 3D ray.
TracingObject()=default
Creates a new tracing object.
HomogenousMatrix4 objectTransformation_
The transformation transforming points located in the coordinate system of this tracing object to poi...
Definition: TracingObject.h:117
LightSources lightSources_
The light sources which will be used for rendering.
Definition: TracingObject.h:129
AttributeSetRef attributes_
The set of attributes defining the appearance of the sphere.
Definition: TracingObject.h:132
GITextures * textures_
The textures of the sphere, if any.
Definition: TracingObject.h:126
void setObjectTransformation(const HomogenousMatrix4 &objectTransformation)
Sets the transformation transforming points located in the coordinate system of this tracing object t...
Definition: TracingObject.h:135
void setLightSources(const LightSources &lightSources)
Sets the light sources that will be used for rendering.
virtual bool determineDampingColor(const Line3 &ray, RGBAColor &color, const Scalar maximalDistance=Numeric::maxValue()) const =0
Determines the amount of light that transmits trough this object in the case e.g.,...
virtual bool determineColor(const Vector3 &viewPosition, const Vector3 &viewObjectDirection, const RayIntersection &intersection, const TracingGroup &group, const unsigned int bounces, const TracingObject *excludedObject, const Lighting::LightingModes lightingModes, RGBAColor &color) const =0
Determines the light (the color) for a specified viewing ray this object does reflect.
GIMaterial * material_
The material of the sphere, if any.
Definition: TracingObject.h:123
virtual bool hasIntersection(const Line3 &ray, const Scalar maximalDistance=Numeric::maxValue(), const TracingObject *excludedObject=nullptr) const =0
Determines whether this tracing object has an intersection with a provided 3D ray.
float Scalar
Definition of a scalar type.
Definition: Math.h:128
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition: HomogenousMatrix4.h:37
std::vector< LightPair > LightSources
Definition of a vector holding light pairs.
Definition: GILightSource.h:40
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15