-
Notifications
You must be signed in to change notification settings - Fork 4
/
minipbrt.h
1561 lines (1172 loc) · 44.9 KB
/
minipbrt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef MINIPBRT_H
#define MINIPBRT_H
/*
MIT License
Copyright (c) 2019 Vilya Harvey
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <limits>
#include <map>
#include <vector>
/// minipbrt - A simple and fast parser for PBRT v3 files
/// =====================================================
///
/// For info about the PBRT file format, see:
/// https://www.pbrt.org/fileformat-v3.html
///
/// Getting started
/// ---------------
///
/// - Add minipbrt.h and minipbrt.cpp into your project.
/// - Include minipbrt.h wherever you need it.
///
/// Loading a file
/// --------------
/// ```
/// minipbrt::Loader loader;
/// if (loader.load(filename)) {
/// minipbrt::Scene* scene = loader.take_scene();
/// // ... process the scene, then delete it ...
/// delete scene;
/// }
/// else {
/// // If parsing failed, the parser will have an error object.
/// const minipbrt::Error* err = loader.error();
/// fprintf(stderr, "[%s, line %lld, column %lld] %s\n",
/// err->filename(), err->line(), err->column(), err->message());
/// // Don't delete err, it's still owned by the loader.
/// }
/// ```
///
/// Implementation notes
/// --------------------
///
/// * The code is C++11.
///
/// * Spectra are always converted to RGB at load time. (This may change in
/// future; for now it simplifies things to convert them straight away).
///
/// * PLY files are not automatically loaded. Call `load_ply_mesh` to load one
/// of them. You can call this for each plymesh shape in parallel, or you can
/// call `load_ply_meshes` to load them all on a single thread.
/// (This is not implemented yet)
///
/// * Likewise, we provide helper functions for triangulating shapes but it's
/// up to you to call them.
///
/// * Most material properties can be either a texture or a value. These
/// properties are represented as structs with type `ColorTex` or `FloatTex`. In
/// both structs, if the `texture` member is anything other than
/// `kInvalidTexture`, the texture should be used *instead* of the `value`.
namespace minipbrt {
//
// Constants
//
static constexpr uint32_t kInvalidIndex = 0xFFFFFFFFu;
//
// Forward declarations
//
// Interfaces
struct Accelerator;
struct Camera;
struct Film;
struct Filter;
struct Integrator;
struct Material;
struct Medium;
struct Sampler;
struct Shape;
struct Texture;
// Instancing structs
struct Object;
struct Instance;
class Parser;
//
// Helper types
//
enum class ParamType : uint32_t {
Bool, //!< A boolean value.
Int, //!< 1 int: a single integer value.
Float, //!< 1 float: a single floating point value.
Point2, //!< 2 floats: a 2D point.
Point3, //!< 3 floats: a 3D point.
Vector2, //!< 2 floats: a 2D direction vector.
Vector3, //!< 3 floats: a 3D direction vector.
Normal3, //!< 3 floats: a 3D normal vector.
RGB, //!< 3 floats: an RGB color.
XYZ, //!< 3 floats: a CIE XYZ color.
Blackbody, //!< 2 floats: temperature (in Kelvin) and scale.
Samples, //!< 2n floats: n pairs of (wavelength, value) samples, sorted by wavelength.
String, //!< A char* pointer and a length.
Texture, //!< A texture reference, stored as a (name, index) pair. The index will be 0xFFFFFFFF if not resolved yet.
};
struct FloatTex {
uint32_t texture;
float value;
};
struct ColorTex {
uint32_t texture;
float value[3];
};
/// A bit set for elements of an enum.
template <class T>
struct Bits {
uint32_t val;
Bits() : val(0) {}
Bits(T ival) : val(1u << static_cast<uint32_t>(ival)) {}
Bits(uint32_t ival) : val(ival) {}
Bits(const Bits<T>& other) : val(other.val) {}
Bits<T>& operator = (const Bits<T>& other) { val = other.val; return *this; }
void set(T ival) { val |= (1u << static_cast<uint32_t>(ival)); }
void clear(T ival) { val &= ~(1u << static_cast<uint32_t>(ival)); }
void toggle(T ival) { val ^= (1u << static_cast<uint32_t>(ival)); }
void setAll() { val = 0xFFFFFFFFu; }
void clearAll() { val = 0u;}
void toggleAll() { val = ~val; }
bool contains(T ival) const { return (val & (1u << static_cast<uint32_t>(ival))) != 0u; }
};
template <class T> Bits<T> operator | (Bits<T> lhs, Bits<T> rhs) { return Bits<T>(lhs.val | rhs.val); }
template <class T> Bits<T> operator & (Bits<T> lhs, Bits<T> rhs) { return Bits<T>(lhs.val & rhs.val); }
template <class T> Bits<T> operator ^ (Bits<T> lhs, Bits<T> rhs) { return Bits<T>(lhs.val ^ rhs.val); }
template <class T> Bits<T> operator ~ (Bits<T> rhs) { return Bits<T>(~rhs.val); }
template <class T> Bits<T> operator | (Bits<T> lhs, T rhs) { return lhs | Bits<T>(rhs); }
template <class T> Bits<T> operator & (Bits<T> lhs, T rhs) { return lhs & Bits<T>(rhs); }
template <class T> Bits<T> operator ^ (Bits<T> lhs, T rhs) { return lhs ^ Bits<T>(rhs); }
template <class T> Bits<T> operator | (T lhs, T rhs) { return Bits<T>(lhs) | Bits<T>(rhs); }
struct Transform {
float start[4][4]; // row major matrix for when time = start time.
float end[4][4]; // row major for when time = end time.
};
//
// Accelerator types
//
enum class AcceleratorType {
BVH,
KdTree,
};
enum class BVHSplit {
SAH,
Middle,
Equal,
HLBVH,
};
struct Accelerator {
virtual ~Accelerator() {}
virtual AcceleratorType type() const = 0;
};
struct BVHAccelerator : public Accelerator {
int maxnodeprims = 4;
BVHSplit splitmethod = BVHSplit::SAH;
virtual ~BVHAccelerator() override {}
virtual AcceleratorType type() const override { return AcceleratorType::BVH; }
};
struct KdTreeAccelerator : public Accelerator {
int intersectcost = 80;
int traversalcost = 1;
float emptybonus = 0.2f;
int maxprims = 1;
int maxdepth = -1;
virtual ~KdTreeAccelerator() override {}
virtual AcceleratorType type() const override { return AcceleratorType::KdTree; }
};
//
// Area Light types
//
enum class AreaLightType {
Diffuse,
};
struct AreaLight {
float scale[3] = { 1.0f, 1.0f, 1.0f };
virtual ~AreaLight() {}
virtual AreaLightType type() const = 0;
};
struct DiffuseAreaLight : public AreaLight {
float L[3] = { 1.0f, 1.0f, 1.0f };
bool twosided = false;
int samples = 1;
virtual ~DiffuseAreaLight() override {}
virtual AreaLightType type() const override { return AreaLightType::Diffuse; }
};
//
// Camera types
//
enum class CameraType {
Perspective,
Orthographic,
Environment,
Realistic,
};
struct Camera {
Transform cameraToWorld;
float shutteropen = 0.0f;
float shutterclose = 1.0f;
virtual ~Camera() {}
virtual CameraType type() const = 0;
virtual void compute_defaults(const Film* film) {}
};
struct PerspectiveCamera : public Camera {
float frameaspectratio = 0.0f; // 0 or less means "compute this from the film resolution"
float screenwindow[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; // endx <= startx or endy <= starty means "compute this from the film resolution"
float lensradius = 0.0f;
float focaldistance = 1e30f;
float fov = 90.0f;
float halffov = 45.0f;
virtual ~PerspectiveCamera() override {}
virtual CameraType type() const override { return CameraType::Perspective; }
virtual void compute_defaults(const Film* film) override;
};
struct OrthographicCamera : public Camera {
float frameaspectratio = 1.0f;
float screenwindow[4] = { -1.0f, 1.0f, -1.0f, 1.0f };
float lensradius = 0.0f;
float focaldistance = 1e30f;
virtual ~OrthographicCamera() override {}
virtual CameraType type() const override { return CameraType::Orthographic; }
virtual void compute_defaults(const Film* film) override;
};
struct EnvironmentCamera : public Camera {
float frameaspectratio = 1.0f;
float screenwindow[4] = { -1.0f, 1.0f, -1.0f, 1.0f };
virtual ~EnvironmentCamera() override {}
virtual CameraType type() const override { return CameraType::Environment; }
virtual void compute_defaults(const Film* film) override;
};
struct RealisticCamera : public Camera {
char* lensfile = nullptr;
float aperturediameter = 1.0f;
float focusdistance = 10.0f;
bool simpleweighting = true;
virtual ~RealisticCamera() override { delete[] lensfile; }
virtual CameraType type() const override { return CameraType::Realistic; }
};
//
// Film types
//
enum class FilmType {
Image,
};
struct Film {
virtual ~Film() {}
virtual FilmType type() const = 0;
virtual float get_aspect_ratio() const = 0;
virtual void get_resolution(int& w, int& h) const = 0;
};
struct ImageFilm : public Film {
int xresolution = 640;
int yresolution = 480;
float cropwindow[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
float scale = 1.0f;
float maxsampleluminance = std::numeric_limits<float>::infinity();
float diagonal = 35.0f; // in millimetres
char* filename = nullptr; // name of the output image.
virtual ~ImageFilm() override { delete[] filename; }
virtual FilmType type() const override { return FilmType::Image; }
virtual float get_aspect_ratio() const override { return float(xresolution) / float(yresolution); }
virtual void get_resolution(int& w, int& h) const override { w = xresolution; h = yresolution; }
};
//
// Filter types
//
enum class FilterType {
Box,
Gaussian,
Mitchell,
Sinc,
Triangle,
};
struct Filter {
float xwidth = 2.0f;
float ywidth = 2.0f;
virtual ~Filter() {}
virtual FilterType type() const = 0;
};
struct BoxFilter : public Filter {
BoxFilter() { xwidth = 0.5f; ywidth = 0.5f; }
virtual ~BoxFilter() override {}
virtual FilterType type() const override { return FilterType::Box; }
};
struct GaussianFilter : public Filter {
float alpha = 2.0f;
virtual ~GaussianFilter() override {}
virtual FilterType type() const override { return FilterType::Gaussian; }
};
struct MitchellFilter : public Filter {
float B = 1.0f / 3.0f;
float C = 1.0f / 3.0f;
virtual ~MitchellFilter() override {}
virtual FilterType type() const override { return FilterType::Mitchell; }
};
struct SincFilter : public Filter {
float tau = 3.0f;
SincFilter() { xwidth = 4.0f; ywidth = 4.0f; }
virtual ~SincFilter() override {}
virtual FilterType type() const override { return FilterType::Sinc; }
};
struct TriangleFilter : public Filter {
virtual ~TriangleFilter() override {}
virtual FilterType type() const override { return FilterType::Triangle; }
};
//
// Integrator types
//
enum class IntegratorType {
BDPT,
DirectLighting,
MLT,
Path,
SPPM,
Whitted,
VolPath,
AO,
};
enum class LightSampleStrategy {
Uniform,
Power,
Spatial,
};
enum class DirectLightSampleStrategy {
All,
One,
};
struct Integrator {
virtual ~Integrator() {}
virtual IntegratorType type() const = 0;
virtual void compute_defaults(const Film* /*film*/) {}
};
struct BDPTIntegrator : public Integrator {
int maxdepth = 5;
int pixelbounds[4] = { 0, -1, 0, -1 }; // endx <= startx or endy <= starty means "whole image".
LightSampleStrategy lightsamplestrategy = LightSampleStrategy::Power;
bool visualizestrategies = false;
bool visualizeweights = false;
virtual ~BDPTIntegrator() override {}
virtual IntegratorType type() const override { return IntegratorType::BDPT; }
virtual void compute_defaults(const Film* film) override;
};
struct DirectLightingIntegrator : public Integrator {
DirectLightSampleStrategy strategy = DirectLightSampleStrategy::All;
int maxdepth = 5;
int pixelbounds[4] = { 0, -1, 0, -1 };
virtual ~DirectLightingIntegrator() override {}
virtual IntegratorType type() const override { return IntegratorType::DirectLighting; }
virtual void compute_defaults(const Film* film) override;
};
struct MLTIntegrator : public Integrator {
int maxdepth = 5;
int bootstrapsamples = 100000;
int chains = 1000;
int mutationsperpixel = 100;
float largestprobability = 0.3f;
float sigma = 0.01f;
virtual ~MLTIntegrator() override {}
virtual IntegratorType type() const override { return IntegratorType::MLT; }
};
struct PathIntegrator : public Integrator {
int maxdepth = 5;
int pixelbounds[4] = { 0, -1, 0, -1 }; // endx <= startx or endy <= starty means "whole image".
float rrthreshold = 1.0f;
LightSampleStrategy lightsamplestrategy = LightSampleStrategy::Spatial;
virtual ~PathIntegrator() override {}
virtual IntegratorType type() const override { return IntegratorType::Path; }
virtual void compute_defaults(const Film* film) override;
};
struct SPPMIntegrator : public Integrator {
int maxdepth = 5;
int maxiterations = 64;
int photonsperiteration = -1;
int imagewritefrequency = 1 << 30;
float radius = 1.0f;
virtual ~SPPMIntegrator() override {}
virtual IntegratorType type() const override { return IntegratorType::SPPM; }
};
struct WhittedIntegrator : public Integrator {
int maxdepth = 5;
int pixelbounds[4] = { 0, -1, 0, -1 };
virtual ~WhittedIntegrator() override {}
virtual IntegratorType type() const override { return IntegratorType::Whitted; }
virtual void compute_defaults(const Film* film) override;
};
struct VolPathIntegrator : public Integrator {
int maxdepth = 5;
int pixelbounds[4] = { 0, -1, 0, -1 }; // endx < startx or endy < starty means "whole image".
float rrthreshold = 1.0f;
LightSampleStrategy lightsamplestrategy = LightSampleStrategy::Spatial;
virtual ~VolPathIntegrator() override {}
virtual IntegratorType type() const override { return IntegratorType::VolPath; }
virtual void compute_defaults(const Film* film) override;
};
struct AOIntegrator : public Integrator {
int pixelbounds[4] = { 0, -1, 0, -1 }; // endx < startx or endy < starty means "whole image".
bool cossample = true;
int nsamples = 64;
virtual ~AOIntegrator() override {}
virtual IntegratorType type() const override { return IntegratorType::AO; }
virtual void compute_defaults(const Film* film) override;
};
//
// Light types
//
enum class LightType {
Distant,
Goniometric,
Infinite,
Point,
Projection,
Spot,
};
struct Light {
Transform lightToWorld; // row major.
float scale[3] = { 1.0f, 1.0f, 1.0f };
virtual ~Light() {}
virtual LightType type() const = 0;
};
struct DistantLight : public Light {
float L[3] = { 1.0f, 1.0f, 1.0f };
float from[3] = { 0.0f, 0.0f, 0.0f };
float to[3] = { 0.0f, 0.0f, 1.0f };
virtual ~DistantLight() override {}
virtual LightType type() const override { return LightType::Distant; }
};
struct GoniometricLight : public Light {
float I[3] = { 1.0f, 1.0f, 1.0f };
char* mapname = nullptr;
virtual ~GoniometricLight() override { delete[] mapname; }
virtual LightType type() const override { return LightType::Goniometric; }
};
struct InfiniteLight : public Light {
float L[3] = { 1.0f, 1.0f, 1.0f };
int samples = 1;
char* mapname = nullptr;
virtual ~InfiniteLight() override { delete[] mapname; }
virtual LightType type() const override { return LightType::Infinite; }
};
struct PointLight : public Light {
float I[3] = { 1.0f, 1.0f, 1.0f };
float from[3] = { 0.0f, 0.0f, 0.0f };
virtual ~PointLight() override {}
virtual LightType type() const override { return LightType::Point; }
};
struct ProjectionLight : public Light {
float I[3] = { 1.0f, 1.0f, 1.0f };
float fov = 45.0f;
char* mapname = nullptr;
virtual ~ProjectionLight() override { delete[] mapname; }
virtual LightType type() const override { return LightType::Projection; }
};
struct SpotLight : public Light {
float I[3] = { 1.0f, 1.0f, 1.0f };
float from[3] = { 0.0f, 0.0f, 0.0f };
float to[3] = { 0.0f, 0.0f, 1.0f };
float coneangle = 30.0f;
float conedeltaangle = 5.0f;
virtual ~SpotLight() override {}
virtual LightType type() const override { return LightType::Spot; }
};
//
// Material types
//
enum class MaterialType {
Disney,
Fourier,
Glass,
Hair,
KdSubsurface,
Matte,
Metal,
Mirror,
Mix,
None,
Plastic,
Substrate,
Subsurface,
Translucent,
Uber,
};
struct Material {
const char* name = nullptr;
uint32_t bumpmap = kInvalidIndex;
virtual ~Material() { delete[] name; }
virtual MaterialType type() const = 0;
};
struct DisneyMaterial : public Material {
ColorTex color = { kInvalidIndex, {0.5f, 0.5f, 0.5f} };
FloatTex anisotropic = { kInvalidIndex, 0.0f };
FloatTex clearcoat = { kInvalidIndex, 0.0f };
FloatTex clearcoatgloss = { kInvalidIndex, 1.0f };
FloatTex eta = { kInvalidIndex, 1.5f };
FloatTex metallic = { kInvalidIndex, 0.0f };
FloatTex roughness = { kInvalidIndex, 0.5f };
ColorTex scatterdistance = { kInvalidIndex, {0.0f, 0.0f, 0.0f} };
FloatTex sheen = { kInvalidIndex, 0.0f };
FloatTex sheentint = { kInvalidIndex, 0.5f };
FloatTex spectrans = { kInvalidIndex, 0.0f };
FloatTex speculartint = { kInvalidIndex, 0.0f };
bool thin = false;
ColorTex difftrans = { kInvalidIndex, {1.0f, 1.0f, 1.0f} }; // only used if `thin == true`
ColorTex flatness = { kInvalidIndex, {0.0f, 0.0f, 0.0f} }; // only used if `thin == true`
virtual ~DisneyMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Disney; }
};
struct FourierMaterial : public Material {
char* bsdffile = nullptr;
virtual ~FourierMaterial() override { delete[] bsdffile; }
virtual MaterialType type() const override { return MaterialType::Fourier; }
};
struct GlassMaterial : public Material {
ColorTex Kr = { kInvalidIndex, {1.0f, 1.0f, 1.0f} };
ColorTex Kt = { kInvalidIndex, {1.0f, 1.0f, 1.0f} };
FloatTex eta = { kInvalidIndex, 1.5f };
FloatTex uroughness = { kInvalidIndex, 0.0f };
FloatTex vroughness = { kInvalidIndex, 0.0f };
bool remaproughness = true;
virtual ~GlassMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Glass; }
};
struct HairMaterial : public Material {
ColorTex sigma_a = { kInvalidIndex, {0.0f, 0.0f, 0.0f} };
ColorTex color = { kInvalidIndex, {0.0f, 0.0f, 0.0f} };
FloatTex eumelanin = { kInvalidIndex, 1.3f };
FloatTex pheomelanin = { kInvalidIndex, 0.0f };
FloatTex eta = { kInvalidIndex, 1.55f };
FloatTex beta_m = { kInvalidIndex, 0.3f };
FloatTex beta_n = { kInvalidIndex, 0.3f };
FloatTex alpha = { kInvalidIndex, 2.0f };
bool has_sigma_a = false;
bool has_color = false;
virtual ~HairMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Hair; }
};
struct KdSubsurfaceMaterial : public Material {
ColorTex Kd = { kInvalidIndex, {0.5f, 0.5f, 0.5f} };
ColorTex mfp = { kInvalidIndex, {0.5f, 0.5f, 0.5f} };
FloatTex eta = { kInvalidIndex, 1.3f };
ColorTex Kr = { kInvalidIndex, {1.0f, 1.0f, 1.0f} };
ColorTex Kt = { kInvalidIndex, {1.0f, 1.0f, 1.0f} };
FloatTex uroughness = { kInvalidIndex, 0.0f };
FloatTex vroughness = { kInvalidIndex, 0.0f };
bool remaproughness = true;
virtual ~KdSubsurfaceMaterial() override {}
virtual MaterialType type() const override { return MaterialType::KdSubsurface; }
};
struct MatteMaterial : public Material {
ColorTex Kd = { kInvalidIndex, {0.5f, 0.5f, 0.5f} };
FloatTex sigma = { kInvalidIndex, 0.0f };
virtual ~MatteMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Matte; }
};
struct MetalMaterial : public Material {
ColorTex eta = { kInvalidIndex, {0.5f, 0.5f, 0.5f} }; // TODO: indices of refraction for copper
ColorTex k = { kInvalidIndex, {0.5f, 0.5f, 0.5f} }; // TODO: absorption coefficients for copper
FloatTex uroughness = { kInvalidIndex, 0.01f };
FloatTex vroughness = { kInvalidIndex, 0.01f };
bool remaproughness = true;
virtual ~MetalMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Metal; }
};
struct MirrorMaterial : public Material {
ColorTex Kr = { kInvalidIndex, {0.9f, 0.9f, 0.9f} };
virtual ~MirrorMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Mirror; }
};
struct MixMaterial : public Material {
ColorTex amount = { kInvalidIndex, {0.5f, 0.5f, 0.5f} };
uint32_t namedmaterial1 = kInvalidIndex;
uint32_t namedmaterial2 = kInvalidIndex;
virtual ~MixMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Mix; }
};
struct NoneMaterial : public Material {
virtual ~NoneMaterial() override {}
virtual MaterialType type() const override { return MaterialType::None; }
};
struct PlasticMaterial : public Material {
ColorTex Kd = { kInvalidIndex, {0.25f, 0.25f, 0.25f} };
ColorTex Ks = { kInvalidIndex, {0.25f, 0.25f, 0.25f} };
FloatTex roughness = { kInvalidIndex, 0.1f };
bool remaproughness = true;
virtual ~PlasticMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Plastic; }
};
struct SubstrateMaterial : public Material {
ColorTex Kd = { kInvalidIndex, {0.5f, 0.5f, 0.5f} };
ColorTex Ks = { kInvalidIndex, {0.5f, 0.5f, 0.5f} };
FloatTex uroughness = { kInvalidIndex, 0.1f };
FloatTex vroughness = { kInvalidIndex, 0.1f };
bool remaproughness = true;
virtual ~SubstrateMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Substrate; }
};
struct SubsurfaceMaterial : public Material {
char* coefficients = nullptr; // name of the measured subsurface scattering coefficients
ColorTex sigma_a = { kInvalidIndex, {0.0011f, 0.0024f, 0.014f} };
ColorTex sigma_prime_s = { kInvalidIndex, {2.55f, 3.12f, 3.77f} };
float scale = 1.0f;
FloatTex eta = { kInvalidIndex, 1.33f };
ColorTex Kr = { kInvalidIndex, {1.0f, 1.0f, 1.0f} };
ColorTex Kt = { kInvalidIndex, {1.0f, 1.0f, 1.0f} };
FloatTex uroughness = { kInvalidIndex, 0.0f };
FloatTex vroughness = { kInvalidIndex, 0.0f };
bool remaproughness = true;
virtual ~SubsurfaceMaterial() override { delete[] coefficients; }
virtual MaterialType type() const override { return MaterialType::Subsurface; }
};
struct TranslucentMaterial : public Material {
ColorTex Kd = { kInvalidIndex, {0.25f, 0.25f, 0.25f} };
ColorTex Ks = { kInvalidIndex, {0.25f, 0.25f, 0.25f} };
ColorTex reflect = { kInvalidIndex, {0.5f, 0.5f, 0.5f} };
ColorTex transmit = { kInvalidIndex, {0.5f, 0.5f, 0.5f} };
FloatTex roughness = { kInvalidIndex, 0.1f };
bool remaproughness = true;
virtual ~TranslucentMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Translucent; }
};
struct UberMaterial : public Material {
ColorTex Kd = { kInvalidIndex, {0.25f, 0.25f, 0.25f} };
ColorTex Ks = { kInvalidIndex, {0.25f, 0.25f, 0.25f} };
ColorTex Kr = { kInvalidIndex, {0.0f, 0.0f, 0.0f} };
ColorTex Kt = { kInvalidIndex, {0.0f, 0.0f, 0.0f} };
FloatTex eta = { kInvalidIndex, 1.5f };
ColorTex opacity = { kInvalidIndex, {1.0f, 1.0f, 1.0f} };
FloatTex uroughness = { kInvalidIndex, 0.1f };
FloatTex vroughness = { kInvalidIndex, 0.1f };
bool remaproughness = true;
virtual ~UberMaterial() override {}
virtual MaterialType type() const override { return MaterialType::Uber; }
};
//
// Medium types
//
enum class MediumType {
Homogeneous,
Heterogeneous,
};
struct Medium {
const char* mediumName = nullptr;
float sigma_a[3] = { 0.0011f, 0.0024f, 0.0014f };
float sigma_s[3] = { 2.55f, 3.21f, 3.77f};
char* preset = nullptr;
float g = 0.0f;
float scale = 1.0f;
virtual ~Medium() {
delete[] mediumName;
delete[] preset;
}
virtual MediumType type() const = 0;
};
struct HomogeneousMedium : public Medium {
virtual ~HomogeneousMedium() override {}
virtual MediumType type() const override { return MediumType::Homogeneous; }
};
struct HeterogeneousMedium : public Medium {
float p0[3] = { 0.0f, 0.0f, 0.0f };
float p1[3] = { 1.0f, 1.0f, 1.0f };
int nx = 1;
int ny = 1;
int nz = 1;
float* density = nullptr;
virtual ~HeterogeneousMedium() override { delete[] density; }
virtual MediumType type() const override { return MediumType::Heterogeneous; }
};
//
// Sampler types
//
enum class SamplerType {
ZeroTwoSequence,
LowDiscrepancy, // An alias for ZeroTwoSequence, kept for backwards compatibility
Halton,
MaxMinDist,
Random,
Sobol,
Stratified,
};
struct Sampler {
virtual ~Sampler() {}
virtual SamplerType type() const = 0;
};
struct ZeroTwoSequenceSampler : public Sampler {
int pixelsamples = 16;
virtual ~ZeroTwoSequenceSampler() override {}
virtual SamplerType type() const override { return SamplerType::ZeroTwoSequence; }
};
struct HaltonSampler : public Sampler {
int pixelsamples = 16;
virtual ~HaltonSampler() override {}
virtual SamplerType type() const override { return SamplerType::Halton; }
};
struct MaxMinDistSampler : public Sampler {
int pixelsamples = 16;
virtual ~MaxMinDistSampler() override {}
virtual SamplerType type() const override { return SamplerType::MaxMinDist; }
};
struct RandomSampler : public Sampler {
int pixelsamples = 16;
virtual ~RandomSampler() override {}
virtual SamplerType type() const override { return SamplerType::Random; }
};
struct SobolSampler : public Sampler {
int pixelsamples = 16;
virtual ~SobolSampler() override {}
virtual SamplerType type() const override { return SamplerType::Sobol; }
};
struct StratifiedSampler : public Sampler {
bool jitter = true;
int xsamples = 2;
int ysamples = 2;
virtual ~StratifiedSampler() override {}
virtual SamplerType type() const override { return SamplerType::Stratified; }
};
//
// Shape types
//
enum class ShapeType {
Cone,
Curve,
Cylinder,
Disk,
Hyperboloid,
Paraboloid,
Sphere,
TriangleMesh,
HeightField,
LoopSubdiv,
Nurbs,
PLYMesh,
};