Loading...
Searching...
No Matches
cosine_weighted_log.h
Go to the documentation of this file.
1#ifndef _BBM_COSINEWEIGHTEDLOG_H_
2#define _BBM_COSINEWEIGHTEDLOG_H_
3
4#include "core/spherical.h"
7
8/************************************************************************/
9/*! \file cosine_weighted_log.h
10
11 \brief The Low et al.'s cosine weighted log BRDF fitting metric from "BRDF
12 models for accurate and efficient rendering of glossy surfaces" [Low 2012]:
13 https://doi.org/10.1145/2077341.2077350
14
15*************************************************************************/
16
17namespace bbm {
18
19 /**********************************************************************/
20 /*! \brief Low et al.'s cosine weighted log error
21
22 Low et al. "BRDF models for accurate and efficient rendering of glossy
23 surfaces": https://doi.org/10.1145/2077341.2077350
24
25 A cosine weighted log error on (in,out) BSDF sample. Each sample is
26 weighted by sin(theta_in)
27
28
29 Implements: concepts::samplelossfunction
30 **********************************************************************/
31 template<typename CONF> requires concepts::config<CONF>
33 {
35
36 inline Value operator()(const Vec3d& in, const Vec3d& /*out*/, const Spectrum& value, const Spectrum& reference) const
37 {
38 auto cosTheta = bbm::max( spherical::cosTheta(in), 0 );
39 auto v = bbm::log(1 + value*cosTheta);
40 auto r = bbm::log(1 + reference*cosTheta);
41 return bbm::hsum( bbm::pow(v-r, 2.0) ) * spherical::sinTheta(in);
42 }
43 };
44
46
47 /**********************************************************************/
48 /*! \brief lowLog loss function
49
50 \tparam BSDF = bsdf to optimize
51 \tparam REFERENCE = bsdf to match
52 \tparam COMPONENT = which bsdf component to optimize
53 \tparam UNIT = unit over which to optimize
54
55 lowLog is a sampled loss function that computes the loss over two BSDFs
56 using the lowLog error and a spherical sampling of in and out directions
57 (spherical_linearizer). Note: *phi_out* is *not* sampled.
58
59 Implements: concepts::sampledlossfunction
60 ***********************************************************************/
61 template<typename BSDF, typename REFERENCE, bsdf_flag COMPONENT=bsdf_flag::All, unit_t UNIT=unit_t::Radiance>
65 struct lowLog : public sampledlossfunction<BSDF, REFERENCE, lowLog_error<get_config<BSDF>>, spherical_linearizer<get_config<BSDF>>, COMPONENT, UNIT>
66 {
68
69 /********************************************************************/
70 /*! \brief Constructor
71
72 \param bsdf = bsdf to optimize
73 \param reference = bsdf to match
74 \param samplesIn = number of (phi, theta) samples for the 'in' direction
75 \param samplesOut = number of *theta* samples for the 'out' direction
76 \param startIn = (phi,theta) angles to start sampling the 'in' direction (default: (0,0))
77 \param endIn = (phi,theta) angles to end sampling the 'in' direction (defailt: Hemisphere)
78 \param startOut = *theta* angle to start sampling the 'out' direction (default: 0)
79 \param endOut = *theta* angle to end sampling the 'out' direction (default: Pi(0.5))
80 *********************************************************************/
81 inline lowLog(const BSDF& bsdf, const REFERENCE& reference,
82 const vec2d<Size_t>& samplesIn,
83 const Size_t& samplesOut,
84 const Vec2d& startIn=0, const Vec2d& endIn=Constants::Hemisphere(),
85 const Scalar& startOut=0, const Scalar& endOut=Constants::Pi(0.5))
86 : sampledlossfunction<BSDF, REFERENCE, lowLog_error<Config>, spherical_linearizer<Config>, COMPONENT, UNIT>(bsdf, reference, lowLog_error<Config>(), spherical_linearizer<Config>(samplesIn, vec2d<Size_t>(1, samplesOut), startIn, endIn, startOut, Vec2d(Constants::Pi(2.0), endOut))) {}
87 };
88
89
90 /**********************************************************************/
91 /*! \brief Bieron and Peers cosine weighted log error
92
93 Bieron and Peers "An Adaptive BRDF Fitting Metric": https://doi.org/10.1111/cgf.14054
94
95 A cosine weighted log error on an (in,out) BSDF sample. Each sample is
96 weighted by sin(theta_in) * sin(theta_out) * cos(theta_out)
97
98 Implements: concepts::samplelossfunction
99 ***********************************************************************/
100 template<typename CONF> requires concepts::config<CONF>
102 {
104
105 inline Value operator()(const Vec3d& in, const Vec3d& out, const Spectrum& value, const Spectrum& reference) const
106 {
107 auto cosTheta = bbm::max( spherical::cosTheta(in), 0 );
108 auto v = bbm::log(1 + value*cosTheta);
109 auto r = bbm::log(1 + reference*cosTheta);
110 return bbm::hsum( bbm::pow(v-r, 2.0) ) * bbm::max( spherical::cosTheta(out), 0 ) * spherical::sinTheta(in) * spherical::sinTheta(out);
111 }
112 };
113
115
116 /*********************************************************************/
117 /*! \brief bieronLog loss function
118
119 \tparam BSDF = bsdf to optimize
120 \tparam REFERENCE = bsdf to match
121 \tparam COMPONENT = which bsdf component to optimize
122 \tparam UNIT = unit over which to optimize
123
124 bieronLog is a sampled loss function that computes the loss over two BSDFs
125 using the bieronLog_error and a spherical sampling of in and out directions
126 (spherical_linearizer).
127
128 Implements: concepts::sampledlossfunction
129 *********************************************************************/
130 template<typename BSDF, typename REFERENCE, bsdf_flag COMPONENT=bsdf_flag::All, unit_t UNIT=unit_t::Radiance>
134 struct bieronLog : public sampledlossfunction<BSDF, REFERENCE, bieronLog_error<get_config<BSDF>>, spherical_linearizer<get_config<BSDF>>, COMPONENT, UNIT>
135 {
137
138 /********************************************************************/
139 /*! \brief Constructor
140
141 \param bsdf = bsdf to optimize
142 \param reference = bsdf to match
143 \param samplesIn = number of (phi, theta) samples for the 'in' direction
144 \param samplesOut = number of (phi, theta) samples for the 'out' direction
145 \param startIn = (phi,theta) angles to start sampling the 'in' direction (default: (0,0))
146 \param endIn = (phi,theta) angles to end sampling the 'in' direction (defailt: Hemisphere)
147 \param startOut = (phi,theta) angles to start sampling the 'out' direction (default: (0,0))
148 \param endOut = (phi,theta) angles to end sampling the 'out' direction (default: Hemisphere)
149 *********************************************************************/
150 inline bieronLog(const BSDF& bsdf, const REFERENCE& reference,
151 const vec2d<Size_t>& samplesIn,
152 const vec2d<Size_t>& samplesOut,
153 const Vec2d& startIn=0, const Vec2d& endIn=Constants::Hemisphere(),
154 const Vec2d& startOut=0, const Vec2d& endOut=Constants::Hemisphere())
155 : sampledlossfunction<BSDF, REFERENCE, bieronLog_error<Config>, spherical_linearizer<Config>, COMPONENT, UNIT>(bsdf, reference, bieronLog_error<Config>(), spherical_linearizer<Config>(samplesIn, samplesOut, startIn, endIn, startOut, endOut)) {}
156 };
157
158
159 /*********************************************************************/
160 /*! \brief Cosine weighted log error weighted by sin theta of in and out.
161
162 A cosine weighted log error for an (in,out) BSDF sample. Each sample is
163 weighted by sin(theta_in) * sin(theta_out). While this error is the
164 re-interpretation of Low et al.'s log error with 'standard' sin theta
165 in.out weighting of the error.
166
167 Implements: concepts::samplelossfunction
168 ***********************************************************************/
169 template<typename CONF> requires concepts::config<CONF>
171 {
173
174 inline Value operator()(const Vec3d& in, const Vec3d& out, const Spectrum& value, const Spectrum& reference) const
175 {
176 auto cosTheta = bbm::max( spherical::cosTheta(in), 0 );
177 auto v = bbm::log(1 + value*cosTheta);
178 auto r = bbm::log(1 + reference*cosTheta);
179 return bbm::hsum( bbm::pow(v-r, 2.0) ) * spherical::sinTheta(in) * spherical::sinTheta(out);
180 }
181 };
182
184
185 /**********************************************************************/
186 /*! \brief standardLog loss function
187
188 \tparam BSDF = bsdf to optimize
189 \tparam REFERENCE = bsdf to match
190 \tparam COMPONENT = which bsdf component to optimize
191 \tparam UNIT = unit over which to optimize
192
193 standardLog is a sampled loss function that computes the loss over two BSDFs
194 using the standardLog_error and a spherical sampling of in and out directions
195 (spherical_linearizer).
196
197 Implements: concepts::sampledlossfunction
198 **********************************************************************/
199 template<typename BSDF, typename REFERENCE, bsdf_flag COMPONENT=bsdf_flag::All, unit_t UNIT=unit_t::Radiance>
203 struct standardLog : public sampledlossfunction<BSDF, REFERENCE, standardLog_error<get_config<BSDF>>, spherical_linearizer<get_config<BSDF>>, COMPONENT, UNIT>
204 {
206
207 /********************************************************************/
208 /*! \brief Constructor
209
210 \param bsdf = bsdf to optimize
211 \param reference = bsdf to match
212 \param samplesIn = number of (phi, theta) samples for the 'in' direction
213 \param samplesOut = number of (phi, theta) samples for the 'out' direction
214 \param startIn = (phi,theta) angles to start sampling the 'in' direction (default: (0,0))
215 \param endIn = (phi,theta) angles to end sampling the 'in' direction (defailt: Hemisphere)
216 \param startOut = (phi,theta) angles to start sampling the 'out' direction (default: (0,0))
217 \param endOut = (phi,theta) angles to end sampling the 'out' direction (default: Hemisphere)
218 *********************************************************************/
219 inline standardLog(const BSDF& bsdf, const REFERENCE& reference,
220 const vec2d<Size_t>& samplesIn,
221 const vec2d<Size_t>& samplesOut,
222 const Vec2d& startIn=0, const Vec2d& endIn=Constants::Hemisphere(),
223 const Vec2d& startOut=0, const Vec2d& endOut=Constants::Hemisphere())
224 : sampledlossfunction<BSDF, REFERENCE, standardLog_error<Config>, spherical_linearizer<Config>, COMPONENT, UNIT>(bsdf, reference, standardLog_error<Config>(), spherical_linearizer<Config>(samplesIn, samplesOut, startIn, endIn, startOut, endOut)) {}
225 };
226
227} // end bbm namespace
228
229#endif /* _BBM_COSINEWEIGHTEDLOG_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 log error.
Definition: cosine_weighted_log.h:102
Value operator()(const Vec3d &in, const Vec3d &out, const Spectrum &value, const Spectrum &reference) const
Definition: cosine_weighted_log.h:105
bieronLog loss function
Definition: cosine_weighted_log.h:135
bieronLog(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_log.h:150
BBM_IMPORT_CONFIG(BSDF)
Low et al.'s cosine weighted log error.
Definition: cosine_weighted_log.h:33
Value operator()(const Vec3d &in, const Vec3d &, const Spectrum &value, const Spectrum &reference) const
Definition: cosine_weighted_log.h:36
lowLog loss function
Definition: cosine_weighted_log.h:66
lowLog(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_log.h:81
BBM_IMPORT_CONFIG(BSDF)
Non-persistent reference (i.e., cannot take rvalues)
Definition: reference.h:86
sampledlossfunction
Definition: sampledlossfunction.h:35
Definition: spherical_linearizer.h:26
Cosine weighted log error weighted by sin theta of in and out.
Definition: cosine_weighted_log.h:171
Value operator()(const Vec3d &in, const Vec3d &out, const Spectrum &value, const Spectrum &reference) const
Definition: cosine_weighted_log.h:174
standardLog loss function
Definition: cosine_weighted_log.h:204
standardLog(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_log.h:219