Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
RayDifferential.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TVector3.h"
4
5#include <limits>
6
7namespace ph
8{
9
10class RayDifferential final
11{
12public:
14 RayDifferential(const math::Vector3R& dPdX, const math::Vector3R& dPdY,
15 const math::Vector3R& dDdX, const math::Vector3R& dDdY);
16
17 // Propagate differential quantities to some location on a surface the ray
18 // has intersected. Specifically, calculate ray differentials on location
19 // <surfaceP> with surface normal <surfaceN>.
20 void transferToSurface(const math::Vector3R& surfaceP, const math::Vector3R& surfaceN);
21
22 // Modify differential quantities as if the ray is reversed in
23 // direction.
24 inline void reverse()
25 {
26 m_dDdX.mulLocal(-1);
27 m_dDdY.mulLocal(-1);
28 }
29
30 inline void setPartialPs(const math::Vector3R& dPdX, const math::Vector3R& dPdY)
31 {
32 m_dPdX = dPdX;
33 m_dPdY = dPdY;
34
35 m_isPartialPsNonZero = isVectorNonZero(dPdX) || isVectorNonZero(dPdY);
36 }
37
38 inline void setPartialDs(const math::Vector3R& dDdX, const math::Vector3R& dDdY)
39 {
40 m_dDdX = dDdX;
41 m_dDdY = dDdY;
42
43 m_isPartialDsNonZero = isVectorNonZero(dDdX) || isVectorNonZero(dDdY);
44 }
45
46 inline const math::Vector3R& getdPdX() const { return m_dPdX; }
47 inline const math::Vector3R& getdPdY() const { return m_dPdY; }
48 inline const math::Vector3R& getdDdX() const { return m_dDdX; }
49 inline const math::Vector3R& getdDdY() const { return m_dDdY; }
50
51 inline bool isNonZero() const { return m_isPartialPsNonZero || m_isPartialDsNonZero; }
52
53private:
54 // A point P on a ray.
56
57 // Direction D of a ray.
59
60 // Partial derivatives for P & D with respect to raster coordinates x & y.
61 math::Vector3R m_dPdX, m_dPdY;
62 math::Vector3R m_dDdX, m_dDdY;
63
64 bool m_isPartialPsNonZero;
65 bool m_isPartialDsNonZero;
66
67 static inline bool isVectorNonZero(const math::Vector3R& vec)
68 {
69 return vec.lengthSquared() > std::numeric_limits<real>::epsilon();
70 }
71};
72
73}// end namespace ph
Definition RayDifferential.h:11
const math::Vector3R & getdDdY() const
Definition RayDifferential.h:49
const math::Vector3R & getdPdY() const
Definition RayDifferential.h:47
const math::Vector3R & getdDdX() const
Definition RayDifferential.h:48
void setPartialDs(const math::Vector3R &dDdX, const math::Vector3R &dDdY)
Definition RayDifferential.h:38
const math::Vector3R & getdPdX() const
Definition RayDifferential.h:46
void transferToSurface(const math::Vector3R &surfaceP, const math::Vector3R &surfaceN)
Definition RayDifferential.cpp:21
void reverse()
Definition RayDifferential.h:24
bool isNonZero() const
Definition RayDifferential.h:51
void setPartialPs(const math::Vector3R &dPdX, const math::Vector3R &dPdY)
Definition RayDifferential.h:30
RayDifferential()
Definition RayDifferential.cpp:10
Derived & mulLocal(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:112
T lengthSquared() const
Definition TVectorNBase.ipp:44
The root for all renderer implementations.
Definition EEngineProject.h:6