Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SampleLocation.h
Go to the documentation of this file.
1#pragma once
2
3#include "Core/HitDetail.h"
4#include "Math/TVector3.h"
5#include "Math/TVector2.h"
7
8#include <limits>
9
10namespace ph
11{
12
21class SampleLocation final
22{
23 // FIXME: uvw should be in float64 for better highres pixel texture sample precision
24 // (test if required)
25 // FIXME: include LoD/footprint info
26
27public:
34
38 explicit SampleLocation(const HitDetail& hit);
41
42 SampleLocation(const SampleLocation& other);
43
47 math::Vector3R uvw() const;
48 math::Vector2R uv() const;
49 void setUvw(const math::Vector3R& uvw);
50 void setUv(const math::Vector2R& uv);
52
53 // TODO: should use uvw remapper instead
54 // or update derivatives?
55 SampleLocation getUvwScaled(const math::Vector3R& scale) const;
56
60
61private:
62 // TODO: seems we don't need all data in HitDetail for texture sampling;
63 // perhaps just store required data here
64 HitDetail m_hit;
65 const math::EColorUsage m_usage;
66};
67
68// In-header Implementations:
69
71 SampleLocation(HitDetail().setHitIntrinsics(nullptr, uvw, std::numeric_limits<real>::max()), usage)
72{}
73
75 SampleLocation(math::Vector3R(uv.x(), uv.y(), 0), usage)
76{}
77
79 SampleLocation(hit, math::EColorUsage::Raw)
80{}
81
83 m_hit(hit), m_usage(usage)
84{}
85
87 SampleLocation(other.m_hit, other.m_usage)
88{}
89
91{
92 return m_hit.getUVW();
93}
94
96{
97 const auto uvwCoords = uvw();
98 return {uvwCoords.x(), uvwCoords.y()};
99}
100
102{
103 m_hit.setHitIntrinsics(
104 m_hit.getPrimitive(),
105 uvw,
106 m_hit.getRayT(),
107 m_hit.getFaceID(),
108 m_hit.getFaceTopology());
109}
110
112{
113 setUvw(math::Vector3R(uv.x(), uv.y(), 0.0_r));
114}
115
117{
118 SampleLocation result(*this);
119 result.setUvw(m_hit.getUVW().mul(scale));
120 return result;
121}
122
124{
125 return m_usage;
126}
127
128}// end namespace ph
Detailed information regarding a ray-primitive intersection.
Definition HitDetail.h:26
uint64 getFaceID() const
Get the face ID associated to the hit.
Definition HitDetail.h:153
const Primitive * getPrimitive() const
Definition HitDetail.h:163
math::Vector3R getUVW() const
Definition HitDetail.h:168
real getRayT() const
Get the parametric distance from the incident ray's origin. Notice that parametric distance is not or...
Definition HitDetail.h:148
FaceTopology getFaceTopology() const
Definition HitDetail.h:158
HitDetail & setHitIntrinsics(const Primitive *primitive, const math::Vector3R &uvw, real rayT, uint64 faceID=NO_FACE_ID, FaceTopology faceTopology=FaceTopology(EFaceTopology::General))
Set essential attributes that are independent to the coordinate system.
Definition HitDetail.cpp:23
Definition SampleLocation.h:22
void setUvw(const math::Vector3R &uvw)
Definition SampleLocation.h:101
void setUv(const math::Vector2R &uv)
Definition SampleLocation.h:111
math::EColorUsage expectedUsage() const
Gets expected type of the usage for the sample.
Definition SampleLocation.h:123
SampleLocation(const math::Vector3R &uvw, math::EColorUsage usage)
Constructs a sample location at .
Definition SampleLocation.h:70
math::Vector2R uv() const
Definition SampleLocation.h:95
math::Vector3R uvw() const
Gets and sets the uvw coordinates of this sample location.
Definition SampleLocation.h:90
SampleLocation getUvwScaled(const math::Vector3R &scale) const
Definition SampleLocation.h:116
T & x()
Definition TVector2.ipp:38
T & y()
Definition TVector2.ipp:44
Derived mul(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:98
EColorUsage
Definition color_enums.h:140
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96