-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathcore_definitions.mdl
4855 lines (4729 loc) · 162 KB
/
core_definitions.mdl
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
/***************************************************************************************************
* Copyright (c) 2015-2025, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**************************************************************************************************/
// The "//group ... //endgroup" comments are used during the
// procedural creation of this module's documentation.
mdl 1.6;
import ::df::*;
import ::state::*;
import ::math::*;
import ::base::*;
import ::tex::*;
import ::anno::*;
export using ::base import texture_return;
export using ::base import mono_mode;
export using ::base import color_layer_mode;
//import support_definitions::*;
module [[
anno::version( 2, 0, 2),
anno::display_name("NVIDIA core definitions")
]];
const string COPYRIGHT = "Copyright 2024 NVIDIA Corporation. All rights reserved.";
//some local functions, dont document
// blend two normals, similar to
// http://blog.selfshadow.com/publications/blending-in-detail/
export float3 blend_normals(
float3 base_normal = state::normal()
[[
anno::description("The base normal")
]],
float base_normal_weight = 1.0f
[[
anno::description("Specifies the strength of the base normal using a linear blend between state::normal and \"base_normal\""),
anno::soft_range(0.0,1.0)
]],
float3 detail_normal = state::normal()
[[
anno::description("The detail normal")
]],
float detail_normal_weight = 1.0f
[[
anno::description("Specifies the strength of the detail normal using a linear blend between state::normal and \"detail_normal\""),
anno::soft_range(0.0,1.0)
]]
)
[[
anno::description("Blend two normals or apply a detail normal map"),
anno::display_name("Blend normals"),
anno::thumbnail(".thumbs/blend_normals.png"),
anno::in_group("Texturing, high level"),
anno::ui_order(33),
anno::author("NVIDIA Corporation"),
anno::copyright_notice(COPYRIGHT)]]
{
return base::blend_normals(base_normal,base_normal_weight,detail_normal,detail_normal_weight);
}
// blend 3 normals, similar to
// http://blog.selfshadow.com/publications/blending-in-detail/
//TODO: make public?
float3 blend_3_normals(
float3 base_normal = state::normal()
[[
anno::description("The base normal")
]],
float base_normal_weight = 1.0f
[[
anno::description("Specifies the strength of the base normal using a linear blend between state::normal and \"base_normal\"")
]],
float3 detail_normal = state::normal()
[[
anno::description("The detail normal")
]],
float detail_normal_weight = 1.0f
[[
anno::description("Specifies the strength of the detail normal using a linear blend between state::normal and \"detail_normal\"")
]],
float3 detail_normal2 = state::normal()
[[
anno::description("The detail normal2")
]],
float detail_normal_weight2 = 1.0f
[[
anno::description("Specifies the strength of the detail normal using a linear blend between state::normal and \"detail_normal\"")
]]
)
[[
anno::description("Blend three normals for sticker-like situations where a detail normal map is applied to a base normal map"),
anno::noinline()
]]
{
float3 tu = state::texture_tangent_u(0);
float3 tv = state::texture_tangent_v(0);
float3 n = state::normal();
float w1 = math::saturate(base_normal_weight);
float w2 = math::saturate(detail_normal_weight);
float w3 = math::saturate(detail_normal_weight2);
float3 n1_t = math::normalize(
float3(math::dot(tu, base_normal) * w1,
math::dot(tv, base_normal) * w1,
math::dot(n, base_normal) * w1 + 1.0f - w1));
float3 n2_t = math::normalize(
float3(math::dot(tu, detail_normal) * w2,
math::dot(tv, detail_normal) * w2,
math::dot(n, detail_normal) * w2 + 1.0f - w2));
float3 n3_t = math::normalize(
float3(math::dot(tu, detail_normal2) * w3,
math::dot(tv, detail_normal2) * w3,
math::dot(n, detail_normal2) * w3 + 1.0f - w3));
n1_t.z += 1.0f;
n2_t.x = -n2_t.x;
n2_t.y = -n2_t.y;
float3 n12_t = n1_t * math::dot(n1_t, n2_t) / n1_t.z - n2_t;
n12_t.z+= 1.0f;
n3_t.x = -n3_t.x;
n3_t.y = -n3_t.y;
float3 n_t = n12_t * math::dot(n12_t, n3_t) / n12_t.z - n3_t;
return math::normalize(
tu * n_t.x +
tv * n_t.y +
n * n_t.z);
}
float3 transform_rotate(float3 p, float3 r)
{
// Euler rotation matrix xyz order to stay compatible with ::base
float3 s = math::sin(r);
float3 c = math::cos(r);
float3x3 rotate =
float3x3( c.y*c.z , -c.x*s.z + s.x*s.y*c.z , s.x*s.z + c.x*s.y*c.z ,
c.y*s.z , c.x*c.z + s.x*s.y*s.z , -s.x*c.z + c.x*s.y*s.z ,
-s.y , s.x*c.y , c.x*c.y );
return p*rotate;
}
float3 transform_rotate_inv(float3 p, float3 r)
{
// Euler rotation matrix xyz order to stay compatible with ::base
float3 s = math::sin(r);
float3 c = math::cos(r);
float3x3 rotate =
float3x3( c.y*c.z , -c.x*s.z + s.x*s.y*c.z , s.x*s.z + c.x*s.y*c.z ,
c.y*s.z , c.x*c.z + s.x*s.y*s.z , -s.x*c.z + c.x*s.y*s.z ,
-s.y , s.x*c.y , c.x*c.y );
return rotate*p;
}
float2 transform_st(float rotation = 0.0, float2 translation = float2(0.0), float2 scale = float2(1.0), float2 st = float2(0.0))
[[
anno::display_name("Transform 2D"),
anno::description("Rotate/translate/scale a 2D coordinate"),
anno::author("NVIDIA Corporation")
]]{
float s = math::sin(rotation);
float c = math::cos(rotation);
float2 st_t=st;
st_t = float2(s*st_t.x+c*st_t.y,s*st_t.y-c*st_t.x);
return st_t*scale+ translation;
}
color biased_color_blend(float w1 = 0.0, color c1 = color(0.0), float w2 = 0.0, color c2 = color(0.0), float w3 = 0.0, color c3 = color(0.0), color mean = color(0.5))
[[
anno::display_name("Biased color blend"),
anno::description("Blend up to 3 colors. Set mean to the average color to preserve contrast when blending textures"),
anno::author("NVIDIA Corporation")
]]
{
color o=w1*c1+w2*c2+w3*c3;
float s=w1+w2+w3;
float s2=w1*w1+w2*w2+w3*w3;
return mean + (o-s*mean)/ math::sqrt(s2);
}
//group Enumerations
export enum material_type
[[
anno::display_name("User interface group"),
anno::description("User interface grouping hint for materials"),
anno::hidden()
]]
{
simple_material
[[ anno::description("Simple material") ]],
complex_material
[[ anno::description("Complex material") ]],
combiner_material
[[ anno::description("Combiner material") ]],
modifier_material
[[ anno::description("Material modifier") ]]
};
export enum emission_type
[[
anno::display_name("Emission mode"),
anno::description("Emission mode definition for light sources"),
anno::hidden()
]]
{
lumen_m2
[[ anno::description("lumen/m2") ]],
lumen
[[ anno::description("lumen") ]],
candela
[[ anno::description("candela") ]],
nit
[[ anno::description("nit (candela/m2)") ]]
};
export enum cell_type
[[
anno::display_name("Worley noise cell type"),
anno::description("Behavior of the Worley noise cell"),
anno::hidden()
]]
{
simple_cells = 0
[[ anno::description("Simple cells") ]],
crystal_cells = 1
[[ anno::description("Crystal cells") ]],
bordered_cells = 2
[[ anno::description("Bordered cells") ]]
};
export enum cell_base
[[
anno::display_name("Worley noise cell shape"),
anno::description("Shape of the Worley noise cell"),
anno::hidden()
]]
{
circular_cells = 0
[[ anno::description("Circle base") ]],
diamond_cells = 1
[[ anno::description("Diamond base") ]]
};
//endgroup
float4x4 rotation_translation_scale(
float3 rotation = float3(0.)
[[ anno::description("Rotation applied to every UVW coordinate") ]],
float3 translation = float3(0.)
[[ anno::description("Offset applied to every UVW coordinate") ]],
float3 scaling = float3(1.)
[[ anno::description("Scale applied to every UVW coordinate") ]]
)
[[
anno::description("Construct transformation matrix from Euler rotation, translation and scale"),
anno::hidden()
]]
{
float4x4 scale =
float4x4(scaling.x , 0. , 0. , 0.,
0. , scaling.y , 0. , 0.,
0. , 0. , scaling.z , 0.,
translation.x , translation.y , translation.z , 1.);
float3 s = math::sin(rotation);
float3 c = math::cos(rotation);
float4x4 rotate =
float4x4( c.y*c.z , -c.x*s.z + s.x*s.y*c.z , s.x*s.z + c.x*s.y*c.z , 0.0,
c.y*s.z , c.x*c.z + s.x*s.y*s.z , -s.x*c.z + c.x*s.y*s.z , 0.0,
-s.y , s.x*c.y , c.x*c.y , 0.0,
0. , 0. , 0. , 1.);
return scale*rotate;
}
export annotation suitable_as_light();
export annotation type_of_material(material_type type);
export annotation dimension(float dimension);
export annotation dimension(float2 dimension);
export annotation dimension(float3 dimension);
//group Texturing functions
export texture_return blend_colors(
color color_1 = color(0.0)
[[ anno::display_name("Color 1") ]],
color color_2 = color(1.0)
[[ anno::display_name("Color 2") ]],
uniform color_layer_mode mode = color_layer_blend
[[
anno::description("Describes how Color 1 and Color 2 are combined"),
anno::display_name("Blend mode")
]],
float weight = 1.
[[
anno::description("Defines strength of the effect. At weight 0, only color 1 will be visible. At weight 1, the blend function will have full effect."),
anno::display_name("Blend weight"),
anno::soft_range(0.0,1.0)
]],
uniform bool linear_blend = true
[[
anno::description("The blend opperation can either be applied in linear or gamma (2.2) color space"),
anno::display_name("Linear blend")
]]
)
[[
anno::display_name("Blend colors"),
anno::description("Allows combining textures and colors in varied ways"),
anno::thumbnail(".thumbs/blend_colors.png"),
anno::in_group("Texturing, high level"),
anno::ui_order(33),
anno::author("NVIDIA Corporation"),
anno::copyright_notice(COPYRIGHT)
]]
{
color c1 = linear_blend? color_1: math::pow(color_1,0.45);
color c2 = linear_blend? color_2: math::pow(color_2,0.45);
float w = linear_blend? weight: math::pow(weight,0.45);
texture_return r = base::blend_color_layers(
layers: base::color_layer[](
base::color_layer(
layer_color: c2,
weight: w,
mode: mode
)),
base: c1
);
return linear_blend? r: texture_return(math::pow(r.tint,2.2),math::pow(r.mono,2.2));
}
export texture_return file_texture(
uniform texture_2d texture
[[
anno::display_name("Bitmap file"),
anno::in_group("Bitmap parameters"),
anno::ui_order(0)
]],
uniform mono_mode mono_source = mono_average
[[
anno::display_name("Scalar mode"),
anno::description("Defines how the texture applies to scalar parameters"),
anno::in_group("Bitmap parameters"),
anno::ui_order(1)
]],
uniform float brightness = 1.
[[
anno::display_name("Brightness"),
anno::in_group("Bitmap parameters"),
anno::ui_order(2),
anno::soft_range(0.0,1.0)
]],
uniform float contrast = 1.
[[
anno::display_name("Contrast"),
anno::in_group("Bitmap parameters"),
anno::ui_order(3),
anno::soft_range(0.0,1.0)
]],
float2 scaling = float2(1.)
[[
anno::description("Controls the scale of the texture on the object"),
anno::display_name("Tiling"),
anno::in_group("Placement"),
anno::ui_order(8)
]],
float2 translation = float2(0.)
[[
anno::description("Controls position of the texture on the object"),
anno::display_name("Offset"),
anno::in_group("Placement"),
anno::ui_order(7)
]],
float rotation = 0.
[[
anno::description("Rotation angle of the texture in degrees"),
anno::display_name("Rotation"),
anno::in_group("Placement"),
anno::ui_order(6),
anno::soft_range(0.0,360.0)
]],
uniform bool clip = false
[[
anno::description("If set to true, texture will not repeat. Outside of the texture, color will be black and the scalar value will be 0."),
anno::display_name("Clip"),
anno::in_group("Placement"),
anno::ui_order(9)
]],
uniform int texture_space = 0
[[
anno::description("Selects a specific UV space"),
anno::display_name("UV space index"),
anno::hard_range(0,3),
anno::in_group("Placement"),
anno::ui_order(5)
]],
uniform bool invert = false
[[
anno::description("Invert image"),
anno::display_name("Invert image"),
anno::in_group("Bitmap parameters"),
anno::ui_order(4)
]]
)
[[
anno::display_name("Bitmap texture"),
anno::description("Allows texturing using image files of various file formats"),
anno::thumbnail(".thumbs/file_texture.png"),
anno::in_group("Texturing, high level"),
anno::ui_order(30),
anno::author("NVIDIA Corporation"),
anno::copyright_notice(COPYRIGHT)
]]
{
return invert == false? base::file_texture(
texture: texture,
mono_source: mono_source,
color_offset: color(0.5*brightness-0.5*contrast*brightness),
color_scale: color(brightness*contrast),
uvw: base::transform_coordinate(
transform: rotation_translation_scale(
scaling: float3(scaling.x, scaling.y, 1.0),
rotation: float3(0.0, 0.0, math::radians(rotation) ),
translation: float3(translation.x, translation.y, 0.0)
),
coordinate: base::coordinate_source(texture_space: texture_space)
),
wrap_u: clip?tex::wrap_clip:tex::wrap_repeat,
wrap_v: clip?tex::wrap_clip:tex::wrap_repeat
): base::file_texture(
texture: texture,
mono_source: mono_source,
color_offset: color(1.0-0.5*brightness+0.5*contrast*brightness),
color_scale: color(-brightness*contrast),
uvw: base::transform_coordinate(
transform: rotation_translation_scale(
scaling: float3(scaling.x, scaling.y, 1.0),
rotation: float3(0.0, 0.0, math::radians(rotation) ),
translation: float3(translation.x, translation.y, 0.0)
),
coordinate: base::coordinate_source(texture_space: texture_space)
),
wrap_u: clip?tex::wrap_clip:tex::wrap_repeat,
wrap_v: clip?tex::wrap_clip:tex::wrap_repeat
);
}
export color triplanar_file_texture(
uniform texture_2d texture_1
[[
anno::display_name("Bitmap file"),
anno::in_group("1st Bitmap parameters"),
anno::ui_order(0)
]],
float2 scaling_1 = float2(1.)
[[
anno::description("Controls the scale of the texture on the object"),
anno::display_name("Tiling"),
anno::in_group("1st Bitmap parameters"),
anno::ui_order(1)
]],
float2 translation_1 = float2(0.)
[[
anno::description("Controls position of the texture on the object"),
anno::display_name("Offset"),
anno::in_group("1st Bitmap parameters"),
anno::ui_order(2)
]],
float rotation_1 = 0.
[[
anno::description("Rotation angle of the texture in degrees"),
anno::display_name("Rotation"),
anno::in_group("1st Bitmap parameters"),
anno::ui_order(3),
anno::soft_range(0.0,360.0)
]],
uniform texture_2d texture_2 = texture_2d()
[[
anno::display_name("Bitmap file"),
anno::in_group("2nd Bitmap parameters"),
anno::ui_order(4)
]],
float2 scaling_2 = float2(1.)
[[
anno::description("Controls the scale of the texture on the object"),
anno::display_name("Tiling"),
anno::in_group("2nd Bitmap parameters"),
anno::enable_if( "tex::texture_isvalid(texture_2)" ),
anno::ui_order(5)
]],
float2 translation_2 = float2(0.)
[[
anno::description("Controls position of the texture on the object"),
anno::display_name("Offset"),
anno::in_group("2nd Bitmap parameters"),
anno::enable_if( "tex::texture_isvalid(texture_2)" ),
anno::ui_order(6)
]],
float rotation_2 = 0.
[[
anno::description("Rotation angle of the texture in degrees"),
anno::display_name("Rotation"),
anno::in_group("2nd Bitmap parameters"),
anno::ui_order(7),
anno::enable_if( "tex::texture_isvalid(texture_2)" ),
anno::soft_range(0.0,360.0)
]],
uniform texture_2d texture_3 = texture_2d()
[[
anno::display_name("Bitmap file"),
anno::in_group("3rd Bitmap parameters"),
anno::ui_order(8)
]],
float2 scaling_3 = float2(1.)
[[
anno::description("Controls the scale of the texture on the object"),
anno::display_name("Tiling"),
anno::in_group("3rd Bitmap parameters"),
anno::enable_if( "tex::texture_isvalid(texture_3)" ),
anno::ui_order(9)
]],
float2 translation_3 = float2(0.)
[[
anno::description("Controls position of the texture on the object"),
anno::display_name("Offset"),
anno::in_group("3rd Bitmap parameters"),
anno::enable_if( "tex::texture_isvalid(texture_3)" ),
anno::ui_order(10)
]],
float rotation_3 = 0.
[[
anno::description("Rotation angle of the texture in degrees"),
anno::display_name("Rotation"),
anno::in_group("3rd Bitmap parameters"),
anno::ui_order(11),
anno::enable_if( "tex::texture_isvalid(texture_3)" ),
anno::soft_range(0.0,360.0)
]],
float blend_range = 0.5
[[
anno::description("Defines the size of the transition area. 0 means hard transition, 1 means blending happens very softly."),
anno::display_name("Blend range"),
anno::in_group("Common parameters"),
anno::ui_order(14),
anno::hard_range(0.0,1.0)
]],
uniform color mean = color(0.0)
[[
anno::description("Allows tweaking of the blend function. A value of 0 disables the function."),
anno::display_name("Mean color"),
anno::in_group("Common parameters"),
anno::ui_order(15),
anno::hard_range(color(0.0),color(1.0))
]],
uniform float3 rotate_origin = float3(0.0)
[[
anno::description("Allows manual alignment of the projection with an object"),
anno::display_name("Rotation of origin"),
anno::in_group("Placement"),
anno::ui_order(13),
anno::soft_range(float3(0.0),float3(360.0))
]],
uniform bool object_space = true
[[
anno::description("If off, world space will be used for generating texture coordinates. If on, object space will apply."),
anno::display_name("Use object space"),
anno::in_group("Placement"),
anno::ui_order(12)
]]
)
[[
anno::display_name("Triplanar Bitmap texture"),
anno::description("Allows texturing using image files of various file formats"),
anno::thumbnail(".thumbs/file_texture.png"),
anno::in_group("Texturing, high level"),
anno::ui_order(30),
anno::author("NVIDIA Corporation"),
anno::copyright_notice(COPYRIGHT)
]]
{
state::coordinate_space space = object_space?state::coordinate_object:state::coordinate_world;
float3 normal = state::transform_normal(state::coordinate_internal, space, state::normal());
float3 position = state::transform_point(state::coordinate_internal, space, state::position());
//TODO: pretransform the space? At least rotating the original space seems desireable and more is not feasible without dedicated ui (gizmo)
normal = transform_rotate(normal, math::radians(rotate_origin));
position = transform_rotate(position, math::radians(rotate_origin));
float3 weights = math::abs(normal);
//TODO: blendrange through pow or is there something better? pow has the drawback of needing 3 lookups nearly always
weights /=math::max_value(weights);
weights = math::pow(weights,1./math::max(blend_range, 0.001));
//weights = math::saturate(weights-float3(1.-blend_range));
weights /=float3(weights.x+weights.y+weights.z);
float2 st1 = normal.x>0?float2(-position.z,position.y):float2(-position.z,-position.y);
float2 st2 = normal.y>0?float2(-position.z,-position.x):float2(-position.z,position.x);
float2 st3 = normal.z>0?float2(-position.y,position.x):float2(-position.y,-position.x);
color c1 = weights.x>0?
tex::lookup_color(
texture_1,
transform_st(math::radians(rotation_1),translation_1,scaling_1,st1))
:color(0.);
color c2 = weights.y>0? tex::texture_isvalid(texture_2)?
tex::lookup_color(
texture_2,
transform_st(math::radians(rotation_2),translation_2,scaling_2,st2))
:tex::lookup_color(
texture_1,
transform_st(math::radians(rotation_1),translation_1,scaling_1,st2))
:color(0.);
color c3 = weights.z>0? tex::texture_isvalid(texture_3)?
tex::lookup_color(
texture_3,
transform_st(math::radians(rotation_3),translation_3,scaling_3,st3))
:tex::lookup_color(
texture_1,
transform_st(math::radians(rotation_1),translation_1,scaling_1,st3))
:color(0.);
return mean == color(0.0)?
c1*weights.x + c2*weights.y+ c3*weights.z:
biased_color_blend(weights.x,c1,weights.y,c2,weights.z,c3,mean);
}
export texture_return perlin_noise_texture(
color color1 = color(1.)
[[
anno::display_name("Color 1"),
anno::in_group("Noise parameters"),
anno::ui_order(1)
]],
color color2 = color(0.)
[[
anno::display_name("Color 2"),
anno::in_group("Noise parameters"),
anno::ui_order(2)
]],
uniform bool object_space = true
[[
anno::description("If off, UV space will be used. If on, 3D texturing in object space will apply. For applications that do not support object space, world space will be used."),
anno::display_name("Use object space"),
anno::in_group("Placement"),
anno::ui_order(7)
]],
uniform int noise_levels = 3
[[
anno::description("Higher amounts will add detail to the noise"),
anno::display_name("Levels"),
anno::hard_range(1,6),
anno::in_group("Noise parameters"),
anno::ui_order(3)
]],
uniform bool absolute_noise = false
[[
anno::display_name("Billowing appearance"),
anno::in_group("Noise parameters"),
anno::ui_order(4)
]],
uniform float noise_threshold_high = 1.
[[
anno::hard_range(0.0,1.),
anno::description("Lowering this value will create bigger areas uniformly colored with Color 1"),
anno::display_name("Upper threshold"),
anno::in_group("Noise parameters"),
anno::ui_order(6)
]],
uniform float noise_threshold_low = 0.
[[
anno::hard_range(0.0,1.),
anno::description("Increasing this value will create bigger areas uniformly colored with Color 2"),
anno::display_name("Lower threshold"),
anno::in_group("Noise parameters"),
anno::ui_order(5)
]],
float3 scaling = float3(10.)
[[
anno::description("Controls the scale of the texture on the object"),
anno::display_name("Tiling"),
anno::in_group("Placement"),
anno::ui_order(11)
]],
float3 translation = float3(0.)
[[
anno::description("Controls position of the texture on the object"),
anno::display_name("Offset"),
anno::in_group("Placement"),
anno::ui_order(10)
]],
float3 rotation = float3(0.)
[[
anno::description("Rotation angle of the texture in degrees"),
anno::display_name("Rotation"),
anno::in_group("Placement"),
anno::ui_order(9)
]],
uniform int texture_space = 0
[[
anno::description("Only applies if \"Use object space\" is off. Selects a specific UV space."),
anno::display_name("UV space index"),
anno::hard_range(0,3),
anno::in_group("Placement"),
anno::ui_order(8)
]]
)
[[
anno::display_name("Perlin noise texture"),
anno::description("Enable texturing with a random noise pattern"),
anno::thumbnail(".thumbs/perlin_noise_texture.png"),
anno::in_group("Texturing, high level"),
anno::ui_order(34),
anno::author("NVIDIA Corporation"),
anno::copyright_notice(COPYRIGHT)
]]
{
return base::perlin_noise_texture(
color1: color1,
color2: color2,
noise_levels: noise_levels,
absolute_noise: absolute_noise,
noise_threshold_high: noise_threshold_high,
noise_threshold_low: noise_threshold_low,
uvw: base::transform_coordinate(
transform: rotation_translation_scale(
scaling: object_space?scaling*state::meters_per_scene_unit() :scaling,
translation: translation,
rotation: math::radians(rotation)
),
coordinate: object_space?
base::coordinate_source(coordinate_system: base::texture_coordinate_object):
base::coordinate_source(texture_space: texture_space)
)
);
}
export float3 perlin_noise_bump_texture(
uniform float factor = 1.
[[
anno::display_name("Bump strength"),
anno::in_group("Noise parameters"),
anno::ui_order(0),
anno::soft_range(0.0,5.0)
]],
float3 scaling = float3(10.)
[[
anno::description("Controls the scale of the texture on the object"),
anno::display_name("Tiling"),
anno::in_group("Placement"),
anno::ui_order(9)
]],
uniform int noise_levels = 1
[[
anno::description("Higher amounts will add detail to the noise"),
anno::display_name("Levels"),
anno::hard_range(1,6),
anno::in_group("Noise parameters"),
anno::ui_order(1)
]],
uniform bool object_space = true
[[
anno::description("If off, UV space will be used. If on, 3D texturing in object space will apply. For applications that do not support object space, world space will be used."),
anno::display_name("Use object space"),
anno::in_group("Placement"),
anno::ui_order(5)
]],
uniform bool absolute_noise = false
[[
anno::display_name("Billowing appearance"),
anno::in_group("Noise parameters"),
anno::ui_order(2)
]],
uniform float noise_threshold_high = 1.
[[
anno::hard_range(0.0,1.),
anno::description("Lowering this value will create bigger areas uniformly colored with Color 1"),
anno::display_name("Upper threshold"),
anno::in_group("Noise parameters"),
anno::ui_order(4)
]],
uniform float noise_threshold_low = 0.
[[
anno::hard_range(0.0,1.),
anno::description("Increasing this value will create bigger areas uniformly colored with Color 2"),
anno::display_name("Lower threshold"),
anno::in_group("Noise parameters"),
anno::ui_order(3)
]],
float3 translation = float3(0.)
[[
anno::description("Controls position of the texture on the object"),
anno::display_name("Offset"),
anno::in_group("Placement"),
anno::ui_order(8)
]],
float3 rotation = float3(0.)
[[
anno::description("Rotation angle of the texture in degrees"),
anno::display_name("Rotation"),
anno::in_group("Placement"),
anno::ui_order(7)
]],
uniform int texture_space = 0
[[
anno::description("Only applies if \"Use object space\" is off. Selects a specific UV space."),
anno::display_name("UV space index"),
anno::hard_range(0,3),
anno::in_group("Placement"),
anno::ui_order(6)
]]
)
[[
anno::display_name("Perlin noise texture - bump mapping"),
anno::description("Enable bump-map texturing with a random noise pattern"),
anno::thumbnail(".thumbs/perlin_noise_bump_texture.png"),
anno::in_group("Texturing, high level"),
anno::ui_order(35),
anno::author("NVIDIA Corporation"),
anno::copyright_notice(COPYRIGHT)
]]
{
return base::perlin_noise_bump_texture(
factor: factor,
noise_levels: noise_levels,
absolute_noise: absolute_noise,
noise_threshold_high: noise_threshold_high,
noise_threshold_low: noise_threshold_low,
uvw: base::transform_coordinate(
transform: rotation_translation_scale(
scaling: scaling,
translation: translation,
rotation: math::radians(rotation)
),
coordinate: object_space?
base::coordinate_source(coordinate_system: base::texture_coordinate_object):
base::coordinate_source(texture_space: texture_space)
)
);
}
export texture_return worley_noise_texture(
color color1 = color(1.)
[[
anno::display_name("Color 1"),
anno::in_group("Noise parameters"),
anno::ui_order(0)
]],
color color2 = color(0.)
[[
anno::display_name("Color 2"),
anno::in_group("Noise parameters"),
anno::ui_order(1)
]],
uniform bool object_space = true
[[
anno::description("If off, UV space will be used. If on, 3D texturing in object space will apply. For applications that do not support object space, world space will be used."),
anno::display_name("Use object space") ,
anno::in_group("Placement"),
anno::ui_order(6)
]],
uniform int texture_space = 0
[[
anno::description("Only applies if \"Use object space\" is off. Selects a specific UV space."),
anno::display_name("UV space index"),
anno::hard_range(0,3),
anno::in_group("Placement"),
anno::ui_order(7)
]],
uniform cell_type mode = simple_cells
[[
anno::display_name("Cell type") ,
anno::description("Cell pattern type"),
anno::in_group("Noise parameters"),
anno::ui_order(2)
]],
uniform cell_base metric = circular_cells
[[
anno::display_name("Cell shape") ,
anno::description("The shape of the cell form"),
anno::in_group("Noise parameters"),
anno::ui_order(3)
]],
uniform float noise_threshold_high = 1.
[[
anno::hard_range(0.0,1.),
anno::description("Lowering this value will create bigger areas uniformly colored with Color 1"),
anno::display_name("Upper threshold"),
anno::in_group("Noise parameters"),
anno::ui_order(5)
]],
uniform float noise_threshold_low = 0.
[[
anno::hard_range(0.0,1.),
anno::description("Increasing this value will create bigger areas uniformly colored with Color 2"),
anno::display_name("Lower threshold"),
anno::in_group("Noise parameters"),
anno::ui_order(4)
]],
float3 scaling = float3(10.)
[[
anno::description("Controls the scale of the texture on the object"),
anno::display_name("Tiling"),
anno::in_group("Placement"),
anno::ui_order(10)
]],
float3 translation = float3(0.)
[[
anno::description("Controls position of the texture on the object"),
anno::display_name("Offset"),
anno::in_group("Placement"),
anno::ui_order(9)
]],
float3 rotation = float3(0.)
[[
anno::description("Rotation angle of the texture in degrees"),
anno::display_name("Rotation"),
anno::in_group("Placement"),
anno::ui_order(8)
]])
[[
anno::display_name("Cellular noise texture"),
anno::description("Allow texturing with a cell forming pattern"),
anno::thumbnail(".thumbs/worley_noise_texture.png"),
anno::in_group("Texturing, high level"),
anno::ui_order(36),
anno::author("NVIDIA Corporation"),
anno::copyright_notice(COPYRIGHT)
]]
{
return base::worley_noise_texture(
color1: color1,
color2: color2,
mode: mode==crystal_cells?2:mode==bordered_cells?3:0,
metric: metric,
noise_threshold_high: noise_threshold_high,
noise_threshold_low: noise_threshold_low,
uvw: base::transform_coordinate(
transform: rotation_translation_scale(
scaling: object_space?scaling*state::meters_per_scene_unit() :scaling,
translation: translation,
rotation: math::radians(rotation)
),
coordinate: object_space?
base::coordinate_source(coordinate_system: base::texture_coordinate_object):
base::coordinate_source(texture_space: texture_space)
)
);