codecraft 0.2.0

A minimalist 3D game engine built on parts of Bevy (ECS, color) with wgpu and winit: OpenPBR materials, clustered lighting, a yakui-drawn UI, audio and gamepad haptics; its binary maps any folder, and the symbols of its Rust files, as a 3D wall of boxes
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
//! `open_pbr_surface` (nodedef `ND_open_pbr_surface_surfaceshader` 1.1.1, 41 inputs).
//! Generated from `mtlx/open_pbr_surface.mtlx` by `openpbr-gen`; do not edit by hand.

#![allow(clippy::excessive_precision)]

use super::types::{Color3, InputError, InputSpec, Value, ValueType, Vector3};

pub const NODEDEF_NAME: &str = "ND_open_pbr_surface_surfaceshader";
pub const NODE_NAME: &str = "open_pbr_surface";
pub const VERSION: &str = "1.1.1";
pub const NODE_GROUP: &str = "pbr";
pub const OUTPUT_TYPE: &str = "surfaceshader";

/// OpenPBR Surface Shading Model: one field per nodedef input, in declaration order.
/// [`Default`] yields the nodedef defaults; `None` on the geometry inputs means the geometric default.
#[derive(Debug, Clone, PartialEq)]
pub struct OpenPbrSurface {
    /// Multiplier on the intensity of the reflection from the diffuse and metallic base.
    pub base_weight: f32,

    /// Color of the reflection from the diffuse and metallic base.
    pub base_color: Color3,

    /// Roughness of the diffuse reflection. Higher values cause the surface to appear flatter.
    pub base_diffuse_roughness: f32,

    /// Specifies how metallic the base material appears (dials the base from pure dielectric to pure metal).
    pub base_metalness: f32,

    /// Multiplies the specular reflectivity.
    pub specular_weight: f32,

    /// Color of the specular reflection (controls the physical edge-tint for metals, and a non-physical overall tint for dielectrics).
    pub specular_color: Color3,

    /// The roughness of the specular reflection. Lower numbers produce sharper reflections, higher numbers produce blurrier reflections.
    pub specular_roughness: f32,

    /// Index of refraction of the dielectric base.
    pub specular_ior: f32,

    /// The directional bias of the roughness of the metal/dielectric base, resulting in increasingly stretched highlights along the tangent direction.
    pub specular_roughness_anisotropy: f32,

    /// Mixture weight between the transparent and opaque dielectric base. The greater the value the more transparent the material.
    pub transmission_weight: f32,

    /// Controls color of the transparent base due to Beer's law volumetric absorption under the surface (reverts to a non-physical tint when transmission_depth is zero).
    pub transmission_color: Color3,

    /// Specifies the distance light travels inside the transparent base before it becomes exactly the transmission_color according to Beer's law.
    pub transmission_depth: f32,

    /// Controls the color of light volumetrically scattered inside the transparent base. Suitable for materials with visually significant scattering such as honey, fruit juice, murky water, opalescent glass, or milky glass.
    pub transmission_scatter: Color3,

    /// The amount of directional bias, or anisotropy, of the volumetric scattering in the transparent base.
    pub transmission_scatter_anisotropy: f32,

    /// Linearly scales the amount of dispersion.
    pub transmission_dispersion_scale: f32,

    /// Physical Abbe number of the dielectric medium, describing how much the dielectric index of refraction varies across wavelengths.
    pub transmission_dispersion_abbe_number: f32,

    /// Mixture weight which dials the opaque dielectric base between diffuse reflection and subsurface scattering. A value of 1.0 indicates full subsurface scattering and a value 0 for diffuse reflection only.
    pub subsurface_weight: f32,

    /// The observed reflection color of the subsurface scattering medium.
    pub subsurface_color: Color3,

    /// Length scale of the subsurface scattering mean free path.
    pub subsurface_radius: f32,

    /// RGB multiplier to subsurface_radius, giving the per-channel scattering mean-free-paths.
    pub subsurface_radius_scale: Color3,

    /// Controls the phase-function of subsurface scattering, where zero scatters light evenly, positive values scatter forwards, and negative values scatter backwards.
    pub subsurface_scatter_anisotropy: f32,

    /// The presence weight of a fuzz layer that can be used to approximate microfibers, for fabrics such as velvet and satin as well as dust grains.
    pub fuzz_weight: f32,

    /// The color of the fuzz layer.
    pub fuzz_color: Color3,

    /// The roughness of the fuzz layer.
    pub fuzz_roughness: f32,

    /// The presence weight of a reflective clear-coat layer on top of the material. Use for materials such as car paint or an oily layer.
    pub coat_weight: f32,

    /// The color of the clear-coat layer's transparency, due to absorption in the coat.
    pub coat_color: Color3,

    /// The roughness of the clear-coat reflections. The lower the value, the sharper the reflection.
    pub coat_roughness: f32,

    /// The directional bias of the roughness of the clear-coat layer, resulting in increasingly stretched highlights along the coat tangent direction.
    pub coat_roughness_anisotropy: f32,

    /// The index of refraction of the clear-coat layer.
    pub coat_ior: f32,

    /// Modulates the physical coat darkening effect.
    pub coat_darkening: f32,

    /// Coverage weight of the thin-film. Use for materials such as multi-tone car paint or soap bubbles.
    pub thin_film_weight: f32,

    /// The thickness of the thin-film layer on the base (in micrometers).
    pub thin_film_thickness: f32,

    /// The index of refraction of the thin-film.
    pub thin_film_ior: f32,

    /// The amount of emitted light, as a luminance in nits.
    pub emission_luminance: f32,

    /// The color of the emitted light.
    pub emission_color: Color3,

    /// The opacity of the entire material.
    pub geometry_opacity: f32,

    /// If true the surface is double-sided and represents an infinitesimally thin shell. Suitable for extremely geometrically thin objects such as leaves or paper.
    pub geometry_thin_walled: bool,

    /// Input geometric normal
    pub geometry_normal: Option<Vector3>,

    /// Input normal for coat layer
    pub geometry_coat_normal: Option<Vector3>,

    /// Input geometric tangent
    pub geometry_tangent: Option<Vector3>,

    /// Input geometric tangent for coat layer
    pub geometry_coat_tangent: Option<Vector3>,
}

impl Default for OpenPbrSurface {
    fn default() -> Self {
        Self {
            base_weight: 1.0,
            base_color: Color3::new(0.8, 0.8, 0.8),
            base_diffuse_roughness: 0.0,
            base_metalness: 0.0,
            specular_weight: 1.0,
            specular_color: Color3::new(1.0, 1.0, 1.0),
            specular_roughness: 0.3,
            specular_ior: 1.5,
            specular_roughness_anisotropy: 0.0,
            transmission_weight: 0.0,
            transmission_color: Color3::new(1.0, 1.0, 1.0),
            transmission_depth: 0.0,
            transmission_scatter: Color3::new(0.0, 0.0, 0.0),
            transmission_scatter_anisotropy: 0.0,
            transmission_dispersion_scale: 0.0,
            transmission_dispersion_abbe_number: 20.0,
            subsurface_weight: 0.0,
            subsurface_color: Color3::new(0.8, 0.8, 0.8),
            subsurface_radius: 1.0,
            subsurface_radius_scale: Color3::new(1.0, 0.5, 0.25),
            subsurface_scatter_anisotropy: 0.0,
            fuzz_weight: 0.0,
            fuzz_color: Color3::new(1.0, 1.0, 1.0),
            fuzz_roughness: 0.5,
            coat_weight: 0.0,
            coat_color: Color3::new(1.0, 1.0, 1.0),
            coat_roughness: 0.0,
            coat_roughness_anisotropy: 0.0,
            coat_ior: 1.6,
            coat_darkening: 1.0,
            thin_film_weight: 0.0,
            thin_film_thickness: 0.5,
            thin_film_ior: 1.4,
            emission_luminance: 0.0,
            emission_color: Color3::new(1.0, 1.0, 1.0),
            geometry_opacity: 1.0,
            geometry_thin_walled: false,
            geometry_normal: None,
            geometry_coat_normal: None,
            geometry_tangent: None,
            geometry_coat_tangent: None,
        }
    }
}

/// Metadata for every input, in nodedef order.
pub static INPUTS: [InputSpec; 41] = [
    InputSpec {
        name: "base_weight",
        ty: ValueType::Float,
        default: Some(Value::Float(1.0)),
        default_geom_prop: None,
        ui_name: "Base Weight",
        ui_folder: "Base",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Multiplier on the intensity of the reflection from the diffuse and metallic base.",
    },
    InputSpec {
        name: "base_color",
        ty: ValueType::Color3,
        default: Some(Value::Color3(Color3::new(0.8, 0.8, 0.8))),
        default_geom_prop: None,
        ui_name: "Base Color",
        ui_folder: "Base",
        ui_min: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        ui_max: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Color of the reflection from the diffuse and metallic base.",
    },
    InputSpec {
        name: "base_diffuse_roughness",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Base Diffuse Roughness",
        ui_folder: "Base",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Roughness of the diffuse reflection. Higher values cause the surface to appear flatter.",
    },
    InputSpec {
        name: "base_metalness",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Base Metalness",
        ui_folder: "Base",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Specifies how metallic the base material appears (dials the base from pure dielectric to pure metal).",
    },
    InputSpec {
        name: "specular_weight",
        ty: ValueType::Float,
        default: Some(Value::Float(1.0)),
        default_geom_prop: None,
        ui_name: "Specular Weight",
        ui_folder: "Specular",
        ui_min: Some(Value::Float(0.0)),
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: Some(Value::Float(1.0)),
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Multiplies the specular reflectivity.",
    },
    InputSpec {
        name: "specular_color",
        ty: ValueType::Color3,
        default: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        default_geom_prop: None,
        ui_name: "Specular Color",
        ui_folder: "Specular",
        ui_min: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        ui_max: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Color of the specular reflection (controls the physical edge-tint for metals, and a non-physical overall tint for dielectrics).",
    },
    InputSpec {
        name: "specular_roughness",
        ty: ValueType::Float,
        default: Some(Value::Float(0.3)),
        default_geom_prop: None,
        ui_name: "Specular Roughness",
        ui_folder: "Specular",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "The roughness of the specular reflection. Lower numbers produce sharper reflections, higher numbers produce blurrier reflections.",
    },
    InputSpec {
        name: "specular_ior",
        ty: ValueType::Float,
        default: Some(Value::Float(1.5)),
        default_geom_prop: None,
        ui_name: "Specular Index of Refraction",
        ui_folder: "Specular",
        ui_min: Some(Value::Float(0.0)),
        ui_max: None,
        ui_soft_min: Some(Value::Float(1.0)),
        ui_soft_max: Some(Value::Float(3.0)),
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Index of refraction of the dielectric base.",
    },
    InputSpec {
        name: "specular_roughness_anisotropy",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Specular Anisotropy",
        ui_folder: "Specular",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "The directional bias of the roughness of the metal/dielectric base, resulting in increasingly stretched highlights along the tangent direction.",
    },
    InputSpec {
        name: "transmission_weight",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Transmission Weight",
        ui_folder: "Transmission",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: Some("transparency"),
        doc: "Mixture weight between the transparent and opaque dielectric base. The greater the value the more transparent the material.",
    },
    InputSpec {
        name: "transmission_color",
        ty: ValueType::Color3,
        default: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        default_geom_prop: None,
        ui_name: "Transmission Color",
        ui_folder: "Transmission",
        ui_min: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        ui_max: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Controls color of the transparent base due to Beer's law volumetric absorption under the surface (reverts to a non-physical tint when transmission_depth is zero).",
    },
    InputSpec {
        name: "transmission_depth",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Transmission Depth",
        ui_folder: "Transmission",
        ui_min: Some(Value::Float(0.0)),
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: Some(Value::Float(1.0)),
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Specifies the distance light travels inside the transparent base before it becomes exactly the transmission_color according to Beer's law.",
    },
    InputSpec {
        name: "transmission_scatter",
        ty: ValueType::Color3,
        default: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        default_geom_prop: None,
        ui_name: "Transmission Scatter",
        ui_folder: "Transmission",
        ui_min: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        ui_max: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Controls the color of light volumetrically scattered inside the transparent base. Suitable for materials with visually significant scattering such as honey, fruit juice, murky water, opalescent glass, or milky glass.",
    },
    InputSpec {
        name: "transmission_scatter_anisotropy",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Transmission Anisotropy",
        ui_folder: "Transmission",
        ui_min: Some(Value::Float(-1.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "The amount of directional bias, or anisotropy, of the volumetric scattering in the transparent base.",
    },
    InputSpec {
        name: "transmission_dispersion_scale",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Transmission Dispersion Scale",
        ui_folder: "Transmission",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Linearly scales the amount of dispersion.",
    },
    InputSpec {
        name: "transmission_dispersion_abbe_number",
        ty: ValueType::Float,
        default: Some(Value::Float(20.0)),
        default_geom_prop: None,
        ui_name: "Transmission Dispersion Abbe Number",
        ui_folder: "Transmission",
        ui_min: Some(Value::Float(0.0)),
        ui_max: None,
        ui_soft_min: Some(Value::Float(9.0)),
        ui_soft_max: Some(Value::Float(91.0)),
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Physical Abbe number of the dielectric medium, describing how much the dielectric index of refraction varies across wavelengths.",
    },
    InputSpec {
        name: "subsurface_weight",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Subsurface Weight",
        ui_folder: "Subsurface",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Mixture weight which dials the opaque dielectric base between diffuse reflection and subsurface scattering. A value of 1.0 indicates full subsurface scattering and a value 0 for diffuse reflection only.",
    },
    InputSpec {
        name: "subsurface_color",
        ty: ValueType::Color3,
        default: Some(Value::Color3(Color3::new(0.8, 0.8, 0.8))),
        default_geom_prop: None,
        ui_name: "Subsurface Color",
        ui_folder: "Subsurface",
        ui_min: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        ui_max: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "The observed reflection color of the subsurface scattering medium.",
    },
    InputSpec {
        name: "subsurface_radius",
        ty: ValueType::Float,
        default: Some(Value::Float(1.0)),
        default_geom_prop: None,
        ui_name: "Subsurface Radius",
        ui_folder: "Subsurface",
        ui_min: Some(Value::Float(0.0)),
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: Some(Value::Float(1.0)),
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Length scale of the subsurface scattering mean free path.",
    },
    InputSpec {
        name: "subsurface_radius_scale",
        ty: ValueType::Color3,
        default: Some(Value::Color3(Color3::new(1.0, 0.5, 0.25))),
        default_geom_prop: None,
        ui_name: "Subsurface Radius Scale",
        ui_folder: "Subsurface",
        ui_min: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        ui_max: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "RGB multiplier to subsurface_radius, giving the per-channel scattering mean-free-paths.",
    },
    InputSpec {
        name: "subsurface_scatter_anisotropy",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Subsurface Anisotropy",
        ui_folder: "Subsurface",
        ui_min: Some(Value::Float(-1.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Controls the phase-function of subsurface scattering, where zero scatters light evenly, positive values scatter forwards, and negative values scatter backwards.",
    },
    InputSpec {
        name: "fuzz_weight",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Fuzz Weight",
        ui_folder: "Fuzz",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "The presence weight of a fuzz layer that can be used to approximate microfibers, for fabrics such as velvet and satin as well as dust grains.",
    },
    InputSpec {
        name: "fuzz_color",
        ty: ValueType::Color3,
        default: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        default_geom_prop: None,
        ui_name: "Fuzz Color",
        ui_folder: "Fuzz",
        ui_min: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        ui_max: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "The color of the fuzz layer.",
    },
    InputSpec {
        name: "fuzz_roughness",
        ty: ValueType::Float,
        default: Some(Value::Float(0.5)),
        default_geom_prop: None,
        ui_name: "Fuzz Roughness",
        ui_folder: "Fuzz",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "The roughness of the fuzz layer.",
    },
    InputSpec {
        name: "coat_weight",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Coat Weight",
        ui_folder: "Coat",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "The presence weight of a reflective clear-coat layer on top of the material. Use for materials such as car paint or an oily layer.",
    },
    InputSpec {
        name: "coat_color",
        ty: ValueType::Color3,
        default: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        default_geom_prop: None,
        ui_name: "Coat Color",
        ui_folder: "Coat",
        ui_min: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        ui_max: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "The color of the clear-coat layer's transparency, due to absorption in the coat.",
    },
    InputSpec {
        name: "coat_roughness",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Coat Roughness",
        ui_folder: "Coat",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "The roughness of the clear-coat reflections. The lower the value, the sharper the reflection.",
    },
    InputSpec {
        name: "coat_roughness_anisotropy",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Coat Anisotropy",
        ui_folder: "Coat",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "The directional bias of the roughness of the clear-coat layer, resulting in increasingly stretched highlights along the coat tangent direction.",
    },
    InputSpec {
        name: "coat_ior",
        ty: ValueType::Float,
        default: Some(Value::Float(1.6)),
        default_geom_prop: None,
        ui_name: "Coat Index of Refraction",
        ui_folder: "Coat",
        ui_min: Some(Value::Float(0.0)),
        ui_max: None,
        ui_soft_min: Some(Value::Float(1.0)),
        ui_soft_max: Some(Value::Float(3.0)),
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "The index of refraction of the clear-coat layer.",
    },
    InputSpec {
        name: "coat_darkening",
        ty: ValueType::Float,
        default: Some(Value::Float(1.0)),
        default_geom_prop: None,
        ui_name: "Coat Darkening",
        ui_folder: "Coat",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Modulates the physical coat darkening effect.",
    },
    InputSpec {
        name: "thin_film_weight",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Thin Film Weight",
        ui_folder: "Thin Film",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "Coverage weight of the thin-film. Use for materials such as multi-tone car paint or soap bubbles.",
    },
    InputSpec {
        name: "thin_film_thickness",
        ty: ValueType::Float,
        default: Some(Value::Float(0.5)),
        default_geom_prop: None,
        ui_name: "Thin Film Thickness",
        ui_folder: "Thin Film",
        ui_min: Some(Value::Float(0.0)),
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: Some(Value::Float(1.0)),
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "The thickness of the thin-film layer on the base (in micrometers).",
    },
    InputSpec {
        name: "thin_film_ior",
        ty: ValueType::Float,
        default: Some(Value::Float(1.4)),
        default_geom_prop: None,
        ui_name: "Thin Film Index of Refraction",
        ui_folder: "Thin Film",
        ui_min: Some(Value::Float(0.0)),
        ui_max: None,
        ui_soft_min: Some(Value::Float(1.0)),
        ui_soft_max: Some(Value::Float(3.0)),
        ui_advanced: true,
        uniform: false,
        hint: None,
        doc: "The index of refraction of the thin-film.",
    },
    InputSpec {
        name: "emission_luminance",
        ty: ValueType::Float,
        default: Some(Value::Float(0.0)),
        default_geom_prop: None,
        ui_name: "Emission Luminance",
        ui_folder: "Emission",
        ui_min: Some(Value::Float(0.0)),
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: Some(Value::Float(1000.0)),
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "The amount of emitted light, as a luminance in nits.",
    },
    InputSpec {
        name: "emission_color",
        ty: ValueType::Color3,
        default: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        default_geom_prop: None,
        ui_name: "Emission Color",
        ui_folder: "Emission",
        ui_min: Some(Value::Color3(Color3::new(0.0, 0.0, 0.0))),
        ui_max: Some(Value::Color3(Color3::new(1.0, 1.0, 1.0))),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "The color of the emitted light.",
    },
    InputSpec {
        name: "geometry_opacity",
        ty: ValueType::Float,
        default: Some(Value::Float(1.0)),
        default_geom_prop: None,
        ui_name: "Opacity",
        ui_folder: "Geometry",
        ui_min: Some(Value::Float(0.0)),
        ui_max: Some(Value::Float(1.0)),
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: Some("opacity"),
        doc: "The opacity of the entire material.",
    },
    InputSpec {
        name: "geometry_thin_walled",
        ty: ValueType::Boolean,
        default: Some(Value::Boolean(false)),
        default_geom_prop: None,
        ui_name: "Thin Walled",
        ui_folder: "Geometry",
        ui_min: None,
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: true,
        uniform: true,
        hint: None,
        doc: "If true the surface is double-sided and represents an infinitesimally thin shell. Suitable for extremely geometrically thin objects such as leaves or paper.",
    },
    InputSpec {
        name: "geometry_normal",
        ty: ValueType::Vector3,
        default: None,
        default_geom_prop: Some("Nworld"),
        ui_name: "Normal",
        ui_folder: "Geometry",
        ui_min: None,
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Input geometric normal",
    },
    InputSpec {
        name: "geometry_coat_normal",
        ty: ValueType::Vector3,
        default: None,
        default_geom_prop: Some("Nworld"),
        ui_name: "Coat Normal",
        ui_folder: "Geometry",
        ui_min: None,
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Input normal for coat layer",
    },
    InputSpec {
        name: "geometry_tangent",
        ty: ValueType::Vector3,
        default: None,
        default_geom_prop: Some("Tworld"),
        ui_name: "Tangent",
        ui_folder: "Geometry",
        ui_min: None,
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Input geometric tangent",
    },
    InputSpec {
        name: "geometry_coat_tangent",
        ty: ValueType::Vector3,
        default: None,
        default_geom_prop: Some("Tworld"),
        ui_name: "Coat Tangent",
        ui_folder: "Geometry",
        ui_min: None,
        ui_max: None,
        ui_soft_min: None,
        ui_soft_max: None,
        ui_advanced: false,
        uniform: false,
        hint: None,
        doc: "Input geometric tangent for coat layer",
    },
];

impl OpenPbrSurface {
    /// Metadata for every input, in nodedef order.
    pub const INPUTS: &'static [InputSpec] = &INPUTS;

    /// Names of all inputs, in nodedef order.
    pub const INPUT_NAMES: [&'static str; 41] = [
        "base_weight",
        "base_color",
        "base_diffuse_roughness",
        "base_metalness",
        "specular_weight",
        "specular_color",
        "specular_roughness",
        "specular_ior",
        "specular_roughness_anisotropy",
        "transmission_weight",
        "transmission_color",
        "transmission_depth",
        "transmission_scatter",
        "transmission_scatter_anisotropy",
        "transmission_dispersion_scale",
        "transmission_dispersion_abbe_number",
        "subsurface_weight",
        "subsurface_color",
        "subsurface_radius",
        "subsurface_radius_scale",
        "subsurface_scatter_anisotropy",
        "fuzz_weight",
        "fuzz_color",
        "fuzz_roughness",
        "coat_weight",
        "coat_color",
        "coat_roughness",
        "coat_roughness_anisotropy",
        "coat_ior",
        "coat_darkening",
        "thin_film_weight",
        "thin_film_thickness",
        "thin_film_ior",
        "emission_luminance",
        "emission_color",
        "geometry_opacity",
        "geometry_thin_walled",
        "geometry_normal",
        "geometry_coat_normal",
        "geometry_tangent",
        "geometry_coat_tangent",
    ];

    /// Metadata for the input called `name`.
    pub fn input_spec(name: &str) -> Option<&'static InputSpec> {
        INPUTS.iter().find(|s| s.name == name)
    }

    /// Current value of the input `name`; `Ok(None)` means it is left at its geometric default.
    pub fn get(&self, name: &str) -> Result<Option<Value>, InputError> {
        Ok(match name {
            "base_weight" => Some(Value::Float(self.base_weight)),
            "base_color" => Some(Value::Color3(self.base_color)),
            "base_diffuse_roughness" => Some(Value::Float(self.base_diffuse_roughness)),
            "base_metalness" => Some(Value::Float(self.base_metalness)),
            "specular_weight" => Some(Value::Float(self.specular_weight)),
            "specular_color" => Some(Value::Color3(self.specular_color)),
            "specular_roughness" => Some(Value::Float(self.specular_roughness)),
            "specular_ior" => Some(Value::Float(self.specular_ior)),
            "specular_roughness_anisotropy" => {
                Some(Value::Float(self.specular_roughness_anisotropy))
            }
            "transmission_weight" => Some(Value::Float(self.transmission_weight)),
            "transmission_color" => Some(Value::Color3(self.transmission_color)),
            "transmission_depth" => Some(Value::Float(self.transmission_depth)),
            "transmission_scatter" => Some(Value::Color3(self.transmission_scatter)),
            "transmission_scatter_anisotropy" => {
                Some(Value::Float(self.transmission_scatter_anisotropy))
            }
            "transmission_dispersion_scale" => {
                Some(Value::Float(self.transmission_dispersion_scale))
            }
            "transmission_dispersion_abbe_number" => {
                Some(Value::Float(self.transmission_dispersion_abbe_number))
            }
            "subsurface_weight" => Some(Value::Float(self.subsurface_weight)),
            "subsurface_color" => Some(Value::Color3(self.subsurface_color)),
            "subsurface_radius" => Some(Value::Float(self.subsurface_radius)),
            "subsurface_radius_scale" => Some(Value::Color3(self.subsurface_radius_scale)),
            "subsurface_scatter_anisotropy" => {
                Some(Value::Float(self.subsurface_scatter_anisotropy))
            }
            "fuzz_weight" => Some(Value::Float(self.fuzz_weight)),
            "fuzz_color" => Some(Value::Color3(self.fuzz_color)),
            "fuzz_roughness" => Some(Value::Float(self.fuzz_roughness)),
            "coat_weight" => Some(Value::Float(self.coat_weight)),
            "coat_color" => Some(Value::Color3(self.coat_color)),
            "coat_roughness" => Some(Value::Float(self.coat_roughness)),
            "coat_roughness_anisotropy" => Some(Value::Float(self.coat_roughness_anisotropy)),
            "coat_ior" => Some(Value::Float(self.coat_ior)),
            "coat_darkening" => Some(Value::Float(self.coat_darkening)),
            "thin_film_weight" => Some(Value::Float(self.thin_film_weight)),
            "thin_film_thickness" => Some(Value::Float(self.thin_film_thickness)),
            "thin_film_ior" => Some(Value::Float(self.thin_film_ior)),
            "emission_luminance" => Some(Value::Float(self.emission_luminance)),
            "emission_color" => Some(Value::Color3(self.emission_color)),
            "geometry_opacity" => Some(Value::Float(self.geometry_opacity)),
            "geometry_thin_walled" => Some(Value::Boolean(self.geometry_thin_walled)),
            "geometry_normal" => self.geometry_normal.map(Value::Vector3),
            "geometry_coat_normal" => self.geometry_coat_normal.map(Value::Vector3),
            "geometry_tangent" => self.geometry_tangent.map(Value::Vector3),
            "geometry_coat_tangent" => self.geometry_coat_tangent.map(Value::Vector3),
            _ => return Err(InputError::Unknown(name.to_string())),
        })
    }

    /// Set the input `name` to `value`; the value must have the input's type.
    pub fn set(&mut self, name: &str, value: Value) -> Result<(), InputError> {
        match (name, value) {
            ("base_weight", Value::Float(v)) => self.base_weight = v,
            ("base_color", Value::Color3(v)) => self.base_color = v,
            ("base_diffuse_roughness", Value::Float(v)) => self.base_diffuse_roughness = v,
            ("base_metalness", Value::Float(v)) => self.base_metalness = v,
            ("specular_weight", Value::Float(v)) => self.specular_weight = v,
            ("specular_color", Value::Color3(v)) => self.specular_color = v,
            ("specular_roughness", Value::Float(v)) => self.specular_roughness = v,
            ("specular_ior", Value::Float(v)) => self.specular_ior = v,
            ("specular_roughness_anisotropy", Value::Float(v)) => {
                self.specular_roughness_anisotropy = v
            }
            ("transmission_weight", Value::Float(v)) => self.transmission_weight = v,
            ("transmission_color", Value::Color3(v)) => self.transmission_color = v,
            ("transmission_depth", Value::Float(v)) => self.transmission_depth = v,
            ("transmission_scatter", Value::Color3(v)) => self.transmission_scatter = v,
            ("transmission_scatter_anisotropy", Value::Float(v)) => {
                self.transmission_scatter_anisotropy = v
            }
            ("transmission_dispersion_scale", Value::Float(v)) => {
                self.transmission_dispersion_scale = v
            }
            ("transmission_dispersion_abbe_number", Value::Float(v)) => {
                self.transmission_dispersion_abbe_number = v
            }
            ("subsurface_weight", Value::Float(v)) => self.subsurface_weight = v,
            ("subsurface_color", Value::Color3(v)) => self.subsurface_color = v,
            ("subsurface_radius", Value::Float(v)) => self.subsurface_radius = v,
            ("subsurface_radius_scale", Value::Color3(v)) => self.subsurface_radius_scale = v,
            ("subsurface_scatter_anisotropy", Value::Float(v)) => {
                self.subsurface_scatter_anisotropy = v
            }
            ("fuzz_weight", Value::Float(v)) => self.fuzz_weight = v,
            ("fuzz_color", Value::Color3(v)) => self.fuzz_color = v,
            ("fuzz_roughness", Value::Float(v)) => self.fuzz_roughness = v,
            ("coat_weight", Value::Float(v)) => self.coat_weight = v,
            ("coat_color", Value::Color3(v)) => self.coat_color = v,
            ("coat_roughness", Value::Float(v)) => self.coat_roughness = v,
            ("coat_roughness_anisotropy", Value::Float(v)) => self.coat_roughness_anisotropy = v,
            ("coat_ior", Value::Float(v)) => self.coat_ior = v,
            ("coat_darkening", Value::Float(v)) => self.coat_darkening = v,
            ("thin_film_weight", Value::Float(v)) => self.thin_film_weight = v,
            ("thin_film_thickness", Value::Float(v)) => self.thin_film_thickness = v,
            ("thin_film_ior", Value::Float(v)) => self.thin_film_ior = v,
            ("emission_luminance", Value::Float(v)) => self.emission_luminance = v,
            ("emission_color", Value::Color3(v)) => self.emission_color = v,
            ("geometry_opacity", Value::Float(v)) => self.geometry_opacity = v,
            ("geometry_thin_walled", Value::Boolean(v)) => self.geometry_thin_walled = v,
            ("geometry_normal", Value::Vector3(v)) => self.geometry_normal = Some(v),
            ("geometry_coat_normal", Value::Vector3(v)) => self.geometry_coat_normal = Some(v),
            ("geometry_tangent", Value::Vector3(v)) => self.geometry_tangent = Some(v),
            ("geometry_coat_tangent", Value::Vector3(v)) => self.geometry_coat_tangent = Some(v),
            (_, value) => {
                let spec =
                    Self::input_spec(name).ok_or_else(|| InputError::Unknown(name.to_string()))?;
                return Err(InputError::TypeMismatch {
                    name: name.to_string(),
                    expected: spec.ty,
                    found: value.value_type(),
                });
            }
        }
        Ok(())
    }

    /// Parse `text` as the input's MaterialX type and assign it.
    pub fn set_from_str(&mut self, name: &str, text: &str) -> Result<(), InputError> {
        let spec = Self::input_spec(name).ok_or_else(|| InputError::Unknown(name.to_string()))?;
        let value = spec.ty.parse_value(text).map_err(InputError::Parse)?;
        self.set(name, value)
    }

    /// Reset the input `name` to its nodedef default.
    pub fn reset(&mut self, name: &str) -> Result<(), InputError> {
        let defaults = Self::default();
        match name {
            "base_weight" => self.base_weight = defaults.base_weight,
            "base_color" => self.base_color = defaults.base_color,
            "base_diffuse_roughness" => {
                self.base_diffuse_roughness = defaults.base_diffuse_roughness
            }
            "base_metalness" => self.base_metalness = defaults.base_metalness,
            "specular_weight" => self.specular_weight = defaults.specular_weight,
            "specular_color" => self.specular_color = defaults.specular_color,
            "specular_roughness" => self.specular_roughness = defaults.specular_roughness,
            "specular_ior" => self.specular_ior = defaults.specular_ior,
            "specular_roughness_anisotropy" => {
                self.specular_roughness_anisotropy = defaults.specular_roughness_anisotropy
            }
            "transmission_weight" => self.transmission_weight = defaults.transmission_weight,
            "transmission_color" => self.transmission_color = defaults.transmission_color,
            "transmission_depth" => self.transmission_depth = defaults.transmission_depth,
            "transmission_scatter" => self.transmission_scatter = defaults.transmission_scatter,
            "transmission_scatter_anisotropy" => {
                self.transmission_scatter_anisotropy = defaults.transmission_scatter_anisotropy
            }
            "transmission_dispersion_scale" => {
                self.transmission_dispersion_scale = defaults.transmission_dispersion_scale
            }
            "transmission_dispersion_abbe_number" => {
                self.transmission_dispersion_abbe_number =
                    defaults.transmission_dispersion_abbe_number
            }
            "subsurface_weight" => self.subsurface_weight = defaults.subsurface_weight,
            "subsurface_color" => self.subsurface_color = defaults.subsurface_color,
            "subsurface_radius" => self.subsurface_radius = defaults.subsurface_radius,
            "subsurface_radius_scale" => {
                self.subsurface_radius_scale = defaults.subsurface_radius_scale
            }
            "subsurface_scatter_anisotropy" => {
                self.subsurface_scatter_anisotropy = defaults.subsurface_scatter_anisotropy
            }
            "fuzz_weight" => self.fuzz_weight = defaults.fuzz_weight,
            "fuzz_color" => self.fuzz_color = defaults.fuzz_color,
            "fuzz_roughness" => self.fuzz_roughness = defaults.fuzz_roughness,
            "coat_weight" => self.coat_weight = defaults.coat_weight,
            "coat_color" => self.coat_color = defaults.coat_color,
            "coat_roughness" => self.coat_roughness = defaults.coat_roughness,
            "coat_roughness_anisotropy" => {
                self.coat_roughness_anisotropy = defaults.coat_roughness_anisotropy
            }
            "coat_ior" => self.coat_ior = defaults.coat_ior,
            "coat_darkening" => self.coat_darkening = defaults.coat_darkening,
            "thin_film_weight" => self.thin_film_weight = defaults.thin_film_weight,
            "thin_film_thickness" => self.thin_film_thickness = defaults.thin_film_thickness,
            "thin_film_ior" => self.thin_film_ior = defaults.thin_film_ior,
            "emission_luminance" => self.emission_luminance = defaults.emission_luminance,
            "emission_color" => self.emission_color = defaults.emission_color,
            "geometry_opacity" => self.geometry_opacity = defaults.geometry_opacity,
            "geometry_thin_walled" => self.geometry_thin_walled = defaults.geometry_thin_walled,
            "geometry_normal" => self.geometry_normal = defaults.geometry_normal,
            "geometry_coat_normal" => self.geometry_coat_normal = defaults.geometry_coat_normal,
            "geometry_tangent" => self.geometry_tangent = defaults.geometry_tangent,
            "geometry_coat_tangent" => self.geometry_coat_tangent = defaults.geometry_coat_tangent,
            _ => return Err(InputError::Unknown(name.to_string())),
        }
        Ok(())
    }

    /// Whether the input `name` currently holds its nodedef default.
    pub fn is_default(&self, name: &str) -> Result<bool, InputError> {
        Ok(self.get(name)? == Self::default().get(name)?)
    }

    /// All inputs whose value differs from the nodedef default, in nodedef order.
    pub fn changed_inputs(&self) -> Vec<(&'static str, Value)> {
        let defaults = Self::default();
        INPUTS
            .iter()
            .filter_map(|spec| {
                let value = self.get(spec.name).ok().flatten()?;
                (Some(value) != defaults.get(spec.name).ok().flatten())
                    .then_some((spec.name, value))
            })
            .collect()
    }
}