tinypbrt 1.1.1
pbrt-v4 scene file parser for C11 with a header-only C++20 wrapper
Loading...
Searching...
No Matches
material.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _TINYPBRT_MATERIAL_HPP_
3#define _TINYPBRT_MATERIAL_HPP_
4
6
8
11
12namespace tpbrt {
50
57 [[nodiscard]] constexpr std::string_view to_string(const material_type type) noexcept {
58 using enum material_type;
59 switch (type) {
60 case COATED_DIFFUSE: return "coateddiffuse";
61 case COATED_CONDUCTOR: return "coatedconductor";
62 case CONDUCTOR: return "conductor";
63 case DIELECTRIC: return "dielectric";
64 case DIFFUSE: return "diffuse";
65 case DIFFUSE_TRANSMISSION: return "diffusetransmission";
66 case HAIR: return "hair";
67 case INTERFACE: return "interface";
68 case MEASURED: return "measured";
69 case MIX: return "mix";
70 case SUBSURFACE: return "subsurface";
71 case THIN_DIELECTRIC: return "thindielectric";
72 case MAX_NUM: return "maxnum";
73 default: return "UNKNOWN";
74 }
75 }
76
81 struct material_handle : detail::wrapper<material_handle, tpbrt_material_handle_t> {
83 using wrapper::wrapper;
84
86 [[nodiscard]] constexpr material_idx_t material_idx() const noexcept { return _native->material_idx; }
87
89 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(material_idx()); }
90 };
91
106
113 [[nodiscard]] constexpr std::string_view to_string(const material_bump_map_type type) noexcept {
114 using enum material_bump_map_type;
115 switch (type) {
116 case NONE: return "none";
117 case DISPLACEMENT: return "displacement";
118 case NORMAL_MAP: return "normalmap";
119 case MAX_NUM: return "maxnum";
120 default: return "UNKNOWN";
121 }
122 }
123
128 struct material_bump_map_params : detail::wrapper<material_bump_map_params, tpbrt_material_bump_map_params_t>,
129 detail::with_variant<material_bump_map_params, texture_handle, string> {
131 using wrapper::wrapper;
132
134 [[nodiscard]] constexpr material_bump_map_type type() const noexcept {
135 return static_cast<material_bump_map_type>(_native->type);
136 }
137
139 [[nodiscard]] constexpr bool_t is_displacement() const noexcept { return type() == material_bump_map_type::DISPLACEMENT; }
140
142 [[nodiscard]] constexpr bool_t is_normal_map() const noexcept { return type() == material_bump_map_type::NORMAL_MAP; }
143
145 [[nodiscard]] constexpr std::optional<texture_handle> as_displacement() const noexcept {
146 if (!is_displacement()) { return std::nullopt; }
147 return _native->as.displacement;
148 }
149
151 [[nodiscard]] constexpr std::optional<string> as_normal_map() const noexcept {
152 if (!is_normal_map()) { return std::nullopt; }
153 return _native->as.normal_map;
154 }
155
157 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
158 using enum material_bump_map_type;
159 switch (type()) {
160 case DISPLACEMENT: return _native->as.displacement;
161 case NORMAL_MAP: return _native->as.normal_map;
162 case MAX_NUM: [[fallthrough]];
163 default: break;
164 }
165 return std::nullopt;
166 }
167
169 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(to_variant(), type()); }
170 };
171
176 struct material_roughness_params : detail::wrapper<material_roughness_params, tpbrt_material_roughness_params_t> {
178 using wrapper::wrapper;
179
181 [[nodiscard]] constexpr texture_handle roughness() const noexcept { return _native->roughness; }
182
184 [[nodiscard]] constexpr texture_handle u_roughness() const noexcept { return _native->u_roughness; }
185
187 [[nodiscard]] constexpr texture_handle v_roughness() const noexcept { return _native->v_roughness; }
188
190 [[nodiscard]] constexpr bool_t remap_roughness() const noexcept { return _native->remap_roughness; }
191
193 [[nodiscard]] constexpr auto reflect() const noexcept {
194 return std::make_tuple(roughness(), u_roughness(), v_roughness(), remap_roughness());
195 }
196 };
197
203 : detail::wrapper<material_coated_diffuse_params, tpbrt_material_coated_diffuse_params_t> {
205 using wrapper::wrapper;
206
208 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
209
211 [[nodiscard]] constexpr texture_handle albedo() const noexcept { return _native->albedo; }
212
214 [[nodiscard]] constexpr texture_handle g() const noexcept { return _native->g; }
215
217 [[nodiscard]] constexpr texture_handle eta() const noexcept { return _native->eta; }
218
220 [[nodiscard]] constexpr uint_t max_depth() const noexcept { return _native->max_depth; }
221
223 [[nodiscard]] constexpr uint_t n_samples() const noexcept { return _native->n_samples; }
224
226 [[nodiscard]] constexpr texture_handle reflectance() const noexcept { return _native->reflectance; }
227
229 [[nodiscard]] constexpr material_roughness_params roughness_params() const noexcept { return _native->roughness_params; }
230
232 [[nodiscard]] constexpr float_t thickness() const noexcept { return _native->thickness; }
233
235 [[nodiscard]] constexpr auto reflect() const noexcept {
236 return std::make_tuple(bump_map(), albedo(), g(), eta(), max_depth(), n_samples(), reflectance(), roughness_params(),
237 thickness());
238 }
239 };
240
253
260 [[nodiscard]] constexpr std::string_view to_string(const material_conductor_value_type type) noexcept {
262 switch (type) {
263 case ETA_K: return "etak";
264 case REFLECTANCE: return "reflectance";
265 case MAX_NUM: return "maxnum";
266 default: return "UNKNOWN";
267 }
268 }
269
275 : detail::wrapper<material_coated_conductor_eta_k,
276 std::remove_cvref_t<decltype(std::declval<const tpbrt_material_coated_conductor_params_t&>().as.conductor)>> {
278 using wrapper::wrapper;
279
281 [[nodiscard]] constexpr spectrum eta() const noexcept { return _native->eta; }
282
284 [[nodiscard]] constexpr spectrum k() const noexcept { return _native->k; }
285
287 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(eta(), k()); }
288 };
289
295 : detail::wrapper<material_coated_conductor_params, tpbrt_material_coated_conductor_params_t>,
296 detail::with_variant<material_coated_conductor_params, material_coated_conductor_eta_k, spectrum> {
298 using wrapper::wrapper;
299
301 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
302
304 [[nodiscard]] constexpr texture_handle albedo() const noexcept { return _native->albedo; }
305
307 [[nodiscard]] constexpr texture_handle g() const noexcept { return _native->g; }
308
310 [[nodiscard]] constexpr uint_t max_depth() const noexcept { return _native->max_depth; }
311
313 [[nodiscard]] constexpr uint_t n_samples() const noexcept { return _native->n_samples; }
314
316 [[nodiscard]] constexpr material_roughness_params conductor_roughness_params() const noexcept {
317 return _native->conductor_roughness_params;
318 }
319
321 [[nodiscard]] constexpr material_roughness_params interface_roughness_params() const noexcept {
322 return _native->interface_roughness_params;
323 }
324
326 [[nodiscard]] constexpr float_t thickness() const noexcept { return _native->thickness; }
327
329 [[nodiscard]] constexpr material_conductor_value_type value_type() const noexcept {
330 return static_cast<material_conductor_value_type>(_native->value_type);
331 }
332
334 [[nodiscard]] constexpr bool_t is_eta_k() const noexcept { return value_type() == material_conductor_value_type::ETA_K; }
335
337 [[nodiscard]] constexpr bool_t is_reflectance() const noexcept {
339 }
340
342 [[nodiscard]] constexpr std::optional<material_coated_conductor_eta_k> as_eta_k() const noexcept {
343 if (!is_eta_k()) { return std::nullopt; }
344 return _native->as.conductor;
345 }
346
348 [[nodiscard]] constexpr std::optional<spectrum> as_reflectance() const noexcept {
349 if (!is_reflectance()) { return std::nullopt; }
350 return _native->as.reflectance;
351 }
352
354 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
356 switch (value_type()) {
357 case ETA_K: return _native->as.conductor;
358 case REFLECTANCE: return _native->as.reflectance;
359 case MAX_NUM: [[fallthrough]];
360 default: break;
361 }
362 return std::nullopt;
363 }
364
366 [[nodiscard]] constexpr auto reflect() const noexcept {
367 return std::make_tuple(bump_map(), albedo(), g(), max_depth(), n_samples(), to_variant(),
369 }
370 };
371
377 : detail::wrapper<material_conductor_eta_k,
378 std::remove_cvref_t<decltype(std::declval<const tpbrt_material_conductor_params_t&>().as.conductor)>> {
380 using wrapper::wrapper;
381
383 [[nodiscard]] constexpr texture_handle eta() const noexcept { return _native->eta; }
384
386 [[nodiscard]] constexpr texture_handle k() const noexcept { return _native->k; }
387
389 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(eta(), k()); }
390 };
391
396 struct material_conductor_params : detail::wrapper<material_conductor_params, tpbrt_material_conductor_params_t>,
397 detail::with_variant<material_conductor_params, material_conductor_eta_k, texture_handle> {
399 using wrapper::wrapper;
400
402 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
403
405 [[nodiscard]] constexpr material_roughness_params roughness_params() const noexcept { return _native->roughness_params; }
406
408 [[nodiscard]] constexpr material_conductor_value_type value_type() const noexcept {
409 return static_cast<material_conductor_value_type>(_native->value_type);
410 }
411
413 [[nodiscard]] constexpr bool_t is_eta_k() const noexcept { return value_type() == material_conductor_value_type::ETA_K; }
414
416 [[nodiscard]] constexpr bool_t is_reflectance() const noexcept {
418 }
419
421 [[nodiscard]] constexpr std::optional<material_conductor_eta_k> as_eta_k() const noexcept {
422 if (!is_eta_k()) { return std::nullopt; }
423 return _native->as.conductor;
424 }
425
427 [[nodiscard]] constexpr std::optional<texture_handle> as_reflectance() const noexcept {
428 if (!is_reflectance()) { return std::nullopt; }
429 return _native->as.reflectance;
430 }
431
433 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
435 switch (value_type()) {
436 case ETA_K: return _native->as.conductor;
437 case REFLECTANCE: return _native->as.reflectance;
438 case MAX_NUM: [[fallthrough]];
439 default: break;
440 }
441 return std::nullopt;
442 }
443
445 [[nodiscard]] constexpr auto reflect() const noexcept {
446 return std::make_tuple(bump_map(), to_variant(), roughness_params(), value_type());
447 }
448 };
449
454 struct material_dielectric_params : detail::wrapper<material_dielectric_params, tpbrt_material_dielectric_params_t> {
456 using wrapper::wrapper;
457
459 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
460
462 [[nodiscard]] constexpr texture_handle eta() const noexcept { return _native->eta; }
463
465 [[nodiscard]] constexpr material_roughness_params roughness_params() const noexcept { return _native->roughness_params; }
466
468 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(bump_map(), eta(), roughness_params()); }
469 };
470
475 struct material_diffuse_params : detail::wrapper<material_diffuse_params, tpbrt_material_diffuse_params_t> {
477 using wrapper::wrapper;
478
480 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
481
483 [[nodiscard]] constexpr texture_handle reflectance() const noexcept { return _native->reflectance; }
484
486 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(bump_map(), reflectance()); }
487 };
488
494 : detail::wrapper<material_diffuse_transmission_params, tpbrt_material_diffuse_transmission_params_t> {
496 using wrapper::wrapper;
497
499 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
500
502 [[nodiscard]] constexpr texture_handle reflectance() const noexcept { return _native->reflectance; }
503
505 [[nodiscard]] constexpr texture_handle transmittance() const noexcept { return _native->transmittance; }
506
508 [[nodiscard]] constexpr texture_handle scale() const noexcept { return _native->scale; }
509
511 [[nodiscard]] constexpr auto reflect() const noexcept {
512 return std::make_tuple(bump_map(), reflectance(), transmittance(), scale());
513 }
514 };
515
520 struct material_hair_params : detail::wrapper<material_hair_params, tpbrt_material_hair_params_t> {
522 using wrapper::wrapper;
523
525 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
526
528 [[nodiscard]] constexpr texture_handle sigma_a() const noexcept { return _native->sigma_a; }
529
531 [[nodiscard]] constexpr texture_handle reflectance() const noexcept { return _native->reflectance; }
532
534 [[nodiscard]] constexpr texture_handle eumelanin() const noexcept { return _native->eumelanin; }
535
537 [[nodiscard]] constexpr texture_handle pheomelanin() const noexcept { return _native->pheomelanin; }
538
540 [[nodiscard]] constexpr texture_handle eta() const noexcept { return _native->eta; }
541
543 [[nodiscard]] constexpr texture_handle beta_m() const noexcept { return _native->beta_m; }
544
546 [[nodiscard]] constexpr texture_handle beta_n() const noexcept { return _native->beta_n; }
547
549 [[nodiscard]] constexpr texture_handle alpha() const noexcept { return _native->alpha; }
550
552 [[nodiscard]] constexpr auto reflect() const noexcept {
553 return std::make_tuple(bump_map(), sigma_a(), reflectance(), eumelanin(), pheomelanin(), eta(), beta_m(), beta_n(),
554 alpha());
555 }
556 };
557
562 struct material_measured_params : detail::wrapper<material_measured_params, tpbrt_material_measured_params_t> {
564 using wrapper::wrapper;
565
567 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
568
570 [[nodiscard]] constexpr string file_name() const noexcept { return _native->file_name; }
571
573 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(bump_map(), file_name()); }
574 };
575
580 struct material_mix_params : detail::wrapper<material_mix_params, tpbrt_material_mix_params_t> {
583
585 using wrapper::wrapper;
586
588 [[nodiscard]] constexpr materials_type materials() const noexcept { return _native->materials; }
589
591 [[nodiscard]] constexpr texture_handle amount() const noexcept { return _native->amount; }
592
594 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(materials(), amount()); }
595 };
596
609
616 [[nodiscard]] constexpr std::string_view to_string(const material_subsurface_scattering_value scattering_value) noexcept {
618 switch (scattering_value) {
619 case SIGMA: return "sigma";
620 case BUILTIN: return "builtin";
621 case MAX_NUM: return "maxnum";
622 default: return "UNKNOWN";
623 }
624 }
625
631 : detail::wrapper<material_subsurface_sigma,
632 std::remove_cvref_t<decltype(std::declval<const tpbrt_material_subsurface_scattering_t&>().as.sigma)>> {
634 using wrapper::wrapper;
635
637 [[nodiscard]] constexpr texture_handle sigma_a() const noexcept { return _native->a; }
638
640 [[nodiscard]] constexpr texture_handle sigma_s() const noexcept { return _native->s; }
641
643 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(sigma_a(), sigma_s()); }
644 };
645
651 : detail::wrapper<material_subsurface_scattering, tpbrt_material_subsurface_scattering_t>,
652 detail::with_variant<material_subsurface_scattering, material_subsurface_sigma, scattering_builtin> {
654 using wrapper::wrapper;
655
657 [[nodiscard]] constexpr material_subsurface_scattering_value type() const noexcept {
658 return static_cast<material_subsurface_scattering_value>(_native->type);
659 }
660
662 [[nodiscard]] constexpr bool_t is_sigma() const noexcept { return type() == material_subsurface_scattering_value::SIGMA; }
663
665 [[nodiscard]] constexpr bool_t is_builtin() const noexcept {
667 }
668
670 [[nodiscard]] constexpr std::optional<material_subsurface_sigma> as_sigma() const noexcept {
671 if (!is_sigma()) { return std::nullopt; }
672 return _native->as.sigma;
673 }
674
676 [[nodiscard]] constexpr std::optional<scattering_builtin> as_builtin() const noexcept {
677 if (!is_builtin()) { return std::nullopt; }
678 return static_cast<scattering_builtin>(_native->as.builtin);
679 }
680
682 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
684 switch (type()) {
685 case SIGMA: return _native->as.sigma;
686 case BUILTIN: return static_cast<scattering_builtin>(_native->as.builtin);
687 case MAX_NUM: [[fallthrough]];
688 default: break;
689 }
690 return std::nullopt;
691 }
692
694 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(to_variant(), type()); }
695 };
696
701 struct material_subsurface_params : detail::wrapper<material_subsurface_params, tpbrt_material_subsurface_params_t> {
703 using wrapper::wrapper;
704
706 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
707
709 [[nodiscard]] constexpr texture_handle eta() const noexcept { return _native->eta; }
710
712 [[nodiscard]] constexpr texture_handle g() const noexcept { return _native->g; }
713
715 [[nodiscard]] constexpr texture_handle mfp() const noexcept { return _native->mfp; }
716
718 [[nodiscard]] constexpr material_subsurface_scattering scattering() const noexcept { return _native->scattering; }
719
721 [[nodiscard]] constexpr texture_handle reflectance() const noexcept { return _native->reflectance; }
722
724 [[nodiscard]] constexpr material_roughness_params roughness_params() const noexcept { return _native->roughness_params; }
725
727 [[nodiscard]] constexpr float_t scale() const noexcept { return _native->scale; }
728
730 [[nodiscard]] constexpr auto reflect() const noexcept {
731 return std::make_tuple(bump_map(), eta(), g(), mfp(), scattering(), reflectance(), roughness_params(), scale());
732 }
733 };
734
740 : detail::wrapper<material_thin_dielectric_params, tpbrt_material_thin_dielectric_params_t> {
742 using wrapper::wrapper;
743
745 [[nodiscard]] constexpr material_bump_map_params bump_map() const noexcept { return _native->bump_map; }
746
748 [[nodiscard]] constexpr texture_handle eta() const noexcept { return _native->eta; }
749
751 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(bump_map(), eta()); }
752 };
753
758 struct material : detail::wrapper<material, tpbrt_material_t>,
759 detail::with_variant<material, material_coated_diffuse_params, material_coated_conductor_params,
760 material_conductor_params, material_dielectric_params, material_diffuse_params,
761 material_diffuse_transmission_params, material_hair_params, material_measured_params, material_mix_params,
762 material_subsurface_params, material_thin_dielectric_params> {
764 using wrapper::wrapper;
765
767 [[nodiscard]] constexpr material_idx_t idx() const noexcept { return _native->idx; }
768
770 [[nodiscard]] constexpr string name() const noexcept { return _native->name; }
771
773 [[nodiscard]] constexpr material_type type() const noexcept { return static_cast<material_type>(_native->type); }
774
776 [[nodiscard]] constexpr bool_t is_coated_diffuse() const noexcept { return type() == material_type::COATED_DIFFUSE; }
777
779 [[nodiscard]] constexpr bool_t is_coated_conductor() const noexcept { return type() == material_type::COATED_CONDUCTOR; }
780
782 [[nodiscard]] constexpr bool_t is_conductor() const noexcept { return type() == material_type::CONDUCTOR; }
783
785 [[nodiscard]] constexpr bool_t is_dielectric() const noexcept { return type() == material_type::DIELECTRIC; }
786
788 [[nodiscard]] constexpr bool_t is_diffuse() const noexcept { return type() == material_type::DIFFUSE; }
789
791 [[nodiscard]] constexpr bool_t is_diffuse_transmission() const noexcept {
793 }
794
796 [[nodiscard]] constexpr bool_t is_hair() const noexcept { return type() == material_type::HAIR; }
797
799 [[nodiscard]] constexpr bool_t is_measured() const noexcept { return type() == material_type::MEASURED; }
800
802 [[nodiscard]] constexpr bool_t is_mix() const noexcept { return type() == material_type::MIX; }
803
805 [[nodiscard]] constexpr bool_t is_subsurface() const noexcept { return type() == material_type::SUBSURFACE; }
806
808 [[nodiscard]] constexpr bool_t is_thin_dielectric() const noexcept { return type() == material_type::THIN_DIELECTRIC; }
809
811 [[nodiscard]] constexpr std::optional<material_coated_diffuse_params> as_coated_diffuse() const noexcept {
812 if (!is_coated_diffuse()) { return std::nullopt; }
813 return _native->as.coated_diffuse;
814 }
815
817 [[nodiscard]] constexpr std::optional<material_coated_conductor_params> as_coated_conductor() const noexcept {
818 if (!is_coated_conductor()) { return std::nullopt; }
819 return _native->as.coated_conductor;
820 }
821
823 [[nodiscard]] constexpr std::optional<material_conductor_params> as_conductor() const noexcept {
824 if (!is_conductor()) { return std::nullopt; }
825 return _native->as.conductor;
826 }
827
829 [[nodiscard]] constexpr std::optional<material_dielectric_params> as_dielectric() const noexcept {
830 if (!is_dielectric()) { return std::nullopt; }
831 return _native->as.dielectric;
832 }
833
835 [[nodiscard]] constexpr std::optional<material_diffuse_params> as_diffuse() const noexcept {
836 if (!is_diffuse()) { return std::nullopt; }
837 return _native->as.diffuse;
838 }
839
841 [[nodiscard]] constexpr std::optional<material_diffuse_transmission_params> as_diffuse_transmission() const noexcept {
842 if (!is_diffuse_transmission()) { return std::nullopt; }
843 return _native->as.diffuse_transmission;
844 }
845
847 [[nodiscard]] constexpr std::optional<material_hair_params> as_hair() const noexcept {
848 if (!is_hair()) { return std::nullopt; }
849 return _native->as.hair;
850 }
851
853 [[nodiscard]] constexpr std::optional<material_measured_params> as_measured() const noexcept {
854 if (!is_measured()) { return std::nullopt; }
855 return _native->as.measured;
856 }
857
859 [[nodiscard]] constexpr std::optional<material_mix_params> as_mix() const noexcept {
860 if (!is_mix()) { return std::nullopt; }
861 return _native->as.mix;
862 }
863
865 [[nodiscard]] constexpr std::optional<material_subsurface_params> as_subsurface() const noexcept {
866 if (!is_subsurface()) { return std::nullopt; }
867 return _native->as.subsurface;
868 }
869
871 [[nodiscard]] constexpr std::optional<material_thin_dielectric_params> as_thin_dielectric() const noexcept {
872 if (!is_thin_dielectric()) { return std::nullopt; }
873 return _native->as.thin_dielectric;
874 }
875
877 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
878 using enum material_type;
879 switch (type()) {
880 case COATED_DIFFUSE: return _native->as.coated_diffuse;
881 case COATED_CONDUCTOR: return _native->as.coated_conductor;
882 case CONDUCTOR: return _native->as.conductor;
883 case DIELECTRIC: return _native->as.dielectric;
884 case DIFFUSE: return _native->as.diffuse;
885 case DIFFUSE_TRANSMISSION: return _native->as.diffuse_transmission;
886 case HAIR: return _native->as.hair;
887 case MEASURED: return _native->as.measured;
888 case MIX: return _native->as.mix;
889 case SUBSURFACE: return _native->as.subsurface;
890 case THIN_DIELECTRIC: return _native->as.thin_dielectric;
891 case MAX_NUM: [[fallthrough]];
892 default: break;
893 }
894 return std::nullopt;
895 }
896
898 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(idx(), name(), to_variant(), type()); }
899 };
900
907 struct materials_list : array<tpbrt_materials_list_t, material, &tpbrt_materials_list_t::materials> {
909 using array::array;
910
912 using array::at;
913
915 using array::operator[];
916
918 [[nodiscard]] result<element_type> at(const material_handle handle) const noexcept {
919 return detail::find_in<element_type, tpbrt_material_t>(tpbrt_get_material_by_handle, _native, handle.native());
920 }
921
923 [[nodiscard]] result<element_type> at(const std::string_view name) const noexcept {
924 return detail::find_in<element_type, tpbrt_material_t>(tpbrt_get_material_by_name, _native,
925 detail::to_native_string(name));
926 }
927
929 [[nodiscard]] result<element_type> operator[](const material_handle handle) const noexcept { return at(handle); }
930
932 [[nodiscard]] result<element_type> operator[](const std::string_view name) const noexcept { return at(name); }
933 };
934
942 [[nodiscard]] inline result<material> get_material(const materials_list list, const material_handle handle) noexcept {
943 return list.at(handle);
944 }
945
953 [[nodiscard]] inline result<material> get_material(const materials_list list, const std::string_view name) noexcept {
954 return list.at(name);
955 }
956} // namespace tpbrt
957#endif // _TINYPBRT_MATERIAL_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.
@ BUILTIN
Aperture value is a builtin aperture.
tpbrt_uchar_t uchar_t
Unsigned char type.
Definition fwd.hpp:34
@ NONE
No error -> Success.
@ DIFFUSE
Diffuse area light.
result< material > get_material(const materials_list list, const material_handle handle) noexcept
Returns material to which handle is provided.
Definition material.hpp:942
tpbrt_material_idx_t material_idx_t
Material index type.
Definition fwd.hpp:337
material_type
Material types.
Definition material.hpp:22
material_bump_map_type
Material bump map types.
Definition material.hpp:96
material_conductor_value_type
Conductor material value type.
Definition material.hpp:245
material_subsurface_scattering_value
Subsurface material scattering value type.
Definition material.hpp:601
@ COATED_CONDUCTOR
Coated conductor.
@ DIFFUSE_TRANSMISSION
Diffuse transmission.
@ INTERFACE
Interface.
@ THIN_DIELECTRIC
Thin Dielectric.
@ CONDUCTOR
Conductor.
@ COATED_DIFFUSE
Coated diffuse.
@ SUBSURFACE
Subsurface.
@ DIELECTRIC
Dielectric.
@ DISPLACEMENT
Displacement as bump map.
@ NORMAL_MAP
Normal map as bump map.
@ REFLECTANCE
Conductor material value defined as 'reflectance' value.
@ ETA_K
Conductor material value defined as 'eta' and 'k' values.
@ SIGMA
Uses sigma_s and sigma_a values.
@ BUILTIN
Uses builtin as sigma_s and sigma_a values.
tpbrt_error_t tpbrt_get_material_by_handle(const tpbrt_materials_list_t *materials, tpbrt_material_handle_t handle, const tpbrt_material_t **material)
Returns pointer to material to which handle is provided.
tpbrt_error_t tpbrt_get_material_by_name(const tpbrt_materials_list_t *materials, tpbrt_string_t name, const tpbrt_material_t **material)
Returns pointer to material with given name.
@ TPBRT_MATERIAL_TYPE_DIFFUSE
Diffuse.
Definition material.h:36
@ TPBRT_MATERIAL_TYPE_COATED_DIFFUSE
Coated diffuse.
Definition material.h:28
@ TPBRT_MATERIAL_TYPE_SUBSURFACE
Subsurface.
Definition material.h:48
@ TPBRT_MATERIAL_TYPE_MIX
Mix.
Definition material.h:46
@ TPBRT_MATERIAL_TYPE_DIELECTRIC
Dielectric.
Definition material.h:34
@ TPBRT_MATERIAL_TYPE_THIN_DIELECTRIC
Thin Dielectric.
Definition material.h:50
@ TPBRT_MATERIAL_TYPE_DIFFUSE_TRANSMISSION
Diffuse transmission.
Definition material.h:38
@ TPBRT_MATERIAL_TYPE_MAX_NUM
Count of available material types.
Definition material.h:52
@ TPBRT_MATERIAL_TYPE_MEASURED
Measured.
Definition material.h:44
@ TPBRT_MATERIAL_TYPE_COATED_CONDUCTOR
Coated conductor.
Definition material.h:30
@ TPBRT_MATERIAL_TYPE_CONDUCTOR
Conductor.
Definition material.h:32
@ TPBRT_MATERIAL_TYPE_INTERFACE
Interface.
Definition material.h:42
@ TPBRT_MATERIAL_TYPE_HAIR
Hair.
Definition material.h:40
@ TPBRT_MATERIAL_BUMP_MAP_TYPE_DISPLACEMENT
Displacement as bump map.
Definition material.h:72
@ TPBRT_MATERIAL_BUMP_MAP_TYPE_MAX_NUM
Count of available material bump map types.
Definition material.h:76
@ TPBRT_MATERIAL_BUMP_MAP_TYPE_NORMAL_MAP
Normal map as bump map.
Definition material.h:74
@ TPBRT_MATERIAL_BUMP_MAP_TYPE_NONE
No bump map.
Definition material.h:70
@ TPBRT_MATERIAL_SUBSURFACE_SCATTERING_VALUE_MAX_NUM
Count of available material scattering values.
Definition material.h:313
@ TPBRT_MATERIAL_SUBSURFACE_SCATTERING_VALUE_SIGMA
Uses sigma_s and sigma_a values.
Definition material.h:309
@ TPBRT_MATERIAL_SUBSURFACE_SCATTERING_VALUE_BUILTIN
Uses builtin as sigma_s and sigma_a values.
Definition material.h:311
@ TPBRT_MATERIAL_CONDUCTOR_VALUE_TYPE_ETA_K
Conductor material value defined as 'eta' and 'k' values.
Definition material.h:142
@ TPBRT_MATERIAL_CONDUCTOR_VALUE_TYPE_MAX_NUM
Count of available conductor material value types.
Definition material.h:146
@ TPBRT_MATERIAL_CONDUCTOR_VALUE_TYPE_REFLECTANCE
Conductor material value defined as 'reflectance' value.
Definition material.h:144
tpbrt_uint_t uint_t
Unsigned int type.
Definition fwd.hpp:92
bool bool_t
Bool type.
Definition fwd.hpp:82
tpbrt_float_t float_t
Float type.
Definition fwd.hpp:97
scattering_builtin
Scattering builtins.
Definition scattering.hpp:21
Definition accelerator.hpp:14
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_material_bump_map_params_t.
Definition material.hpp:129
constexpr std::optional< texture_handle > as_displacement() const noexcept
Returns material bump map parameters as displacement.
Definition material.hpp:145
constexpr bool_t is_displacement() const noexcept
Returns true if type is displacement.
Definition material.hpp:139
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition material.hpp:157
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:169
constexpr material_bump_map_type type() const noexcept
Returns type value.
Definition material.hpp:134
constexpr std::optional< string > as_normal_map() const noexcept
Returns material bump map parameters as normal_map.
Definition material.hpp:151
constexpr bool_t is_normal_map() const noexcept
Returns true if type is normal_map.
Definition material.hpp:142
Conductor eta and k values of the coated conductor material.
Definition material.hpp:276
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:287
constexpr spectrum k() const noexcept
Returns the conductor's extinction coefficient.
Definition material.hpp:284
constexpr spectrum eta() const noexcept
Returns the conductor's index of refraction.
Definition material.hpp:281
C++ wrapper for tpbrt_material_coated_conductor_params_t.
Definition material.hpp:296
constexpr material_roughness_params conductor_roughness_params() const noexcept
Returns conductor_roughness_params value.
Definition material.hpp:316
constexpr uint_t max_depth() const noexcept
Returns max_depth value.
Definition material.hpp:310
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:301
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:366
constexpr texture_handle g() const noexcept
Returns g value.
Definition material.hpp:307
constexpr bool_t is_reflectance() const noexcept
Returns true if type is reflectance.
Definition material.hpp:337
constexpr uint_t n_samples() const noexcept
Returns n_samples value.
Definition material.hpp:313
constexpr texture_handle albedo() const noexcept
Returns albedo value.
Definition material.hpp:304
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition material.hpp:354
constexpr std::optional< material_coated_conductor_eta_k > as_eta_k() const noexcept
Returns eta_k parameters (std::nullopt if the type is different).
Definition material.hpp:342
constexpr float_t thickness() const noexcept
Returns thickness value.
Definition material.hpp:326
constexpr std::optional< spectrum > as_reflectance() const noexcept
Returns reflectance parameters (std::nullopt if the type is different).
Definition material.hpp:348
constexpr material_conductor_value_type value_type() const noexcept
Returns value_type value.
Definition material.hpp:329
constexpr material_roughness_params interface_roughness_params() const noexcept
Returns interface_roughness_params value.
Definition material.hpp:321
constexpr bool_t is_eta_k() const noexcept
Returns true if type is eta_k.
Definition material.hpp:334
C++ wrapper for tpbrt_material_coated_diffuse_params_t.
Definition material.hpp:203
constexpr float_t thickness() const noexcept
Returns thickness value.
Definition material.hpp:232
constexpr texture_handle reflectance() const noexcept
Returns reflectance value.
Definition material.hpp:226
constexpr texture_handle g() const noexcept
Returns g value.
Definition material.hpp:214
constexpr material_roughness_params roughness_params() const noexcept
Returns roughness_params value.
Definition material.hpp:229
constexpr uint_t max_depth() const noexcept
Returns max_depth value.
Definition material.hpp:220
constexpr texture_handle eta() const noexcept
Returns eta value.
Definition material.hpp:217
constexpr texture_handle albedo() const noexcept
Returns albedo value.
Definition material.hpp:211
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:208
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:235
constexpr uint_t n_samples() const noexcept
Returns n_samples value.
Definition material.hpp:223
Conductor eta and k values of the conductor material.
Definition material.hpp:378
constexpr texture_handle k() const noexcept
Returns the conductor's absorption coefficient.
Definition material.hpp:386
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:389
constexpr texture_handle eta() const noexcept
Returns the conductor's index of refraction.
Definition material.hpp:383
C++ wrapper for tpbrt_material_conductor_params_t.
Definition material.hpp:397
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:402
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:445
constexpr bool_t is_reflectance() const noexcept
Returns true if type is reflectance.
Definition material.hpp:416
constexpr std::optional< texture_handle > as_reflectance() const noexcept
Returns reflectance parameters (std::nullopt if the type is different).
Definition material.hpp:427
constexpr std::optional< material_conductor_eta_k > as_eta_k() const noexcept
Returns eta_k parameters (std::nullopt if the type is different).
Definition material.hpp:421
constexpr material_roughness_params roughness_params() const noexcept
Returns roughness_params value.
Definition material.hpp:405
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition material.hpp:433
constexpr material_conductor_value_type value_type() const noexcept
Returns value_type value.
Definition material.hpp:408
constexpr bool_t is_eta_k() const noexcept
Returns true if type is eta_k.
Definition material.hpp:413
C++ wrapper for tpbrt_material_dielectric_params_t.
Definition material.hpp:454
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:468
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:459
constexpr material_roughness_params roughness_params() const noexcept
Returns roughness_params value.
Definition material.hpp:465
constexpr texture_handle eta() const noexcept
Returns eta value.
Definition material.hpp:462
C++ wrapper for tpbrt_material_diffuse_params_t.
Definition material.hpp:475
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:480
constexpr texture_handle reflectance() const noexcept
Returns reflectance value.
Definition material.hpp:483
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:486
C++ wrapper for tpbrt_material_diffuse_transmission_params_t.
Definition material.hpp:494
constexpr texture_handle transmittance() const noexcept
Returns transmittance value.
Definition material.hpp:505
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:511
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:499
constexpr texture_handle scale() const noexcept
Returns scale value.
Definition material.hpp:508
constexpr texture_handle reflectance() const noexcept
Returns reflectance value.
Definition material.hpp:502
C++ wrapper for tpbrt_material_hair_params_t.
Definition material.hpp:520
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:525
constexpr texture_handle pheomelanin() const noexcept
Returns pheomelanin value.
Definition material.hpp:537
constexpr texture_handle eumelanin() const noexcept
Returns eumelanin value.
Definition material.hpp:534
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:552
constexpr texture_handle sigma_a() const noexcept
Returns sigma_a value.
Definition material.hpp:528
constexpr texture_handle reflectance() const noexcept
Returns reflectance value.
Definition material.hpp:531
constexpr texture_handle beta_m() const noexcept
Returns beta_m value.
Definition material.hpp:543
constexpr texture_handle beta_n() const noexcept
Returns beta_n value.
Definition material.hpp:546
constexpr texture_handle alpha() const noexcept
Returns alpha value.
Definition material.hpp:549
constexpr texture_handle eta() const noexcept
Returns eta value.
Definition material.hpp:540
C++ wrapper for tpbrt_material_handle_t.
Definition material.hpp:81
constexpr material_idx_t material_idx() const noexcept
Returns material_idx value.
Definition material.hpp:86
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:89
C++ wrapper for tpbrt_material_measured_params_t.
Definition material.hpp:562
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:567
constexpr string file_name() const noexcept
Returns file_name value.
Definition material.hpp:570
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:573
C++ wrapper for tpbrt_material_mix_params_t.
Definition material.hpp:580
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:594
constexpr materials_type materials() const noexcept
Returns materials value.
Definition material.hpp:588
constexpr texture_handle amount() const noexcept
Returns amount value.
Definition material.hpp:591
C++ wrapper for tpbrt_material_roughness_params_t.
Definition material.hpp:176
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:193
constexpr texture_handle v_roughness() const noexcept
Returns v_roughness value.
Definition material.hpp:187
constexpr texture_handle roughness() const noexcept
Returns roughness value.
Definition material.hpp:181
constexpr texture_handle u_roughness() const noexcept
Returns u_roughness value.
Definition material.hpp:184
constexpr bool_t remap_roughness() const noexcept
Returns remap_roughness value.
Definition material.hpp:190
C++ wrapper for tpbrt_material_subsurface_params_t.
Definition material.hpp:701
constexpr texture_handle eta() const noexcept
Returns eta value.
Definition material.hpp:709
constexpr texture_handle g() const noexcept
Returns g value.
Definition material.hpp:712
constexpr material_roughness_params roughness_params() const noexcept
Returns roughness_params value.
Definition material.hpp:724
constexpr texture_handle mfp() const noexcept
Returns mfp value.
Definition material.hpp:715
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:730
constexpr texture_handle reflectance() const noexcept
Returns reflectance value.
Definition material.hpp:721
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:706
constexpr material_subsurface_scattering scattering() const noexcept
Returns scattering value.
Definition material.hpp:718
constexpr float_t scale() const noexcept
Returns scale value.
Definition material.hpp:727
C++ wrapper for tpbrt_material_subsurface_scattering_t.
Definition material.hpp:652
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:694
constexpr std::optional< scattering_builtin > as_builtin() const noexcept
Returns builtin parameters (std::nullopt if the type is different).
Definition material.hpp:676
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition material.hpp:682
constexpr bool_t is_builtin() const noexcept
Returns true if type is builtin.
Definition material.hpp:665
constexpr bool_t is_sigma() const noexcept
Returns true if type is sigma.
Definition material.hpp:662
constexpr material_subsurface_scattering_value type() const noexcept
Returns type value.
Definition material.hpp:657
constexpr std::optional< material_subsurface_sigma > as_sigma() const noexcept
Returns material scattering value as sigma.
Definition material.hpp:670
Absorption and scattering coefficients of the subsurface material.
Definition material.hpp:632
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:643
constexpr texture_handle sigma_a() const noexcept
Returns absorption coefficient of the volume, measured in mm^-1.
Definition material.hpp:637
constexpr texture_handle sigma_s() const noexcept
Returns scattering coefficient of the volume, measured in mm^-1.
Definition material.hpp:640
C++ wrapper for tpbrt_material_thin_dielectric_params_t.
Definition material.hpp:740
constexpr texture_handle eta() const noexcept
Returns eta value.
Definition material.hpp:748
constexpr material_bump_map_params bump_map() const noexcept
Returns bump_map value.
Definition material.hpp:745
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:751
C++ wrapper for tpbrt_material_t.
Definition material.hpp:762
constexpr bool_t is_dielectric() const noexcept
Returns true if type is dielectric.
Definition material.hpp:785
constexpr bool_t is_mix() const noexcept
Returns true if type is mix.
Definition material.hpp:802
constexpr bool_t is_diffuse_transmission() const noexcept
Returns true if type is diffuse_transmission.
Definition material.hpp:791
constexpr bool_t is_coated_conductor() const noexcept
Returns true if type is coated_conductor.
Definition material.hpp:779
constexpr std::optional< material_coated_diffuse_params > as_coated_diffuse() const noexcept
Returns material parameters as coated_diffuse.
Definition material.hpp:811
constexpr bool_t is_conductor() const noexcept
Returns true if type is conductor.
Definition material.hpp:782
constexpr std::optional< material_dielectric_params > as_dielectric() const noexcept
Returns material parameters as dielectric.
Definition material.hpp:829
constexpr std::optional< material_diffuse_transmission_params > as_diffuse_transmission() const noexcept
Returns material parameters as diffuse_transmission.
Definition material.hpp:841
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition material.hpp:877
constexpr std::optional< material_conductor_params > as_conductor() const noexcept
Returns material parameters as conductor.
Definition material.hpp:823
constexpr std::optional< material_coated_conductor_params > as_coated_conductor() const noexcept
Returns material parameters as coated_conductor.
Definition material.hpp:817
constexpr bool_t is_hair() const noexcept
Returns true if type is hair.
Definition material.hpp:796
constexpr material_idx_t idx() const noexcept
Returns idx value.
Definition material.hpp:767
constexpr std::optional< material_hair_params > as_hair() const noexcept
Returns material parameters as hair.
Definition material.hpp:847
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition material.hpp:898
constexpr bool_t is_diffuse() const noexcept
Returns true if type is diffuse.
Definition material.hpp:788
constexpr std::optional< material_mix_params > as_mix() const noexcept
Returns material parameters as mix.
Definition material.hpp:859
constexpr std::optional< material_subsurface_params > as_subsurface() const noexcept
Returns material parameters as subsurface.
Definition material.hpp:865
constexpr bool_t is_subsurface() const noexcept
Returns true if type is subsurface.
Definition material.hpp:805
constexpr bool_t is_measured() const noexcept
Returns true if type is measured.
Definition material.hpp:799
constexpr std::optional< material_thin_dielectric_params > as_thin_dielectric() const noexcept
Returns material parameters as thin_dielectric.
Definition material.hpp:871
constexpr bool_t is_coated_diffuse() const noexcept
Returns true if type is coated_diffuse.
Definition material.hpp:776
constexpr material_type type() const noexcept
Returns type value.
Definition material.hpp:773
constexpr string name() const noexcept
Returns name value.
Definition material.hpp:770
constexpr bool_t is_thin_dielectric() const noexcept
Returns true if type is thin_dielectric.
Definition material.hpp:808
constexpr std::optional< material_measured_params > as_measured() const noexcept
Returns material parameters as measured.
Definition material.hpp:853
constexpr std::optional< material_diffuse_params > as_diffuse() const noexcept
Returns material parameters as diffuse.
Definition material.hpp:835
C++ wrapper for tpbrt_materials_list_t.
Definition material.hpp:907
result< element_type > at(const std::string_view name) const noexcept
Returns material with given name.
Definition material.hpp:923
result< element_type > operator[](const std::string_view name) const noexcept
Returns material with given name.
Definition material.hpp:932
result< element_type > at(const material_handle handle) const noexcept
Returns material pointed by given handle.
Definition material.hpp:918
result< element_type > operator[](const material_handle handle) const noexcept
Returns material pointed by given handle.
Definition material.hpp:929
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_texture_handle_t.
Definition texture.hpp:53