Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSamplingFilm.ipp
Go to the documentation of this file.
2#include "Math/TVector3.h"
3#include "Frame/TFrame.h"
7
8#include <Common/assertion.h>
9#include <Common/logging.h>
10
11#include <cstddef>
12#include <iostream>
13#include <algorithm>
14
15namespace ph
16{
17
18template<typename Sample>
20 const int64 actualWidthPx,
21 const int64 actualHeightPx,
22 const SampleFilter& filter)
23
25 actualWidthPx,
26 actualHeightPx,
27 math::TAABB2D<int64>(
28 math::TVector2<int64>(0, 0),
29 math::TVector2<int64>(actualWidthPx, actualHeightPx)),
30 filter)
31{}
32
33template<typename Sample>
35 const int64 actualWidthPx,
36 const int64 actualHeightPx,
37 const math::TAABB2D<int64>& effectiveWindowPx,
38 const SampleFilter& filter)
39
40 : Film(
41 actualWidthPx,
42 actualHeightPx,
43 effectiveWindowPx)
44
45 , m_filter(filter)
46 , m_sampleWindowPx(math::TAABB2D<float64>::makeEmpty())
47 , m_softness(1.0f)
48{
49 setSoftEdge(true);
50
51 PH_ASSERT(!getSampleWindowPx().isEmpty());
52}
53
54template<typename Sample>
56{
57 Film::setEffectiveWindowPx(effectiveWindow);
59 updateSampleDimensions();
60}
61
62template<typename Sample>
63inline void TSamplingFilm<Sample>::setSoftEdge(const bool useSoftEdge, const float32 softness)
64{
65 PH_ASSERT_IN_RANGE_INCLUSIVE(softness, 0.0f, 1.0f);
66 m_softness = useSoftEdge ? softness : 0.0f;
67
68 updateSampleDimensions();
69}
70
71template<typename Sample>
74 return m_filter;
77template<typename Sample>
79{
80 return {m_sampleWindowPx.getWidth(), m_sampleWindowPx.getHeight()};
81}
82
83template<typename Sample>
85 -> const math::TAABB2D<float64>&
86{
87 return m_sampleWindowPx;
88}
89
90template<typename Sample>
92{
93 return {getActualResPx(), getEffectiveWindowPx(), getSampleWindowPx()};
94}
95
96template<typename Sample>
98{
99 return m_softness > 0.0f;
100}
101
102template<typename Sample>
104{
105 // Softness = 1: full filter half size; 0: nothing
106 const auto pxToExpand = math::Vector2D(m_filter.getHalfSizePx()) * m_softness;
107
108 // Expand from pixel centers (discrete coordinates + 0.5)
109 m_sampleWindowPx = math::TAABB2D<float64>(
110 math::Vector2D(getEffectiveWindowPx().getMinVertex()).add(0.5).sub(pxToExpand),
111 math::Vector2D(getEffectiveWindowPx().getMaxVertex()).sub(0.5).add(pxToExpand));
112
113 if(m_sampleWindowPx.isEmpty())
114 {
115 PH_DEFAULT_LOG(Warning,
116 "Sampling film has empty sample window (effective window = {}, half filter size = {}, "
117 "softness = {}).", getEffectiveWindowPx().toString(), getFilter().getHalfSizePx(), m_softness);
118 }
119
120 // Even if softness is 0, sample window will not necessarily equal to effective window. Sample
121 // window is the region where samples will contribute to the film, and that depends on the
122 // filter size. Only filters of unit size (with softness = 0) will make sample window equal
123 // to effective window.
124#if PH_DEBUG
125 if(m_softness == 0.0f && m_filter.getHalfSizePx().isEqual({0.5, 0.5}))
126 {
127 // For fairly small integers and only do +- of 0.5, no numerical error should manifest
128 const auto fEffectiveWindowPx = math::TAABB2D<float64>(getEffectiveWindowPx());
129 PH_ASSERT_MSG(m_sampleWindowPx == fEffectiveWindowPx,
130 "sample window = " + m_sampleWindowPx.toString() + ", "
131 "effective window = " + fEffectiveWindowPx.toString());
132 }
133#endif
134}
135
136}// end namespace ph
A camera film that receives any quantity.
Definition Film.h:17
virtual void setEffectiveWindowPx(const math::TAABB2D< int64 > &effectiveWindow)
Set the region where the film will be used. Implementation is advised to take advantage of this and o...
Definition Film.h:75
An image reconstruction kernel.
Definition SampleFilter.h:17
A camera film that receives any quantity, for sampling-based rendering techniques.
Definition TSamplingFilm.h:22
TSamplingFilm()=default
const SampleFilter & getFilter() const
Definition TSamplingFilm.ipp:72
void setSoftEdge(bool useSoftEdge, float32 softness=1.0f)
Whether to increase the sampling window converage for prettier boundaries in developed frame....
Definition TSamplingFilm.ipp:63
math::TVector2< float64 > getSampleResPx() const
Definition TSamplingFilm.ipp:78
bool isSoftEdged() const
Definition TSamplingFilm.ipp:97
const math::TAABB2D< float64 > & getSampleWindowPx() const
Definition TSamplingFilm.ipp:84
void setEffectiveWindowPx(const math::TAABB2D< int64 > &effectiveWindow) override
Set the region where the film will be used. Implementation is advised to take advantage of this and o...
Definition TSamplingFilm.ipp:55
SamplingFilmDimensions getDimensions() const
Definition TSamplingFilm.ipp:91
A 2-D Axis-Aligned Bounding Box (AABB).
Definition TAABB2D.h:26
Represents a 2-D vector.
Definition TVector2.h:19
TVector2< float64 > Vector2D
Definition math_fwd.h:47
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition SamplingFilmDimensions.h:12