tinypbrt 1.1.1
pbrt-v4 scene file parser for C11 with a header-only C++20 wrapper
Loading...
Searching...
No Matches
light.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _TINYPBRT_LIGHT_HPP_
3#define _TINYPBRT_LIGHT_HPP_
4
6
8
9#include <string_view>
10#include <tuple>
11
18
19namespace tpbrt {
45
52 [[nodiscard]] constexpr std::string_view to_string(const light_source_type type) noexcept {
53 using enum light_source_type;
54 switch (type) {
55 case DISTANT: return "distant";
56 case GONIOMETRIC: return "goniometric";
57 case INFINITE: return "infinite";
58 case POINT: return "point";
59 case PROJECTION: return "projection";
60 case SPOT: return "spot";
61 case MAX_NUM: return "maxnum";
62 default: return "UNKNOWN";
63 }
64 }
65
70 struct light_source_distant_params : detail::wrapper<light_source_distant_params, tpbrt_light_source_distant_params_t> {
72 using wrapper::wrapper;
73
75 [[nodiscard]] constexpr spectrum l() const noexcept { return _native->l; }
76
78 [[nodiscard]] constexpr point from() const noexcept { return _native->from; }
79
81 [[nodiscard]] constexpr point to() const noexcept { return _native->to; }
82
84 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(l(), from(), to()); }
85 };
86
92 : detail::wrapper<light_source_goniometric_params, tpbrt_light_source_goniometric_params_t> {
94 using wrapper::wrapper;
95
97 [[nodiscard]] constexpr string file_name() const noexcept { return _native->file_name; }
98
100 [[nodiscard]] constexpr spectrum i() const noexcept { return _native->i; }
101
103 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(file_name(), i()); }
104 };
105
110 struct light_source_infinite_params : detail::wrapper<light_source_infinite_params, tpbrt_light_source_infinite_params_t> {
113
115 using wrapper::wrapper;
116
118 [[nodiscard]] constexpr string file_name() const noexcept { return _native->file_name; }
119
121 [[nodiscard]] constexpr portal_type portal() const noexcept { return _native->portal; }
122
124 [[nodiscard]] constexpr spectrum l() const noexcept { return _native->l; }
125
127 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(file_name(), portal(), l()); }
128 };
129
134 struct light_source_point_params : detail::wrapper<light_source_point_params, tpbrt_light_source_point_params_t> {
136 using wrapper::wrapper;
137
139 [[nodiscard]] constexpr spectrum i() const noexcept { return _native->i; }
140
142 [[nodiscard]] constexpr point from() const noexcept { return _native->from; }
143
145 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(i(), from()); }
146 };
147
153 : detail::wrapper<light_source_projection_params, tpbrt_light_source_projection_params_t> {
155 using wrapper::wrapper;
156
158 [[nodiscard]] constexpr spectrum i() const noexcept { return _native->i; }
159
161 [[nodiscard]] constexpr string file_name() const noexcept { return _native->file_name; }
162
164 [[nodiscard]] constexpr float_t fov() const noexcept { return _native->fov; }
165
167 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(i(), file_name(), fov()); }
168 };
169
174 struct light_source_spot_params : detail::wrapper<light_source_spot_params, tpbrt_light_source_spot_params_t> {
176 using wrapper::wrapper;
177
179 [[nodiscard]] constexpr spectrum i() const noexcept { return _native->i; }
180
182 [[nodiscard]] constexpr point from() const noexcept { return _native->from; }
183
185 [[nodiscard]] constexpr point to() const noexcept { return _native->to; }
186
188 [[nodiscard]] constexpr float_t cone_angle() const noexcept { return _native->cone_angle; }
189
191 [[nodiscard]] constexpr float_t cone_delta_angle() const noexcept { return _native->cone_delta_angle; }
192
194 [[nodiscard]] constexpr auto reflect() const noexcept {
195 return std::make_tuple(i(), from(), to(), cone_angle(), cone_delta_angle());
196 }
197 };
198
204 : detail::wrapper<light_source, tpbrt_light_source_t>,
205 detail::with_variant<light_source, light_source_distant_params, light_source_goniometric_params,
206 light_source_infinite_params, light_source_point_params, light_source_projection_params, light_source_spot_params> {
208 using wrapper::wrapper;
209
211 [[nodiscard]] constexpr transform_handle transform() const noexcept { return _native->transform; }
212
214 [[nodiscard]] constexpr float_t scale() const noexcept { return _native->scale; }
215
217 [[nodiscard]] constexpr opt_float power_illuminance() const noexcept { return _native->power_illuminance; }
218
220 [[nodiscard]] constexpr media_handle interior_media_handle() const noexcept { return _native->interior_media_handle; }
221
223 [[nodiscard]] constexpr media_handle exterior_media_handle() const noexcept { return _native->exterior_media_handle; }
224
226 [[nodiscard]] constexpr light_source_type type() const noexcept { return static_cast<light_source_type>(_native->type); }
227
229 [[nodiscard]] constexpr bool_t is_distant() const noexcept { return type() == light_source_type::DISTANT; }
230
232 [[nodiscard]] constexpr bool_t is_goniometric() const noexcept { return type() == light_source_type::GONIOMETRIC; }
233
235 [[nodiscard]] constexpr bool_t is_infinite() const noexcept { return type() == light_source_type::INFINITE; }
236
238 [[nodiscard]] constexpr bool_t is_point() const noexcept { return type() == light_source_type::POINT; }
239
241 [[nodiscard]] constexpr bool_t is_projection() const noexcept { return type() == light_source_type::PROJECTION; }
242
244 [[nodiscard]] constexpr bool_t is_spot() const noexcept { return type() == light_source_type::SPOT; }
245
247 [[nodiscard]] constexpr std::optional<light_source_distant_params> as_distant() const noexcept {
248 if (!is_distant()) { return std::nullopt; }
249 return _native->as.distant;
250 }
251
253 [[nodiscard]] constexpr std::optional<light_source_goniometric_params> as_goniometric() const noexcept {
254 if (!is_goniometric()) { return std::nullopt; }
255 return _native->as.goniometric;
256 }
257
259 [[nodiscard]] constexpr std::optional<light_source_infinite_params> as_infinite() const noexcept {
260 if (!is_infinite()) { return std::nullopt; }
261 return _native->as.infinite;
262 }
263
265 [[nodiscard]] constexpr std::optional<light_source_point_params> as_point() const noexcept {
266 if (!is_point()) { return std::nullopt; }
267 return _native->as.point;
268 }
269
271 [[nodiscard]] constexpr std::optional<light_source_projection_params> as_projection() const noexcept {
272 if (!is_projection()) { return std::nullopt; }
273 return _native->as.projection;
274 }
275
277 [[nodiscard]] constexpr std::optional<light_source_spot_params> as_spot() const noexcept {
278 if (!is_spot()) { return std::nullopt; }
279 return _native->as.spot;
280 }
281
283 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
284 using enum light_source_type;
285 switch (type()) {
286 case DISTANT: return _native->as.distant;
287 case GONIOMETRIC: return _native->as.goniometric;
288 case INFINITE: return _native->as.infinite;
289 case POINT: return _native->as.point;
290 case PROJECTION: return _native->as.projection;
291 case SPOT: return _native->as.spot;
292 case MAX_NUM: [[fallthrough]];
293 default: break;
294 }
295 return std::nullopt;
296 }
297
299 [[nodiscard]] constexpr auto reflect() const noexcept {
301 to_variant(), type());
302 }
303 };
304
315
322 [[nodiscard]] constexpr std::string_view to_string(const area_light_type type) noexcept {
323 using enum area_light_type;
324 switch (type) {
325 case DIFFUSE: return "diffuse";
326 case MAX_NUM: return "maxnum";
327 default: return "UNKNOWN";
328 }
329 }
330
335 struct area_light_diffuse_params : detail::wrapper<area_light_diffuse_params, tpbrt_area_light_diffuse_params_t> {
337 using wrapper::wrapper;
338
340 [[nodiscard]] constexpr string file_name() const noexcept { return _native->file_name; }
341
343 [[nodiscard]] constexpr spectrum l() const noexcept { return _native->l; }
344
346 [[nodiscard]] constexpr bool_t two_sided() const noexcept { return _native->two_sided; }
347
349 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(file_name(), l(), two_sided()); }
350 };
351
356 struct area_light : detail::wrapper<area_light, tpbrt_area_light_t>,
357 detail::with_variant<area_light, area_light_diffuse_params> {
359 using wrapper::wrapper;
360
362 [[nodiscard]] constexpr area_light_idx_t idx() const noexcept { return _native->idx; }
363
365 [[nodiscard]] constexpr float_t scale() const noexcept { return _native->scale; }
366
368 [[nodiscard]] constexpr opt_float power() const noexcept { return _native->power; }
369
371 [[nodiscard]] constexpr area_light_type type() const noexcept { return static_cast<area_light_type>(_native->type); }
372
374 [[nodiscard]] constexpr bool_t is_diffuse() const noexcept { return type() == area_light_type::DIFFUSE; }
375
377 [[nodiscard]] constexpr std::optional<area_light_diffuse_params> as_diffuse() const noexcept {
378 if (!is_diffuse()) { return std::nullopt; }
379 return _native->as.diffuse;
380 }
381
383 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
384 using enum area_light_type;
385 switch (type()) {
386 case DIFFUSE: return _native->as.diffuse;
387 case MAX_NUM: [[fallthrough]];
388 default: break;
389 }
390 return std::nullopt;
391 }
392
394 [[nodiscard]] constexpr auto reflect() const noexcept {
395 return std::make_tuple(idx(), scale(), power(), to_variant(), type());
396 }
397 };
398
403 struct area_light_handle : detail::wrapper<area_light_handle, tpbrt_area_light_handle_t> {
405 using wrapper::wrapper;
406
408 [[nodiscard]] constexpr area_light_idx_t area_light_idx() const noexcept { return _native->area_light_idx; }
409
411 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(area_light_idx()); }
412 };
413
419
426 struct area_lights_list : array<tpbrt_area_lights_list_t, area_light, &tpbrt_area_lights_list_t::lights> {
428 using array::array;
429
431 using array::at;
432
434 using array::operator[];
435
437 [[nodiscard]] result<element_type> at(const area_light_handle handle) const noexcept {
438 return detail::find_in<element_type, tpbrt_area_light_t>(tpbrt_get_area_light_by_handle, _native, handle.native());
439 }
440
442 [[nodiscard]] result<element_type> operator[](const area_light_handle handle) const noexcept { return at(handle); }
443 };
444
452 [[nodiscard]] inline result<area_light> get_area_light(const area_lights_list list, const area_light_handle handle) noexcept {
453 return list.at(handle);
454 }
455
460 struct lights_list : detail::wrapper<lights_list, tpbrt_lights_list_t> {
462 using wrapper::wrapper;
463
465 [[nodiscard]] constexpr lights_sources_list lights_sources() const noexcept { return _native->lights_sources; }
466
468 [[nodiscard]] constexpr area_lights_list area_lights() const noexcept { return _native->area_lights; }
469
471 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(lights_sources(), area_lights()); }
472 };
473} // namespace tpbrt
474#endif // _TINYPBRT_LIGHT_HPP_
constexpr std::string_view to_string(const accelerator_type type) noexcept
Converts accelerator_type enum value to string.
Definition accelerator.hpp:39
@ MAX_NUM
Count of available accelerator types.
tpbrt_uchar_t uchar_t
Unsigned char type.
Definition fwd.hpp:34
area_light_type
Area light type.
Definition light.hpp:309
tpbrt_area_light_idx_t area_light_idx_t
Area light index type.
Definition fwd.hpp:358
light_source_type
Light source type.
Definition light.hpp:29
result< area_light > get_area_light(const area_lights_list list, const area_light_handle handle) noexcept
Returns area light to which handle is provided.
Definition light.hpp:452
@ DIFFUSE
Diffuse area light.
@ INFINITE
Infinite light source.
@ DISTANT
Distant (directional) light source.
@ SPOT
Spot light source.
@ POINT
Point light source.
@ GONIOMETRIC
Goniometric light source.
@ PROJECTION
Projection light source.
tpbrt_error_t tpbrt_get_area_light_by_handle(const tpbrt_area_lights_list_t *area_lights_list, tpbrt_area_light_handle_t handle, const tpbrt_area_light_t **area_light)
Returns pointer to area light to which handle is provided.
@ TPBRT_LIGHT_SOURCE_TYPE_INFINITE
Infinite light source.
Definition light.h:32
@ TPBRT_LIGHT_SOURCE_TYPE_DISTANT
Distant (directional) light source.
Definition light.h:28
@ TPBRT_LIGHT_SOURCE_TYPE_POINT
Point light source.
Definition light.h:34
@ TPBRT_LIGHT_SOURCE_TYPE_GONIOMETRIC
Goniometric light source.
Definition light.h:30
@ TPBRT_LIGHT_SOURCE_TYPE_SPOT
Spot light source.
Definition light.h:38
@ TPBRT_LIGHT_SOURCE_TYPE_PROJECTION
Projection light source.
Definition light.h:36
@ TPBRT_LIGHT_SOURCE_TYPE_MAX_NUM
Count of available light source types.
Definition light.h:40
@ TPBRT_AREA_LIGHT_TYPE_MAX_NUM
Count of available area light types.
Definition light.h:165
@ TPBRT_AREA_LIGHT_TYPE_DIFFUSE
Diffuse area light.
Definition light.h:163
bool bool_t
Bool type.
Definition fwd.hpp:82
tpbrt_float_t float_t
Float type.
Definition fwd.hpp:97
Definition accelerator.hpp:14
C++ wrapper for tpbrt_area_light_diffuse_params_t.
Definition light.hpp:335
constexpr bool_t two_sided() const noexcept
Returns two_sided value.
Definition light.hpp:346
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:349
constexpr spectrum l() const noexcept
Returns l value.
Definition light.hpp:343
constexpr string file_name() const noexcept
Returns file_name value.
Definition light.hpp:340
C++ wrapper for tpbrt_area_light_handle_t.
Definition light.hpp:403
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:411
constexpr area_light_idx_t area_light_idx() const noexcept
Returns area_light_idx value.
Definition light.hpp:408
C++ wrapper for tpbrt_area_light_t.
Definition light.hpp:357
constexpr bool_t is_diffuse() const noexcept
Returns true if type is diffuse.
Definition light.hpp:374
constexpr area_light_type type() const noexcept
Returns type value.
Definition light.hpp:371
constexpr opt_float power() const noexcept
Returns power value.
Definition light.hpp:368
constexpr float_t scale() const noexcept
Returns scale value.
Definition light.hpp:365
constexpr std::optional< area_light_diffuse_params > as_diffuse() const noexcept
Returns diffuse parameters (std::nullopt if the type is different).
Definition light.hpp:377
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:394
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition light.hpp:383
constexpr area_light_idx_t idx() const noexcept
Returns idx value.
Definition light.hpp:362
C++ wrapper for tpbrt_area_lights_list_t.
Definition light.hpp:426
result< element_type > at(const area_light_handle handle) const noexcept
Returns area light pointed by given handle.
Definition light.hpp:437
result< element_type > operator[](const area_light_handle handle) const noexcept
Returns element pointed by given handle.
Definition light.hpp:442
Generic C++ array view with type conversion (a non owning view on memory owned by the C library).
Definition common.hpp:448
constexpr result< element_type > at(const size_t index) const noexcept
Returns element on given index or error::INDEX_OUT_OF_RANGE.
Definition common.hpp:519
C++ wrapper for tpbrt_light_source_distant_params_t.
Definition light.hpp:70
constexpr point from() const noexcept
Returns p value.
Definition light.hpp:78
constexpr point to() const noexcept
Returns to value.
Definition light.hpp:81
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:84
constexpr spectrum l() const noexcept
Returns l value.
Definition light.hpp:75
C++ wrapper for tpbrt_light_source_goniometric_params_t.
Definition light.hpp:92
constexpr string file_name() const noexcept
Returns file_name value.
Definition light.hpp:97
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:103
constexpr spectrum i() const noexcept
Returns i value.
Definition light.hpp:100
C++ wrapper for tpbrt_light_source_infinite_params_t.
Definition light.hpp:110
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:127
constexpr portal_type portal() const noexcept
Returns portal value.
Definition light.hpp:121
constexpr string file_name() const noexcept
Returns file_name value.
Definition light.hpp:118
constexpr spectrum l() const noexcept
Returns l value.
Definition light.hpp:124
C++ wrapper for tpbrt_light_source_point_params_t.
Definition light.hpp:134
constexpr spectrum i() const noexcept
Returns i value.
Definition light.hpp:139
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:145
constexpr point from() const noexcept
Returns from value.
Definition light.hpp:142
C++ wrapper for tpbrt_light_source_projection_params_t.
Definition light.hpp:153
constexpr float_t fov() const noexcept
Returns fov value.
Definition light.hpp:164
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:167
constexpr string file_name() const noexcept
Returns file_name value.
Definition light.hpp:161
constexpr spectrum i() const noexcept
Returns i value.
Definition light.hpp:158
C++ wrapper for tpbrt_light_source_spot_params_t.
Definition light.hpp:174
constexpr spectrum i() const noexcept
Returns i value.
Definition light.hpp:179
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:194
constexpr float_t cone_delta_angle() const noexcept
Returns cone_delta_angle value.
Definition light.hpp:191
constexpr point to() const noexcept
Returns to value.
Definition light.hpp:185
constexpr float_t cone_angle() const noexcept
Returns cone_angle value.
Definition light.hpp:188
constexpr point from() const noexcept
Returns from value.
Definition light.hpp:182
C++ wrapper for tpbrt_light_source_t.
Definition light.hpp:206
constexpr bool_t is_infinite() const noexcept
Returns true if type is infinite.
Definition light.hpp:235
constexpr bool_t is_distant() const noexcept
Returns true if type is distant.
Definition light.hpp:229
constexpr std::optional< light_source_goniometric_params > as_goniometric() const noexcept
Returns light parameters as goniometric.
Definition light.hpp:253
constexpr transform_handle transform() const noexcept
Returns transform value.
Definition light.hpp:211
constexpr bool_t is_projection() const noexcept
Returns true if type is projection.
Definition light.hpp:241
constexpr float_t scale() const noexcept
Returns scale value.
Definition light.hpp:214
constexpr std::optional< light_source_infinite_params > as_infinite() const noexcept
Returns light parameters as infinite.
Definition light.hpp:259
constexpr media_handle exterior_media_handle() const noexcept
Returns exterior_media_handle value.
Definition light.hpp:223
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:299
constexpr bool_t is_goniometric() const noexcept
Returns true if type is goniometric.
Definition light.hpp:232
constexpr opt_float power_illuminance() const noexcept
Returns power_illuminance value.
Definition light.hpp:217
constexpr std::optional< light_source_spot_params > as_spot() const noexcept
Returns light parameters as spot.
Definition light.hpp:277
constexpr std::optional< light_source_projection_params > as_projection() const noexcept
Returns light parameters as projection.
Definition light.hpp:271
constexpr bool_t is_point() const noexcept
Returns true if type is point.
Definition light.hpp:238
constexpr media_handle interior_media_handle() const noexcept
Returns interior_media_handle value.
Definition light.hpp:220
constexpr light_source_type type() const noexcept
Returns type value.
Definition light.hpp:226
constexpr bool_t is_spot() const noexcept
Returns true if type is spot.
Definition light.hpp:244
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition light.hpp:283
constexpr std::optional< light_source_distant_params > as_distant() const noexcept
Returns light parameters as distant.
Definition light.hpp:247
constexpr std::optional< light_source_point_params > as_point() const noexcept
Returns light parameters as point.
Definition light.hpp:265
C++ wrapper for tpbrt_lights_list_t.
Definition light.hpp:460
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition light.hpp:471
constexpr area_lights_list area_lights() const noexcept
Returns area_lights value.
Definition light.hpp:468
constexpr lights_sources_list lights_sources() const noexcept
Returns lights_sources value.
Definition light.hpp:465
C++ wrapper for tpbrt_media_handle_t.
Definition media.hpp:458
C++ wrapper for tpbrt_opt_float_t.
Definition math.hpp:24
Result of an operation: either a value or an error code (similar to C++23 std::expected).
Definition error.hpp:165
C++ wrapper for tpbrt_spectrum_t.
Definition color.hpp:270
C++ wrapper for tpbrt_transform_handle_t.
Definition transform.hpp:24
C++ wrapper for tpbrt_vec3_t.
Definition math.hpp:132