Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSphere.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/math.h"
5#include "Math/math_fwd.h"
7
8#include <array>
9#include <utility>
10
11namespace ph::math
12{
13
18template<typename T>
19class TSphere final
20{
21public:
22 static TSphere makeUnit();
23
24 TSphere() = default;
25
29 explicit TSphere(T radius);
30
35 bool isIntersecting(
36 const TLineSegment<T>& segment,
37 real* out_hitT) const;
38
41 /*bool isIntersectingRefined(
42 const TLineSegment<T>& segment,
43 T* out_hitT) const;*/
44
45 bool isInside(const TVector3<T>& point) const;
46
47 T getRadius() const;
48 T getArea() const;
49 TAABB3D<T> getAABB() const;
50
56 bool mayOverlapVolume(const TAABB3D<T>& volume) const;
57
61
69 TVector3<T> sampleToSurfaceArchimedes(const std::array<T, 2>& sample) const;
70
75 TVector3<T> sampleToSurfaceArchimedes(const std::array<T, 2>& sample, T* out_pdfA) const;
77
81
86 TVector3<T> sampleToSurfaceAbsCosThetaWeighted(const std::array<T, 2>& sample) const;
87
92 TVector3<T> sampleToSurfaceAbsCosThetaWeighted(const std::array<T, 2>& sample, T* out_pdfA) const;
94
96
97 TVector2<T> surfaceToLatLong01(const TVector3<T>& surface) const;
98 TVector2<T> latLong01ToPhiTheta(const TVector2<T>& latLong01) const;
99 TVector3<T> latLong01ToSurface(const TVector2<T>& latLong01) const;
100
103 TVector2<T> surfaceToPhiTheta(const TVector3<T>& surface) const;
104
107 TVector3<T> phiThetaToSurface(const TVector2<T>& phiTheta) const;
108
121 template<typename SurfaceToUv>
122 std::pair<TVector3<T>, TVector3<T>> surfaceDerivativesWrtUv(
123 const TVector3<T>& surface,
124 SurfaceToUv surfaceToUv,
125 T hInRadians = to_radians<T>(1)) const;
126
127private:
129 bool isIntersectingNaive(
130 const TLineSegment<T>& segment,
131 real* out_hitT) const;
132
134 bool isIntersectingHearnBaker(
135 const TLineSegment<T>& segment,
136 real* out_hitT) const;
137
138 T m_radius;
139};
140
141}// end namespace ph::math
142
A 3-D Axis-Aligned Bounding Box (AABB).
Definition TAABB3D.h:32
Represents a line segment in space.
Definition TLineSegment.h:25
A sphere in 3-D space.
Definition TSphere.h:20
static TSphere makeUnit()
Definition TSphere.ipp:19
TVector2< T > surfaceToPhiTheta(const TVector3< T > &surface) const
Map Cartesian to spherical coordinates on the surface of the sphere.
Definition TSphere.ipp:422
bool isInside(const TVector3< T > &point) const
Same as isIntersecting(), except the cost is slightly higher to reduce numerical error.
Definition TSphere.ipp:63
TVector3< T > latLong01ToSurface(const TVector2< T > &latLong01) const
Definition TSphere.ipp:416
TVector2< T > surfaceToLatLong01(const TVector3< T > &surface) const
Definition TSphere.ipp:393
T getArea() const
Definition TSphere.ipp:266
TAABB3D< T > getAABB() const
Definition TSphere.ipp:272
TVector3< T > phiThetaToSurface(const TVector2< T > &phiTheta) const
Map spherical to Cartesian coordinates on the surface of the sphere.
Definition TSphere.ipp:440
TVector2< T > latLong01ToPhiTheta(const TVector2< T > &latLong01) const
Definition TSphere.ipp:405
T uniformSurfaceSamplePdfA() const
Definition TSphere.ipp:386
T getRadius() const
Definition TSphere.ipp:260
TVector3< T > sampleToSurfaceArchimedes(const std::array< T, 2 > &sample) const
Definition TSphere.ipp:319
TVector3< T > sampleToSurfaceAbsCosThetaWeighted(const std::array< T, 2 > &sample) const
Definition TSphere.ipp:349
bool mayOverlapVolume(const TAABB3D< T > &volume) const
Conservatively checks whether this sphere overlaps a volume. By conservative, it means true can be re...
Definition TSphere.ipp:283
std::pair< TVector3< T >, TVector3< T > > surfaceDerivativesWrtUv(const TVector3< T > &surface, SurfaceToUv surfaceToUv, T hInRadians=to_radians< T >(1)) const
Calculate dPdU and dPdV with finite difference.
Definition TSphere.ipp:457
bool isIntersecting(const TLineSegment< T > &segment, real *out_hitT) const
Checks whether the segment is interseting with this sphere.
Definition TSphere.ipp:32
Represents a 2-D vector.
Definition TVector2.h:19
Represents a 3-D vector.
Definition TVector3.h:17
Miscellaneous math utilities.
Math functions and utilities.
Definition TransformInfo.h:10
T to_radians(const T degrees)
Convert degrees to radians.
Definition math.h:140