Loading...
Searching...
No Matches
cosine_weighted_l2.h
Go to the documentation of this file.
1#ifndef _BBM_COSINEWEIGHTEDL2_H_
2#define _BBM_COSINEWEIGHTEDL2_H_
3
4#include "core/spherical.h"
7
8/************************************************************************/
9/*! \file cosine_weighted_l2.h
10
11 A cosine weighted L2 loss functions
12*************************************************************************/
13
14namespace bbm {
15
16 /*********************************************************************/
17 /*! \brief Standard cosine weighted l2 error
18
19 A cosine weighted l2 error for an (in,out) BSDF sample. Each sample is
20 weighted by sin(theta_in) * sin(theta_out)
21
22 Implements: concepts::samplelossfunction
23 ***********************************************************************/
24 template<typename CONF> requires concepts::config<CONF>
26 {
28
29 inline Value operator()(const Vec3d& in, const Vec3d& out, const Spectrum& value, const Spectrum& reference) const
30 {
31 return bbm::hsum(bbm::pow( (value - reference) * bbm::max( spherical::cosTheta(in), 0 ), 2.0))
33 }
34 };
35
37
38 /**********************************************************************/
39 /*! \brief nganL2 loss function
40
41 \tparam BSDF = bsdf to optimize
42 \tparam REFERENCE = bsdf to match
43 \tparam COMPONENT = which bsdf component to optimize
44 \tparam UNIT = unit over which to optimize
45
46 nganL2 is a sampled loss function that computes the loss over two BSDFs
47 using the nganL2_error and a spherical sampling of in and out directions
48 (spherical_linearizer).
49
50 Implements: concepts::sampledlossfunction
51 **********************************************************************/
52 template<typename BSDF, typename REFERENCE, bsdf_flag COMPONENT=bsdf_flag::All, unit_t UNIT=unit_t::Radiance>
56 struct nganL2 : public sampledlossfunction<BSDF, REFERENCE, nganL2_error<get_config<BSDF>>, spherical_linearizer<get_config<BSDF>>, COMPONENT, UNIT>
57 {
59
60 /********************************************************************/
61 /*! \brief Constructor
62
63 \param bsdf = bsdf to optimize
64 \param reference = bsdf to match
65 \param samplesIn = number of (phi, theta) samples for the 'in' direction
66 \param samplesOut = number of (phi, theta) samples for the 'out' direction
67 \param startIn = (phi,theta) angles to start sampling the 'in' direction (default: (0,0))
68 \param endIn = (phi,theta) angles to end sampling the 'in' direction (defailt: Hemisphere)
69 \param startOut = (phi,theta) angles to start sampling the 'out' direction (default: (0,0))
70 \param endOut = (phi,theta) angles to end sampling the 'out' direction (default: Hemisphere)
71 *********************************************************************/
72 inline nganL2(const BSDF& bsdf, const REFERENCE& reference,
73 const vec2d<Size_t>& samplesIn,
74 const vec2d<Size_t>& samplesOut,
75 const Vec2d& startIn=0, const Vec2d& endIn=Constants::Hemisphere(),
76 const Vec2d& startOut=0, const Vec2d& endOut=Constants::Hemisphere())
77 : sampledlossfunction<BSDF, REFERENCE, nganL2_error<Config>, spherical_linearizer<Config>, COMPONENT, UNIT>(bsdf, reference, nganL2_error<Config>(), spherical_linearizer<Config>(samplesIn, samplesOut, startIn, endIn, startOut, endOut)) {}
78 };
79
80
81 /**********************************************************************/
82
83
84 /**********************************************************************/
85 /*! \brief Low et al. cosine weighted l2 error
86
87 Low et al. "BRDF models for accurate and efficient rendering of glossy
88 surfaces": https://doi.org/10.1145/2077341.2077350
89
90 A cosine weighted l2 error on (in,out) BSDF sample. Each sample is
91 weighted by sin(theta_in)
92
93 Implements: concepts::samplelossfunction
94 ***********************************************************************/
95 template<typename CONF> requires concepts::config<CONF>
97 {
99
100 inline Value operator()(const Vec3d& in, const Vec3d& /*out*/, const Spectrum& value, const Spectrum& reference) const
101 {
102 return bbm::hsum(bbm::pow( (value - reference) * bbm::max( spherical::cosTheta(in), 0 ), 2.0 ))
104 }
105 };
106
108
109 /**********************************************************************/
110 /*! \brief lowL2 loss function
111
112 \tparam BSDF = bsdf to optimize
113 \tparam REFERENCE = bsdf to match
114 \tparam COMPONENT = which bsdf component to optimize
115 \tparam UNIT = unit over which to optimize
116
117 lowL2 is a sampled loss function that computes the loss over two BSDFs
118 using the lowL2_error and a spherical sampling of in and out directions
119 (spherical_linearizer). Note: *phi_out* is *not* sampled.
120
121 Implements: concepts::sampledlossfunction
122 **********************************************************************/
123 template<typename BSDF, typename REFERENCE, bsdf_flag COMPONENT=bsdf_flag::All, unit_t UNIT=unit_t::Radiance>
127 struct lowL2 : public sampledlossfunction<BSDF, REFERENCE, lowL2_error<get_config<BSDF>>, spherical_linearizer<get_config<BSDF>>, COMPONENT, UNIT>
128 {
130
131 /********************************************************************/
132 /*! \brief Constructor
133
134 \param bsdf = bsdf to optimize
135 \param reference = bsdf to match
136 \param samplesIn = number of (phi, theta) samples for the 'in' direction
137 \param samplesOut = number of *theta* samples for the 'out' direction
138 \param startIn = (phi,theta) angles to start sampling the 'in' direction (default: (0,0))
139 \param endIn = (phi,theta) angles to end sampling the 'in' direction (defailt: Hemisphere)
140 \param startOut = *theta* angle to start sampling the 'out' direction (default: 0)
141 \param endOut = *theta* angle to end sampling the 'out' direction (default: Pi(0.5))
142 *********************************************************************/
143 inline lowL2(const BSDF& bsdf, const REFERENCE& reference,
144 const vec2d<Size_t>& samplesIn,
145 const Size_t& samplesOut,
146 const Vec2d& startIn=0, const Vec2d& endIn=Constants::Hemisphere(),
147 const Scalar& startOut=0, const Scalar& endOut=Constants::Pi(0.5))
148 : sampledlossfunction<BSDF, REFERENCE, lowL2_error<Config>, spherical_linearizer<Config>, COMPONENT, UNIT>(bsdf, reference, lowL2_error<Config>(), spherical_linearizer<Config>(samplesIn, vec2d<Size_t>(1, samplesOut), startIn, endIn, startOut, Vec2d(Constants::Pi(2.0), endOut))) {}
149 };
150
151
152 /**********************************************************************/
153
154
155 /**********************************************************************/
156 /*! \brief Bieron and Peers cosine weighted l2 error
157
158 Bieron and Peers "An Adaptive BRDF Fitting Metric": https://doi.org/10.1111/cgf.14054
159
160 A cosine weighted l2 error on an (in,out) BSDF sample. Each sample is
161 weighted by sin(theta_in) * sin(theta_out) * cos(theta_out)
162
163 Implements: concepts::samplelossfunction
164 ***********************************************************************/
165 template<typename CONF> requires concepts::config<CONF>
167 {
169
170 inline Value operator()(const Vec3d& in, const Vec3d& out, const Spectrum& value, const Spectrum& reference) const
171 {
172 return bbm::hsum(bbm::pow( (value - reference) * bbm::max( spherical::cosTheta(in), 0 ), 2.0))
173 * bbm::max( spherical::cosTheta(out), 0 )
175 }
176 };
177
179
180 /*********************************************************************/
181 /*! \brief bieronL2 loss function
182
183 \tparam BSDF = bsdf to optimize
184 \tparam REFERENCE = bsdf to match
185 \tparam COMPONENT = which bsdf component to optimize
186 \tparam UNIT = unit over which to optimize
187
188 bieronL2 is a sampled loss function that computes the loss over two BSDFs
189 using the bieronL2_error and a spherical sampling of in and out directions
190 (spherical_linearizer).
191
192 Implements: concepts::sampledlossfunction
193 *********************************************************************/
194 template<typename BSDF, typename REFERENCE, bsdf_flag COMPONENT=bsdf_flag::All, unit_t UNIT=unit_t::Radiance>
198 struct bieronL2 : public sampledlossfunction<BSDF, REFERENCE, bieronL2_error<get_config<BSDF>>, spherical_linearizer<get_config<BSDF>>, COMPONENT, UNIT>
199 {
201
202 /********************************************************************/
203 /*! \brief Constructor
204
205 \param bsdf = bsdf to optimize
206 \param reference = bsdf to match
207 \param samplesIn = number of (phi, theta) samples for the 'in' direction
208 \param samplesOut = number of (phi, theta) samples for the 'out' direction
209 \param startIn = (phi,theta) angles to start sampling the 'in' direction (default: (0,0))
210 \param endIn = (phi,theta) angles to end sampling the 'in' direction (defailt: Hemisphere)
211 \param startOut = (phi,theta) angles to start sampling the 'out' direction (default: (0,0))
212 \param endOut = (phi,theta) angles to end sampling the 'out' direction (default: Hemisphere)
213 *********************************************************************/
214 inline bieronL2(const BSDF& bsdf, const REFERENCE& reference,
215 const vec2d<Size_t>& samplesIn,
216 const vec2d<Size_t>& samplesOut,
217 const Vec2d& startIn=0, const Vec2d& endIn=Constants::Hemisphere(),
218 const Vec2d& startOut=0, const Vec2d& endOut=Constants::Hemisphere())
219 : sampledlossfunction<BSDF, REFERENCE, bieronL2_error<Config>, spherical_linearizer<Config>, COMPONENT, UNIT>(bsdf, reference, bieronL2_error<Config>(), spherical_linearizer<Config>(samplesIn, samplesOut, startIn, endIn, startOut, endOut)) {}
220 };
221
222
223} // end bbm namespace
224
225#endif /* _BBM_COSINEWEIGHTEDL2_H_ */
Definition of a loss function that is the sum of losses on samples.
BSDF implementation of a BSDF model.
Definition: bsdf.h:30
bsdfmodel concept
Definition: bsdfmodel.h:33
matching_config concept
Definition: config.h:63
Definition: samplelossfunction.h:28
#define BBM_CHECK_CONCEPT(CONCEPTNAME, CLASSNAME,...)
Check a class for a concept with bbm::concepts::archetypes in the namespace.
Definition: macro.h:35
T sinTheta(const vec2d< T > &v)
Definition: spherical.h:75
T cosTheta(const vec2d< T > &v)
Definition: spherical.h:109
Definition: aggregatebsdf.h:29
decltype(auto) value(T &&t)
return the value of an attribute, or if not an attribute the object
Definition: attribute_value.h:20
Methods for handling spherical coordinates.
Bieron and Peers cosine weighted l2 error.
Definition: cosine_weighted_l2.h:167
Value operator()(const Vec3d &in, const Vec3d &out, const Spectrum &value, const Spectrum &reference) const
Definition: cosine_weighted_l2.h:170
bieronL2 loss function
Definition: cosine_weighted_l2.h:199
bieronL2(const BSDF &bsdf, const REFERENCE &reference, const vec2d< Size_t > &samplesIn, const vec2d< Size_t > &samplesOut, const Vec2d &startIn=0, const Vec2d &endIn=Constants::Hemisphere(), const Vec2d &startOut=0, const Vec2d &endOut=Constants::Hemisphere())
Constructor.
Definition: cosine_weighted_l2.h:214
BBM_IMPORT_CONFIG(BSDF)
Low et al. cosine weighted l2 error.
Definition: cosine_weighted_l2.h:97
Value operator()(const Vec3d &in, const Vec3d &, const Spectrum &value, const Spectrum &reference) const
Definition: cosine_weighted_l2.h:100
lowL2 loss function
Definition: cosine_weighted_l2.h:128
lowL2(const BSDF &bsdf, const REFERENCE &reference, const vec2d< Size_t > &samplesIn, const Size_t &samplesOut, const Vec2d &startIn=0, const Vec2d &endIn=Constants::Hemisphere(), const Scalar &startOut=0, const Scalar &endOut=Constants::Pi(0.5))
Constructor.
Definition: cosine_weighted_l2.h:143
BBM_IMPORT_CONFIG(BSDF)
Standard cosine weighted l2 error.
Definition: cosine_weighted_l2.h:26
Value operator()(const Vec3d &in, const Vec3d &out, const Spectrum &value, const Spectrum &reference) const
Definition: cosine_weighted_l2.h:29
nganL2 loss function
Definition: cosine_weighted_l2.h:57
BBM_IMPORT_CONFIG(BSDF)
nganL2(const BSDF &bsdf, const REFERENCE &reference, const vec2d< Size_t > &samplesIn, const vec2d< Size_t > &samplesOut, const Vec2d &startIn=0, const Vec2d &endIn=Constants::Hemisphere(), const Vec2d &startOut=0, const Vec2d &endOut=Constants::Hemisphere())
Constructor.
Definition: cosine_weighted_l2.h:72
Non-persistent reference (i.e., cannot take rvalues)
Definition: reference.h:86
sampledlossfunction
Definition: sampledlossfunction.h:35
Definition: spherical_linearizer.h:26