Repository navigation
Expand file tree
/
Copy pathmaterials.R
More file actions
1394 lines (1373 loc) · 61 KB
/
Copy pathmaterials.R
File metadata and controls
1394 lines (1373 loc) · 61 KB
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
#' Diffuse Material
#'
#' @param color Default `white`. The color of the surface. Can be either
#' a hexadecimal code, R color string, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param checkercolor Default `NA`. If not `NA`, determines the secondary color of the checkered surface.
#' Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param checkerperiod Default `3`. The period of the checker pattern. Increasing this value makes the checker
#' pattern bigger, and decreasing it makes it smaller
#' @param noise Default `0`. If not `0`, covers the surface in a turbulent marble pattern. This value will determine
#' the amount of turbulence in the texture.
#' @param noisephase Default `0`. The phase of the noise. The noise will repeat at `360`.
#' @param noiseintensity Default `10`. Intensity of the noise.
#' @param noisecolor Default `#000000`. The secondary color of the noise pattern.
#' Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param gradient_color Default `NA`. If not `NA`, creates a secondary color for a linear gradient
#' between the this color and color specified in `color`. Direction is determined by `gradient_transpose`.
#' @param gradient_transpose Default `FALSE`. If `TRUE`, this will use the `v` coordinate texture instead
#' of the `u` coordinate texture to map the gradient.
#' @param gradient_point_start Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `color`.
#' @param gradient_point_end Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `gradient_color`.
#' @param gradient_type Default `hsv`. Colorspace to calculate the gradient. Alternative `rgb`.
#' @param image_texture Default `""`. A 3-layer RGB array or filename to be used as the texture on the surface of the object.
#' @param image_repeat Default `1`. Number of times to repeat the image across the surface.
#' `u` and `v` repeat amount can be set independently if user passes in a length-2 vector.
#' @param alpha_texture Default `""`. A matrix or filename (specifying a greyscale image) to
#' be used to specify the transparency.
#' @param bump_texture Default `""`. A matrix, array, or filename (specifying a greyscale image) to
#' be used to specify a bump map for the surface.
#' @param bump_intensity Default `1`. Intensity of the bump map. High values may lead to unphysical results.
#' @param fog Default `FALSE`. If `TRUE`, the object will be a volumetric scatterer.
#' @param fogdensity Default `0.01`. The density of the fog. Higher values will produce more opaque objects.
#' @param sigma Default `NULL`. A number between 0 and Infinity specifying the roughness of the surface using the Oren-Nayar microfacet model.
#' Higher numbers indicate a roughed surface, where sigma is the standard deviation of the microfacet orientation angle. When 0, this reverts
#' to the default lambertian behavior.
#' @param importance_sample Default `FALSE`. If `TRUE`, the object will be sampled explicitly during
#' the rendering process. If the object is particularly important in contributing to the light paths
#' in the image (e.g. light sources, refracting glass ball with caustics, metal objects concentrating light),
#' this will help with the convergence of the image.
#'
#' @return Single row of a tibble describing the diffuse material.
#' @export
#' @importFrom grDevices col2rgb
#'
#'@examplesIf interactive() || identical(Sys.getenv("IN_PKGDOWN"), "true")
#' #Generate the cornell box and add a single white sphere to the center
#' scene = generate_cornell() |>
#' add_object(sphere(x=555/2,y=555/2,z=555/2,radius=555/8,material=diffuse()))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
#'
#' #Add a checkered rectangular cube below
#' scene = scene |>
#' add_object(cube(x=555/2,y=555/8,z=555/2,xwidth=555/2,ywidth=555/4,zwidth=555/2,
#' material = diffuse(checkercolor="purple",checkerperiod=20)))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
#'
#' #Add a marbled sphere
#' scene = scene |>
#' add_object(sphere(x=555/2+555/4,y=555/2,z=555/2,radius=555/8,
#' material = diffuse(noise=1/20)))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
#'
#' #Add an rougher (Oren-Nayar) surface
#' scene = scene |>
#' add_object(sphere(x=555/2-555/4,y=555/2,z=555/2,radius = 555/8,
#' material = diffuse(sigma = 80)))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
#'
#' #' #Add an line segment with a color gradient
#' scene = scene |>
#' add_object(segment(start = c(555,450,450),end=c(0,450,450),radius = 50,
#' material = diffuse(color="#1f7326", gradient_color = "#a60d0d")))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
diffuse = function(
color = "#ffffff",
checkercolor = NA,
checkerperiod = 3,
noise = 0,
noisephase = 0,
noiseintensity = 10,
noisecolor = "#000000",
gradient_color = NA,
gradient_transpose = FALSE,
gradient_point_start = NA,
gradient_point_end = NA,
gradient_type = "hsv",
image_texture = "",
image_repeat = 1,
alpha_texture = "",
bump_texture = "",
bump_intensity = 1,
fog = FALSE,
fogdensity = 0.01,
sigma = NULL,
importance_sample = FALSE
) {
if (all(!is.na(checkercolor))) {
checkercolor = convert_color(checkercolor)
} else {
checkercolor = NA
}
if (all(!is.na(gradient_color))) {
gradient_color = convert_color(gradient_color)
} else {
gradient_color = NA
}
if (
!any(is.na(gradient_point_start)) &&
!any(is.na(gradient_point_end)) &&
!any(is.na(gradient_color))
) {
stopifnot(length(gradient_point_start) == 3)
stopifnot(length(gradient_point_end) == 3)
stopifnot(is.numeric(gradient_point_start))
stopifnot(is.numeric(gradient_point_end))
gradient_point_info = c(gradient_point_start, gradient_point_end)
is_world_gradient = TRUE
} else {
is_world_gradient = FALSE
gradient_point_info = NA
}
info = convert_color(color)
noisecolor = convert_color(noisecolor)
image_texture = check_image_texture(image_texture)
alpha_texture = check_image_texture(alpha_texture)
bump_texture = check_image_texture(bump_texture)
type = "diffuse"
if (!is.null(sigma) && is.numeric(sigma)) {
if (sigma < 0) {
warning(
"sigma must be greater than 0 (input: ",
sigma,
")--ignoring and using lambertian model"
)
} else {
if (sigma == 0) {
type = "diffuse"
} else {
type = "oren-nayar"
sigma = sigma * pi / 180
}
}
} else {
sigma = 0
}
if (length(image_repeat) == 1) {
image_repeat = c(image_repeat, image_repeat)
}
stopifnot(checkerperiod != 0)
ray_material(list(
type = get_material_enum(type),
properties = list(info),
checkercolor = list(c(checkercolor, checkerperiod)),
gradient_color = list(gradient_color),
gradient_transpose = gradient_transpose,
world_gradient = is_world_gradient,
gradient_point_info = list(gradient_point_info),
gradient_type = gradient_type,
noise = noise,
noisephase = noisephase * pi / 180,
noiseintensity = noiseintensity,
noisecolor = list(noisecolor),
image = image_texture,
image_repeat = list(image_repeat),
alphaimage = alpha_texture,
lightintensity = NA_real_,
fog = fog,
fogdensity = fogdensity,
implicit_sample = importance_sample,
sigma = sigma,
glossyinfo = list(NA),
bump_texture = bump_texture,
bump_intensity = bump_intensity,
roughness_texture = ""
))
}
#' Metallic Material
#'
#' @param color Default `white`. The color of the sphere. Can be either
#' a hexadecimal code, R color string, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param eta Default `0`. Wavelength dependent refractivity of the material (red, green, and blue channels).
#' If single number, will be repeated across all three channels.
#' @param kappa Default `0`. Wavelength dependent absorption of the material (red, green, and blue channels).
#' If single number, will be repeated across all three channels.
#' @param fuzz Default `0`. Deprecated--Use the microfacet material instead, as it is designed for rough metals.
#' The roughness of the metallic surface. Maximum `1`.
#' @param checkercolor Default `NA`. If not `NA`, determines the secondary color of the checkered surface.
#' Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param checkerperiod Default `3`. The period of the checker pattern. Increasing this value makes the checker
#' pattern bigger, and decreasing it makes it smaller
#' @param noise Default `0`. If not `0`, covers the surface in a turbulent marble pattern. This value will determine
#' the amount of turbulence in the texture.
#' @param noisephase Default `0`. The phase of the noise. The noise will repeat at `360`.
#' @param noiseintensity Default `10`. Intensity of the noise.
#' @param noisecolor Default `#000000`. The secondary color of the noise pattern.
#' Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param gradient_color Default `NA`. If not `NA`, creates a secondary color for a linear gradient
#' between the this color and color specified in `color`. Direction is determined by `gradient_transpose`.
#' @param gradient_transpose Default `FALSE`. If `TRUE`, this will use the `v` coordinate texture instead
#' of the `u` coordinate texture to map the gradient.
#' @param gradient_point_start Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `color`.
#' @param gradient_point_end Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `gradient_color`.
#' @param gradient_type Default `hsv`. Colorspace to calculate the gradient. Alternative `rgb`.
#' @param image_texture Default `""`. A 3-layer RGB array or filename to be used as the texture on the surface of the object.
#' @param image_repeat Default `1`. Number of times to repeat the image across the surface.
#' `u` and `v` repeat amount can be set independently if user passes in a length-2 vector.
#' @param alpha_texture Default `""`. A matrix or filename (specifying a greyscale image) to be used to specify the transparency.
#' @param bump_texture Default `""`. A matrix, array, or filename (specifying a greyscale image) to
#' be used to specify a bump map for the surface.
#' @param bump_intensity Default `1`. Intensity of the bump map. High values may lead to unphysical results.
#' @param importance_sample Default `FALSE`. If `TRUE`, the object will be sampled explicitly during
#' the rendering process. If the object is particularly important in contributing to the light paths
#' in the image (e.g. light sources, refracting glass ball with caustics, metal objects concentrating light),
#' this will help with the convergence of the image.
#' @importFrom grDevices col2rgb
#'
#' @return Single row of a tibble describing the metallic material.
#' @export
#'
#'@examplesIf interactive() || identical(Sys.getenv("IN_PKGDOWN"), "true")
#' # Generate the cornell box with a single chrome sphere in the center. For other metals,
#' # See the website refractiveindex.info for eta and k data, use wavelengths 5
#' # 80nm (R), 530nm (G), and 430nm (B).
#' scene = generate_cornell() |>
#' add_object(sphere(x=555/2,y=555/2,z=555/2,radius=555/8,
#' material=metal(eta=c(3.2176,3.1029,2.1839), k = c(3.3018,3.33,3.0339))))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
#' #Add an aluminum rotated shiny metal block
#' scene = scene |>
#' add_object(cube(x=380,y=150/2,z=200,xwidth=150,ywidth=150,zwidth=150,
#' material = metal(eta = c(1.07,0.8946,0.523), k = c(6.7144,6.188,4.95)),angle=c(0,45,0)))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
#' #Add a copper metal cube
#' scene = scene |>
#' add_object(cube(x=150,y=150/2,z=300,xwidth=150,ywidth=150,zwidth=150,
#' material = metal(eta = c(0.497,0.8231,1.338),
#' k = c(2.898,2.476,2.298)),
#' angle=c(0,-30,0)))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
#'
#' #Finally, let's add a lead pipe
#' scene2 = scene |>
#' add_object(cylinder(x=450,y=200,z=400,length=400,radius=30,
#' material = metal(eta = c(1.44,1.78,1.9),
#' k = c(3.18,3.36,3.43)),
#' angle=c(0,-30,0)))
#' render_scene(scene2, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
metal = function(
color = "#ffffff",
eta = 0,
kappa = 0,
fuzz = 0,
checkercolor = NA,
checkerperiod = 3,
noise = 0,
noisephase = 0,
noiseintensity = 10,
noisecolor = "#000000",
gradient_color = NA,
gradient_transpose = FALSE,
gradient_point_start = NA,
gradient_point_end = NA,
gradient_type = "hsv",
image_texture = "",
image_repeat = 1,
alpha_texture = "",
bump_texture = "",
bump_intensity = 1,
importance_sample = FALSE
) {
color = convert_color(color)
if (all(!is.na(checkercolor))) {
checkercolor = convert_color(checkercolor)
} else {
checkercolor = NA
}
if (all(!is.na(gradient_color))) {
gradient_color = convert_color(gradient_color)
} else {
gradient_color = NA
}
if (
!any(is.na(gradient_point_start)) &&
!any(is.na(gradient_point_end)) &&
!any(is.na(gradient_color))
) {
stopifnot(length(gradient_point_start) == 3)
stopifnot(length(gradient_point_end) == 3)
stopifnot(is.numeric(gradient_point_start))
stopifnot(is.numeric(gradient_point_end))
gradient_point_info = c(gradient_point_start, gradient_point_end)
is_world_gradient = TRUE
} else {
is_world_gradient = FALSE
gradient_point_info = NA
}
noisecolor = convert_color(noisecolor)
image_texture = check_image_texture(image_texture)
alpha_texture = check_image_texture(alpha_texture)
bump_texture = check_image_texture(bump_texture)
if (length(eta) == 1) {
eta = c(eta, eta, eta)
}
if (length(kappa) == 1) {
kappa = c(kappa, kappa, kappa)
}
if (length(eta) > 3 || length(eta) == 2) {
stop("eta must be either single number or 3-component vector")
}
if (length(kappa) > 3 || length(kappa) == 2) {
stop("kappa must be either single number or 3-component vector")
}
if (length(image_repeat) == 1) {
image_repeat = c(image_repeat, image_repeat)
}
glossyinfo = list(c(1, 0, 0, eta, kappa))
ray_material(list(
type = get_material_enum("metal"),
properties = list(c(color, fuzz)),
checkercolor = list(c(checkercolor, checkerperiod)),
gradient_color = list(gradient_color),
gradient_transpose = gradient_transpose,
world_gradient = is_world_gradient,
gradient_point_info = list(gradient_point_info),
gradient_type = gradient_type,
noise = noise,
noisephase = noisephase * pi / 180,
noiseintensity = noiseintensity,
noisecolor = list(noisecolor),
lightinfo = list(NA),
image = image_texture,
image_repeat = list(image_repeat),
alphaimage = alpha_texture,
lightintensity = NA_real_,
fog = FALSE,
fogdensity = 0.01,
implicit_sample = importance_sample,
sigma = 0,
glossyinfo = glossyinfo,
bump_texture = bump_texture,
bump_intensity = bump_intensity,
roughness_texture = ""
))
}
#' Dielectric (glass) Material
#'
#'
#' @param color Default `white`. The color of the surface. Can be either
#' a hexadecimal code, R color string, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param refraction Default `1.5`. The index of refraction.
#' @param attenuation Default `c(0,0,0)`. The Beer-Lambert color-channel specific exponential attenuation
#' through the material. Higher numbers will result in less of that color making it through the material. If a character string
#' is provided (either as a named R color or a hex string), this will be converted to a length-3 vector equal to one minus the RGB
#' color vector, which should approximate the color being passed.
#' Note: This assumes the object has a closed surface.
#' @param attenuation_intensity Default `1`. Changes the attenuation by a multiplicative factor. Values lower than one will make the
#' dielectric more transparent, while values greater than one will make the glass more opaque.
#' @param priority Default `0`. When two dielectric materials overlap, the one with the lower priority value
#' is used for intersection. NOTE: If the camera is placed inside a dielectric object, its priority value
#' will not be taken into account when determining hits to other objects also inside the object.
#' @param importance_sample Default `FALSE`. If `TRUE`, the object will be sampled explicitly during
#' the rendering process. If the object is particularly important in contributing to the light paths
#' in the image (e.g. light sources, refracting glass ball with caustics, metal objects concentrating light),
#' this will help with the convergence of the image.
#' @param bump_texture Default `""`. A matrix, array, or filename (specifying a greyscale image) to
#' be used to specify a bump map for the surface.
#' @param bump_intensity Default `1`. Intensity of the bump map. High values may lead to unphysical results.
#'
#' @return Single row of a tibble describing the dielectric material.
#' @export
#'
#'@examplesIf interactive() || identical(Sys.getenv("IN_PKGDOWN"), "true")
#' #Generate a checkered ground
#' scene = generate_ground(depth=-0.5, material = diffuse(checkercolor="grey30",checkerperiod=2))
#' #Add a glass sphere
#' scene |>
#' add_object(sphere(x=-0.5,radius=0.5,material=dielectric())) |>
#' render_scene(parallel=TRUE,samples=16)
#'
#' #Add a rotated colored glass cube
#' scene |>
#' add_object(sphere(x=-0.5,radius=0.5,material=dielectric())) |>
#' add_object(cube(x=0.5,xwidth=0.5,material=dielectric(color="darkgreen"),angle=c(0,-45,0))) |>
#' render_scene(parallel=TRUE,samples=16)
#'
#' #Add an area light behind and at an angle and turn off the ambient lighting
#' scene |>
#' add_object(sphere(x=-0.5,radius=0.5,material=dielectric())) |>
#' add_object(cube(x=0.5,xwidth=0.5,material=dielectric(color="darkgreen"),angle=c(0,-45,0))) |>
#' add_object(yz_rect(z=3,y=1,x=0,zwidth=3,ywidth=0.5,
#' material=light(intensity=30),
#' angle=c(0,90,-45), order_rotation = c(3,2,1))) |>
#' render_scene(parallel=TRUE,aperture=0, ambient_light=FALSE,samples=16, lookfrom=c(0,3,-10))
#'
#' #Color glass using Beer-Lambert attenuation, which attenuates light on a per-channel
#' #basis as it travels through the material. This effect is what gives some types of glass
#' #a green glow at the edges. We will get this effect by setting a lower attenuation value
#' #for the `green` (second) channel in the dielectric `attenuation` argument.
#' generate_ground(depth=-0.5,material=diffuse(checkercolor="grey30",checkerperiod=2)) |>
#' add_object(sphere(z=5,x=-0.5,y=1,material=light(intensity=10))) |>
#' add_object(cube(y=0.3,ywidth=0.1,xwidth=2,zwidth=2,angle=c(45,110,0),
#' material=dielectric(attenuation=c(1.2,0.2,1.2),
#' attenuation_intensity=2))) |>
#' render_scene(parallel=TRUE, samples = 16)
#'
#' #If you have overlapping dielectrics, the `priority` value can help disambiguate what
#' #object wins. Here, I place a bubble inside a cube by setting a lower priority value and
#' #making the inner sphere have a index of refraction of 1. I also place spheres at the corners.
#' generate_ground(depth=-0.51,material=diffuse(checkercolor="grey30",checkerperiod=2)) |>
#' add_object(cube(material = dielectric(priority=2, attenuation = c(10,3,10)))) |>
#' add_object(sphere(radius=0.49,material = dielectric(priority=1, refraction=1))) |>
#' add_object(sphere(radius=0.25,x=0.5,z=-0.5,y=0.5,
#' material = dielectric(priority=0,attenuation = c(10,3,10) ))) |>
#' add_object(sphere(radius=0.25,x=-0.5,z=0.5,y=0.5,
#' material = dielectric(priority=0,attenuation = c(10,3,10)))) |>
#' add_object(sphere(y=5,x=-5,radius=3,material=light())) |>
#' render_scene(parallel=TRUE, samples = 16,lookfrom=c(5,1,5))
dielectric = function(
color = "white",
refraction = 1.5,
attenuation = c(0, 0, 0),
attenuation_intensity = 1,
priority = 0,
importance_sample = FALSE,
bump_texture = "",
bump_intensity = 1
) {
color = convert_color(color)
stopifnot(
attenuation_intensity >= 0 &&
is.numeric(attenuation_intensity) &&
!is.na(attenuation_intensity) &&
!is.infinite(attenuation_intensity)
)
if (is.character(attenuation)) {
attenuation = 1 - convert_color(attenuation)
}
attenuation = attenuation * attenuation_intensity
bump_texture = check_image_texture(bump_texture)
ray_material(list(
type = get_material_enum("dielectric"),
properties = list(c(color, refraction, attenuation, priority)),
checkercolor = list(NA),
gradient_color = list(NA),
gradient_transpose = FALSE,
world_gradient = FALSE,
gradient_point_info = list(NA),
gradient_type = NA,
noise = 0,
noisephase = 0,
noiseintensity = 0,
noisecolor = list(c(0, 0, 0)),
image = "",
image_repeat = list(c(1, 1)),
alphaimage = "",
lightintensity = NA_real_,
fog = FALSE,
fogdensity = NA_real_,
implicit_sample = importance_sample,
sigma = 0,
glossyinfo = list(NA),
bump_texture = bump_texture,
bump_intensity = bump_intensity,
roughness_texture = ""
))
}
#' Microfacet Material
#'
#' @param color Default `white`. The color of the surface. Can be either
#' a hexadecimal code, R color string, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param roughness Default `0.0001`. Roughness of the surface, between `0` (smooth) and `1` (diffuse).
#' Can be either a single number, or two numbers indicating an anisotropic distribution of normals. `0` is a smooth surface, while
#' `1` is extremely rough. This can be used to create a wide-variety of materials (e.g. `0-0.01` is specular
#' metal, `0.02`-`0.1` is brushed metal, `0.1`-`0.3` is a rough metallic surface , `0.3`-`0.5` is diffuse, and
#' above that is a rough satin-like material).
#' Two numbers will specify the x and y roughness separately (e.g. `roughness = c(0.01, 0.001)` gives an
#' etched metal effect). If `0`, this defaults to the `metal()` material for faster evaluation.
#' @param transmission Default `FALSE`. If `TRUE`, this material will be a rough dielectric instead of a rough metallic surface.
#' @param eta Default `0`. Wavelength dependent refractivity of the material (red, green, and blue channels).
#' If single number, will be repeated across all three channels. If `transmission = TRUE`, this is a single value representing the
#' index of refraction of the material.
#' @param kappa Default `0`. Wavelength dependent absorption of the material (red, green, and blue channels).
#' If single number, will be repeated across all three channels. If `transmission = TRUE`, this length-3 vector specifies
#' the attenuation of the dielectric (analogous to the dielectric `attenuation` argument).
#' @param microfacet Default `tbr`. Type of microfacet distribution. Alternative option `beckmann`.
#' @param checkercolor Default `NA`. If not `NA`, determines the secondary color of the checkered surface.
#' Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param checkerperiod Default `3`. The period of the checker pattern. Increasing this value makes the checker
#' pattern bigger, and decreasing it makes it smaller
#' @param noise Default `0`. If not `0`, covers the surface in a turbulent marble pattern. This value will determine
#' the amount of turbulence in the texture.
#' @param noisephase Default `0`. The phase of the noise. The noise will repeat at `360`.
#' @param noiseintensity Default `10`. Intensity of the noise.
#' @param noisecolor Default `#000000`. The secondary color of the noise pattern.
#' Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param gradient_color Default `NA`. If not `NA`, creates a secondary color for a linear gradient
#' between the this color and color specified in `color`. Direction is determined by `gradient_transpose`.
#' @param gradient_transpose Default `FALSE`. If `TRUE`, this will use the `v` coordinate texture instead
#' of the `u` coordinate texture to map the gradient.
#' @param gradient_point_start Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `color`.
#' @param gradient_point_end Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `gradient_color`.
#' @param gradient_type Default `hsv`. Colorspace to calculate the gradient. Alternative `rgb`.
#' @param image_texture Default `""`. A 3-layer RGB array or filename to be used as the texture on the surface of the object.
#' @param image_repeat Default `1`. Number of times to repeat the image across the surface.
#' `u` and `v` repeat amount can be set independently if user passes in a length-2 vector.
#' @param alpha_texture Default `""`. A matrix or filename (specifying a greyscale image) to be used to specify the transparency.
#' @param bump_texture Default `""`. A matrix, array, or filename (specifying a greyscale image) to
#' be used to specify a bump map for the surface.
#' @param bump_intensity Default `1`. Intensity of the bump map. High values may lead to unphysical results.
#' @param roughness_texture Default `""`. A matrix, array, or filename (specifying a greyscale image) to
#' be used to specify a roughness map for the surface.
#' @param roughness_range Default ` c(0.0001, 0.2)`. This is a length-2 vector that specifies the range of roughness values
#' that the `roughness_texture` can take.
#' @param roughness_flip Default `FALSE`. Setting this to `TRUE` flips the roughness values specified in the `roughness_texture`
#' so high values are now low values and vice versa.
#' @param importance_sample Default `FALSE`. If `TRUE`, the object will be sampled explicitly during
#' the rendering process. If the object is particularly important in contributing to the light paths
#' in the image (e.g. light sources, refracting glass ball with caustics, metal objects concentrating light),
#' this will help with the convergence of the image.
#'
#' @return Single row of a tibble describing the microfacet material.
#' @export
#'
#'@examplesIf interactive() || identical(Sys.getenv("IN_PKGDOWN"), "true")
#' # Generate a golden egg, using eta and kappa taken from physical measurements
#' # See the website refractiveindex.info for eta and k data, use
#' # wavelengths 580nm (R), 530nm (G), and 430nm (B).
#' generate_cornell() |>
#' add_object(ellipsoid(x=555/2,555/2,y=150, a=100,b=150,c=100,
#' material=microfacet(roughness=0.1,
#' eta=c(0.216,0.42833,1.3184), kappa=c(3.239,2.4599,1.8661)))) |>
#' render_scene(lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, parallel=TRUE,clamp_value=10)
#' #Make the roughness anisotropic (either horizontal or vertical), adding an extra light in front
#' #to show off the different microfacet orientations
#' generate_cornell() |>
#' add_object(sphere(x=555/2,z=50,y=75,radius=20,material=light())) |>
#' add_object(ellipsoid(x=555-150,555/2,y=150, a=100,b=150,c=100,
#' material=microfacet(roughness=c(0.3,0.1),
#' eta=c(0.216,0.42833,1.3184), kappa=c(3.239,2.4599,1.8661)))) |>
#' add_object(ellipsoid(x=150,555/2,y=150, a=100,b=150,c=100,
#' material=microfacet(roughness=c(0.1,0.3),
#' eta=c(0.216,0.42833,1.3184), kappa=c(3.239,2.4599,1.8661)))) |>
#' render_scene(lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, parallel=TRUE,clamp_value=10)
#' #Render a rough silver R with a smaller golden egg in front
#' generate_cornell() |>
#' add_object(obj_model(r_obj(simple_r = TRUE),
#' x=555/2,z=350,y=0, scale_obj = 200, angle=c(0,20,0),
#' material=microfacet(roughness=0.2,
#' eta=c(1.1583,0.9302,0.5996), kappa=c(6.9650,6.396,5.332)))) |>
#' add_object(ellipsoid(x=200,z=200,y=80, a=50,b=80,c=50,
#' material=microfacet(roughness=0.1,
#' eta=c(0.216,0.42833,1.3184), kappa=c(3.239,2.4599,1.8661)))) |>
#' render_scene(lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, parallel=TRUE,clamp_value=10)
#' #Increase the roughness
#' generate_cornell() |>
#' add_object(obj_model(r_obj(simple_r = TRUE),
#' x=555/2,z=350,y=0, scale_obj = 200, angle=c(0,20,0),
#' material=microfacet(roughness=0.5,
#' eta=c(1.1583,0.9302,0.5996), kappa=c(6.9650,6.396,5.332)))) |>
#' add_object(ellipsoid(x=200,z=200,y=80, a=50,b=80,c=50,
#' material=microfacet(roughness=0.3,
#' eta=c(0.216,0.42833,1.3184), kappa=c(3.239,2.4599,1.8661)))) |>
#' render_scene(lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, parallel=TRUE,clamp_value=10)
#' #Use transmission for a rough dielectric
#' generate_cornell() |>
#' add_object(text3d(label="XY Plane", z=550,y=555/2,x=555/2,text_height=200,
#' orientation = "xy",
#' material=diffuse(color="grey10"), angle=c(0,0,0))) |>
#' add_object(obj_model(r_obj(simple_r = TRUE),
#' x=555/2,z=350,y=0, scale_obj = 200, angle=c(0,20,0),
#' material=microfacet(roughness=0.25, transmission=T, eta=1.3))) |>
#' add_object(ellipsoid(x=200,z=200,y=80, a=50,b=80,c=50,
#' material=microfacet(roughness=0.15, transmission=T, eta=1.6))) |>
#' render_scene(lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=64,
#' aperture=0, fov=40, parallel=TRUE,clamp_value=10, min_variance=1e-6)
microfacet = function(
color = "white",
roughness = 0.0001,
transmission = FALSE,
eta = 0,
kappa = 0,
microfacet = "tbr",
checkercolor = NA,
checkerperiod = 3,
noise = 0,
noisephase = 0,
noiseintensity = 10,
noisecolor = "#000000",
gradient_color = NA,
gradient_transpose = FALSE,
gradient_point_start = NA_real_,
gradient_point_end = NA_real_,
gradient_type = "hsv",
image_texture = "",
image_repeat = 1,
alpha_texture = "",
bump_texture = "",
bump_intensity = 1,
roughness_texture = "",
roughness_range = c(0.0001, 0.2),
roughness_flip = FALSE,
importance_sample = FALSE
) {
microtype = switch(microfacet, "tbr" = 1, "beckmann" = 2, 1)
roughness[roughness <= 0] = 0
roughness[roughness > 1] = 1
if (length(roughness) == 1) {
alphax = roughness^2
alphay = roughness^2
} else {
alphax = roughness[1]^2
alphay = roughness[2]^2
}
if (length(roughness_range) != 2) {
stop("length of roughness_range must be 2")
}
if (roughness_range[1] > roughness_range[2]) {
roughness_range = rev(roughness_range)
}
if (
roughness_range[1] == roughness_range[2] && nchar(roughness_texture) > 0
) {
roughness_texture = ""
roughness = roughness_range[1]
}
if (length(eta) == 1) {
eta = c(eta, eta, eta)
}
if (length(kappa) == 1) {
kappa = c(kappa, kappa, kappa)
}
if (length(eta) > 3 || length(eta) == 2) {
stop("eta must be either single number or 3-component vector")
}
if (length(kappa) > 3 || length(kappa) == 2) {
stop("kappa must be either single number or 3-component vector")
}
color = convert_color(color)
if (all(!is.na(checkercolor))) {
checkercolor = convert_color(checkercolor)
} else {
checkercolor = NA
}
if (all(!is.na(gradient_color))) {
gradient_color = convert_color(gradient_color)
} else {
gradient_color = NA
}
if (
!any(is.na(gradient_point_start)) &&
!any(is.na(gradient_point_end)) &&
!any(is.na(gradient_color))
) {
stopifnot(length(gradient_point_start) == 3)
stopifnot(length(gradient_point_end) == 3)
stopifnot(is.numeric(gradient_point_start))
stopifnot(is.numeric(gradient_point_end))
gradient_point_info = c(gradient_point_start, gradient_point_end)
is_world_gradient = TRUE
} else {
is_world_gradient = FALSE
gradient_point_info = NA
}
noisecolor = convert_color(noisecolor)
image_texture = check_image_texture(image_texture)
alpha_texture = check_image_texture(alpha_texture)
bump_texture = check_image_texture(bump_texture)
roughness_texture = check_image_texture(roughness_texture)
if (length(image_repeat) == 1) {
image_repeat = c(image_repeat, image_repeat)
}
roughness_flip = ifelse(roughness_flip, 1, 0)
glossyinfo = list(c(
microtype,
alphax,
alphay,
eta,
kappa,
roughness_range,
roughness_flip
))
if (alphax == 0 && alphay == 0) {
if (!transmission) {
ray_material(list(
type = get_material_enum("metal"),
properties = list(c(color, 0)),
gradient_color = list(gradient_color),
gradient_transpose = FALSE,
world_gradient = is_world_gradient,
gradient_point_info = list(gradient_point_info),
gradient_type = gradient_type,
checkercolor = list(c(checkercolor, checkerperiod)),
noise = noise,
noisephase = noisephase * pi / 180,
noiseintensity = noiseintensity,
noisecolor = list(noisecolor),
image = image_texture,
image_repeat = list(image_repeat),
alphaimage = alpha_texture,
lightintensity = NA_real_,
fog = FALSE,
fogdensity = NA_real_,
implicit_sample = importance_sample,
sigma = 0,
glossyinfo = glossyinfo,
bump_texture = bump_texture,
bump_intensity = bump_intensity,
roughness_texture = ""
))
} else {
ray_material(list(
type = get_material_enum("dielectric"),
properties = list(c(color, eta[1], c(0, 0, 0), 0)),
gradient_color = list(gradient_color),
gradient_transpose = FALSE,
world_gradient = is_world_gradient,
gradient_point_info = list(gradient_point_info),
gradient_type = gradient_type,
checkercolor = list(c(checkercolor, checkerperiod)),
noise = noise,
noisephase = noisephase * pi / 180,
noiseintensity = noiseintensity,
noisecolor = list(noisecolor),
image = image_texture,
image_repeat = list(image_repeat),
alphaimage = alpha_texture,
lightintensity = NA_real_,
fog = FALSE,
fogdensity = NA_real_,
implicit_sample = importance_sample,
sigma = 0,
glossyinfo = glossyinfo,
bump_texture = bump_texture,
bump_intensity = bump_intensity,
roughness_texture = ""
))
}
} else {
if (transmission) {
typeval = "mf-t"
} else {
typeval = "mf"
}
ray_material(list(
type = get_material_enum(typeval),
properties = list(c(color)),
gradient_color = list(gradient_color),
gradient_transpose = FALSE,
world_gradient = is_world_gradient,
gradient_point_info = list(gradient_point_info),
gradient_type = gradient_type,
checkercolor = list(c(checkercolor, checkerperiod)),
noise = noise,
noisephase = noisephase * pi / 180,
noiseintensity = noiseintensity,
noisecolor = list(noisecolor),
image = image_texture,
image_repeat = list(image_repeat),
alphaimage = alpha_texture,
lightintensity = NA_real_,
fog = FALSE,
fogdensity = NA_real_,
implicit_sample = importance_sample,
sigma = 0,
glossyinfo = glossyinfo,
bump_texture = bump_texture,
bump_intensity = bump_intensity,
roughness_texture = roughness_texture
))
}
}
#' Light Material
#'
#' @param color Default `white`. The color of the light Can be either
#' a hexadecimal code, R color string, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param intensity Default `10`. If a positive value, this will turn this object into a light emitting the value specified
#' in `color` (ignoring other properties). Higher values will produce a brighter light.
#' @param importance_sample Default `TRUE`. Keeping this on for lights improves the convergence of the rendering
#' algorithm, in most cases. If the object is particularly important in contributing to the light paths
#' in the image (e.g. light sources, refracting glass ball with caustics, metal objects concentrating light),
#' this will help with the convergence of the image.
#' @param spotlight_focus Default `NA`, no spotlight. Otherwise, a length-3 numeric vector specifying
#' the x/y/z coordinates that the spotlight should be focused on. Only works for spheres and rectangles.
#' @param spotlight_width Default `30`. Angular width of the spotlight.
#' @param spotlight_start_falloff Default `15`. Angle at which the light starts fading in intensity.
#' @param invisible Default `FALSE`. If `TRUE`, the light itself will be invisible.
#' @param image_texture Default `""`. A 3-layer RGB array or filename to be used as the texture on the surface of the object.
#' @param image_repeat Default `1`. Number of times to repeat the image across the surface.
#' `u` and `v` repeat amount can be set independently if user passes in a length-2 vector.
#' @param gradient_color Default `NA`. If not `NA`, creates a secondary color for a linear gradient
#' between the this color and color specified in `color`. Direction is determined by `gradient_transpose`.
#' @param gradient_transpose Default `FALSE`. If `TRUE`, this will use the `v` coordinate texture instead
#' of the `u` coordinate texture to map the gradient.
#' @param gradient_point_start Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `color`.
#' @param gradient_point_end Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `gradient_color`.
#' @param gradient_type Default `hsv`. Colorspace to calculate the gradient. Alternative `rgb`.
#'
#' @return Single row of a tibble describing the light material.
#' @export
#' @importFrom grDevices col2rgb
#'
#'@examplesIf interactive() || identical(Sys.getenv("IN_PKGDOWN"), "true")
#' #Generate the cornell box without a light and add a single white sphere to the center
#' scene = generate_cornell(light=FALSE) |>
#' add_object(sphere(x=555/2,y=555/2,z=555/2,radius=555/8,material=light()))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
#'
#' #Remove the light for direct camera rays, but keep the lighting
#' scene = generate_cornell(light=FALSE) |>
#' add_object(sphere(x=555/2,y=555/2,z=555/2,radius=555/8,
#' material=light(intensity=15,invisible=TRUE)))
#' render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), samples=16,
#' aperture=0, fov=40, ambient_light=FALSE, parallel=TRUE)
#'
#' #All gather around the orb
#' scene = generate_ground(material = diffuse(checkercolor="grey50")) |>
#' add_object(sphere(radius=0.25,material=light(intensity=90,color="#f11"))) |>
#' add_object(obj_model(r_obj(), scale=2.5,z=-3,x=-1.25,y=0, angle=c(0,235,0))) |>
#' add_object(pig(scale=0.3, x=1.5,z=-2,y=-1.5,angle=c(0,-135,0)))
#' render_scene(scene, samples=16, parallel=TRUE, clamp_value=10, lookfrom=c(0,0,10))
light = function(
color = "#ffffff",
intensity = 10,
importance_sample = TRUE,
spotlight_focus = NA,
spotlight_width = 30,
spotlight_start_falloff = 15,
invisible = FALSE,
image_texture = "",
image_repeat = 1,
gradient_color = NA,
gradient_transpose = FALSE,
gradient_point_start = NA,
gradient_point_end = NA,
gradient_type = "hsv"
) {
info = convert_color(color)
image_texture = check_image_texture(image_texture)
if (length(image_repeat) == 1) {
image_repeat = c(image_repeat, image_repeat)
}
if (all(!is.na(gradient_color))) {
gradient_color = convert_color(gradient_color)
} else {
gradient_color = NA_real_
}
if (
!any(is.na(gradient_point_start)) &&
!any(is.na(gradient_point_end)) &&
!any(is.na(gradient_color))
) {
stopifnot(length(gradient_point_start) == 3)
stopifnot(length(gradient_point_end) == 3)
stopifnot(is.numeric(gradient_point_start))
stopifnot(is.numeric(gradient_point_end))
gradient_point_info = c(gradient_point_start, gradient_point_end)
is_world_gradient = TRUE
} else {
is_world_gradient = FALSE
gradient_point_info = NA_real_
}
if (invisible) {
invisible = 1
} else {
invisible = 0
}
if (all(!is.na(spotlight_focus))) {
stopifnot(length(spotlight_focus) == 3)
spotlight_width = min(c(spotlight_width, 180))
spotlight_start_falloff = min(c(spotlight_start_falloff, 90))
info = c(
info,
spotlight_focus,
cospi(spotlight_width / 180),
cospi(spotlight_start_falloff / 180),
invisible
)
ray_material(list(
type = get_material_enum("spotlight"),
properties = list(info),
checkercolor = list(NA_real_),
gradient_color = list(NA_real_),
gradient_transpose = FALSE,
world_gradient = FALSE,
gradient_point_info = list(NA_real_),
gradient_type = NA,
noise = 0,
noisephase = 0,
noiseintensity = 0,
noisecolor = list(c(0, 0, 0)),
image = image_texture,
image_repeat = list(image_repeat),
alphaimage = "",
lightintensity = intensity,
fog = FALSE,
fogdensity = 0.01,
implicit_sample = importance_sample,
sigma = 0,
glossyinfo = list(NA_real_),
bump_texture = "",
bump_intensity = 1,
roughness_texture = ""
))
} else {
info = c(info, invisible)
ray_material(list(
type = get_material_enum("light"),
properties = list(info),
checkercolor = list(NA_real_),
gradient_color = list(gradient_color),
gradient_transpose = gradient_transpose,
world_gradient = is_world_gradient,
gradient_point_info = list(gradient_point_info),
gradient_type = gradient_type,
noise = 0,
noisephase = 0,
noiseintensity = 0,
noisecolor = list(c(0, 0, 0)),
image = image_texture,
image_repeat = list(image_repeat),
alphaimage = "",
lightintensity = intensity,
fog = FALSE,
fogdensity = 0.01,
implicit_sample = importance_sample,
sigma = 0,
glossyinfo = list(NA_real_),
bump_texture = "",
bump_intensity = 1,
roughness_texture = ""
))
}
}
#' Glossy Material
#'
#' @param color Default `white`. The color of the surface. Can be either
#' a hexadecimal code, R color string, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param gloss Default `0.8`. Gloss of the surface, between `1` (completely glossy) and `0` (rough glossy).
#' Can be either a single number, or two numbers indicating an anisotropic distribution of normals (as in `microfacet()`).
#' @param reflectance Default `0.03`. The reflectivity of the surface. `1` is a full mirror, `0` is diffuse with a glossy highlight.
#' @param microfacet Default `tbr`. Type of microfacet distribution. Alternative option `beckmann`.
#' @param checkercolor Default `NA`. If not `NA`, determines the secondary color of the checkered surface.
#' Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param checkerperiod Default `3`. The period of the checker pattern. Increasing this value makes the checker
#' pattern bigger, and decreasing it makes it smaller
#' @param noise Default `0`. If not `0`, covers the surface in a turbulent marble pattern. This value will determine
#' the amount of turbulence in the texture.
#' @param noisephase Default `0`. The phase of the noise. The noise will repeat at `360`.
#' @param noiseintensity Default `10`. Intensity of the noise.
#' @param noisecolor Default `#000000`. The secondary color of the noise pattern.
#' Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
#' @param gradient_color Default `NA`. If not `NA`, creates a secondary color for a linear gradient
#' between the this color and color specified in `color`. Direction is determined by `gradient_transpose`.
#' @param gradient_transpose Default `FALSE`. If `TRUE`, this will use the `v` coordinate texture instead
#' of the `u` coordinate texture to map the gradient.
#' @param gradient_point_start Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `color`.
#' @param gradient_point_end Default `NA`. If not `NA`, this changes the behavior from mapping texture coordinates to
#' mapping to world space coordinates. This should be a length-3 vector specifying the x,y, and z points where the gradient
#' begins with value `gradient_color`.