-
Notifications
You must be signed in to change notification settings - Fork 3
/
v2_PxrSurface.osl
835 lines (730 loc) · 37.3 KB
/
v2_PxrSurface.osl
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
/*
* Copyright 2018-2020 Laika, LLC. Authored by Mitch Prater.
*
* Licensed under the Apache License Version 2.0 http://apache.org/licenses/LICENSE-2.0,
* or the MIT license http://opensource.org/licenses/MIT, at your option.
*
* This program may not be copied, modified, or distributed except according to those terms.
*/
/*
Material: a single node that combines bxdf and displacement controls.
Each material node has a Material Input connection which is composited OVER
this material's parameter settings, and the result is returned in Material Output.
*/
#include "ikaConstants.h"
#include "material/v2_Displacement.h"
#include "material/v2_PxrSurface.h"
shader v2_PxrSurface
[[
int rfm_nodeid = 1234034,
string rfm_classification = "rendernode/RenderMan/pattern/material",
string help =
"A Material "
"defines its response to light, its surface displacement, and its presence. "
"Other materials of the same type can be composited together to produce a single layered material. "
"The composited result is returned as a <strong>Material Output</strong>. "
"<br/><br/>"
"Note: a material that's connected to this one's <strong>Material Input</strong> "
"is composited OVER this one. "
"<br/><br/>"
"<strong>Material Input</strong><br/>"
" <strong>↓</strong><br/>"
" This Material<br/>"
" <strong>↓</strong><br/>"
"<strong>Material Output</strong>"
"<br/><br/>"
"The output of the final Material node in the chain is connected to a "
"<strong>Material_v2_Shaders</strong> Shading Group, which produces a "
"<em>prmanBxdf</em> and a <em>prmanDisplacement</em> output. "
]]
(
string Notes = ""
[[
int connectable = 0,
string help =
"A Material "
"defines its response to light, its surface displacement, and its presence. "
"Other materials of the same type can be composited together to produce a single layered material. "
"The composited result is returned as a <strong>Material Output</strong>. "
"<br/><br/>"
"Note: a material that's connected to this one's <strong>Material Input</strong> "
"is composited OVER this one. "
"<br/><br/>"
"<strong>Material Input</strong><br/>"
" <strong>↓</strong><br/>"
" This Material<br/>"
" <strong>↓</strong><br/>"
"<strong>Material Output</strong>"
"<br/><br/>"
"The output of the final Material node in the chain is connected to a "
"<strong>Material_v2_Shaders</strong> Shading Group, which produces a "
"<em>prmanBxdf</em> and a <em>prmanDisplacement</em> output. "
]],
/*
* The Input Material data set.
*
* This consists of a vstruct parameter, a material struct parameter, and a set
* of enable parameters for each response. The material struct and response enable
* parameters are members of the vstruct parameter.
*/
// The vstruct parameter. This is the single material connection point
// for all the material parameters in the material struct.
PXRSURFACE_MATERIAL_VSTRUCT( MaterialInput, Material Input,
The connected <strong>Material Input</strong> layers OVER this one:
connect a v2_PxrSurface <strong>Material Output</strong> here to
layer it OVER this material.
),
// The material struct parameter.
PXRSURFACE_MATERIAL_STRUCT( MaterialInput, MatIn ),
// The response Enable parameters. These are linked to a vstructmember of the vstruct parameter.
ALL_ENABLE_PARAMS( MaterialInput, ClearCoat ),
ALL_ENABLE_PARAMS( MaterialInput, PrimarySpecular ),
ALL_ENABLE_PARAMS( MaterialInput, SecondarySpecular ),
RESPONSE_ENABLE_PARAM( MaterialInput, Iridescence ),
SHADINGNORMAL_ENABLE_PARAM( MaterialInput, Iridescence ),
ANISOTROPYDIRECTION_ENABLE_PARAM( MaterialInput, Iridescence ),
RESPONSE_ENABLE_PARAM( MaterialInput, Fuzz ),
SHADINGNORMAL_ENABLE_PARAM( MaterialInput, Fuzz ),
RESPONSE_ENABLE_PARAM( MaterialInput, Diffuse ),
SHADINGNORMAL_ENABLE_PARAM( MaterialInput, Diffuse ),
RESPONSE_ENABLE_PARAM( MaterialInput, Scatter ),
RESPONSE_ENABLE_PARAM( MaterialInput, Subsurface ),
RESPONSE_ENABLE_PARAM( MaterialInput, Glass ),
SHADINGNORMAL_ENABLE_PARAM( MaterialInput, Glass ),
ANISOTROPYDIRECTION_ENABLE_PARAM( MaterialInput, Glass ),
RESPONSE_ENABLE_PARAM( MaterialInput, Glow ),
/*
* This material's user interface parameters.
*/
int Enable = 1
[[
int connectable = 0,
string label = "Enable",
string widget = "checkBox",
string help =
"Turns the computation of this Material On/Off. "
"When disabled, this material will not be included in any layered set of materials: its "
"<strong>Material Input</strong> will be copied directly to its <strong>Material Output</strong>. "
]],
float Mask = 1.0
[[
string label = "Mask",
int slider = 1, float slidermin = 0.0, float slidermax = 1.0,
string help =
"This material <strong>Mask</strong> (a.k.a. Opacity, Alpha, Matte, Presence, etc.) "
"determines the distribution of this material layer: where it is versus where it isn't. "
"Specifically, it controls the blend between this material and the material "
"composited UNDER it. "
]],
//
// Bxdf parameters start here.
//
normal Global_ShadingNormal = normal( 0.0 )
[[
string page = "Global",
string label = "Shading Normal",
string help =
"An alternate shading normal to use for all responses. "
"If an individual response specifies its own shading normal values, "
"they will override these settings. "
]],
float Global_UseShadingNormal = 1.0
[[
string page = "Global",
string label = "Use Shading Normal",
int slider = 1, float slidermin = 0.0, float slidermax = 1.0,
string help =
"How much of the connected <strong>Shading Normal</strong> is used? "
"This is a mix between the regular (potentially displaced) shading normal <strong>N</strong>, "
"and the connected <strong>Shading Normal</strong> value. "
"<br/><br/>"
"Note: this has no effect if the <strong>Shading Normal</strong> is unconnected. "
]],
color Global_ShadowColor = color( 0.0 )
[[
string page = "Global",
string label = "Shadow Color",
string help =
"Sets the color of the shadows cast by this material. "
]],
color Global_UserColor = color( 0.0 )
[[
string page = "Global",
string label = "User Color",
string help =
"<strong>User Color</strong> is output in LPE user lobe 4: <strong>U4</strong> "
]],
// Clearcoat response.
CLEARCOAT_UI_DECLARE( Clear Coat, ClearCoat,
<strong>Clear Coat</strong> represents a clear specular layer applied over all the other
responses. It can be truly clear. Or it can optionally absorb colored light from the layers
below it to tint the overall response.
, ClearCoat_RoughnessUIDefault ),
// Primary specular response.
SPECULAR_UI_DECLARE( Primary Specular, PrimarySpecular,
<strong>Primary Specular</strong> is the first of two 'standard' specular responses.
It is capable of producing a broad range of response types from artistic
to physically based and dielectric to metallic.
, PrimarySpecular_RoughnessUIDefault ),
// Secondary specular response.
SPECULAR_UI_DECLARE( Secondary Specular, SecondarySpecular,
<strong>Secondary Specular</strong> is the second of two 'standard' specular responses.
It is capable of producing a broad range of response types from artistic
to physically based and dielectric to metallic.
, SecondarySpecular_RoughnessUIDefault ),
// Iridescence response.
IRIDESCENCE_UI_DECLARE(
<strong>Iridescence</strong> is a special type of specular response.
It produces the effects of thin-film interference and can be controlled
using Artistic or Physically based controls.
),
// Fuzz response.
FUZZ_UI_DECLARE(
<strong>Fuzz</strong> produces scattering of the illumination in
a boundry layer on the surface. It is implemented as a Marschner
hair primary reflection response (R component) where the hair fibers
are oriented in the direction of the shading normal.
),
// Diffuse response.
DIFFUSE_UI_DECLARE(
<strong>Diffuse</strong> uses an Oren-Nayar response model employing
a Roughness parameter to control the deviation of micro-facet normals.
),
// Scatter response.
SCATTER_UI_DECLARE(
<strong>Scatter</strong> produces (single) scattering through the interior
of an object. It has many controls for altering the physical and artistic
characteristics of the response.
Its main feature is the ability to alter the directionality of the scattering
from forward to backward to isotropic.
),
// Subsurface response.
SUBSURFACE_UI_DECLARE(
<strong>Subsurface</strong> produces multiple scattering through the interior
of an object. It has many controls for altering the physical and artistic
characteristics of the response.
),
// Scatter & Subsurface controls.
color ScatterAndSubsurface_IlluminationTint = color( 1.0 )
[[
string page = "Scatter And Subsurface",
string label = "Illumination Tint",
string help =
"Tints the incoming illumination prior to being used in the "
"<strong>Scatter</strong> and <strong>Subsurface</strong> response computations. "
"In light linear space. "
]],
float ScatterAndSubsurface_Roughness = 0.0
[[
string page = "Scatter And Subsurface",
string label = "Roughness",
int slider = 1, float slidermin = 0.0, float slidermax = 1.0,
string help =
"Controls the diffuse micro-facet surface roughness used in the "
"<strong>Scatter</strong> and <strong>Subsurface</strong> response computations. "
"Increasing <strong>Roughness</strong> causes the rays penetrating into "
"the material to have an increasingly broader range of directions than lower "
"<strong>Roughness</strong> values. This tends to slightly darken the overall response, "
"as the light is more widely dispersed prior to entering the material. "
]],
// Glass response.
GLASS_UI_DECLARE(
<strong>Glass</strong> produces a physically-based glass that
includes <strong>Reflection</strong> and <strong>Refraction</strong>.
It has many controls for altering the physical properties of the glass
including its interior.
),
// Glow response.
EGC_UI_DECLARE( Glow, Glow,
<strong>Glow</strong> can make an object appear to emit light.
<br/><br/>
Note: this is not an efficient way to illuminate a scene and would require
indirect bounces to be at least 2 to be effective. This should instead be
used simply as a shading effect and not for actual lighting.
),
//
// Displacement parameters start here.
//
float Displacement_Thickness = 0.0
[[
string page = "Displacement",
string label = "Thickness",
int slider = 1, float slidermin = 0.0, float slidermax = 1.0,
string help =
"<strong>Thickness</strong> determines the degree to which this material will "
"cover over the displacement of the underlying material (the one connected to "
"<strong>Material Output</strong>). "
"<br/><br/>"
"When 0, this material has no thickness, so it will be applied directly "
"to, and exactly follow, the underlying material's displaced surface. "
"<br/><br/>"
"When 1, this material is completely 'thick', so it will be applied to the underlying "
"material's smooth <strong>Covering Height</strong> surface. "
]],
float Displacement_BumpPercent = 1.0
[[
string page = "Displacement",
string label = "Bump Percent",
int slider = 1, float slidermin = 0.0, float slidermax = 2.0,
string help =
"How much of the displaced surface normal is used in shading? "
"<br/><br/>"
"Values greater than 1 <em>accentuate</em> the shading effects of the displacement. "
"<br/><br/>"
"Values less than 1 <em>diminish</em> the shading effects of any displacement. "
"The result of this can be used as a simple substitute for subsurface scattering effects. "
"<br/><br/>"
"Note: any time the shading normal doesn't match the geometry's normal "
"(<strong>Bump Percent</strong> ≠ 1), there is the possibility "
"of artifacts in the shaded result - particularly when <strong>Bump Percent</strong> > 1. "
"You've been warned. "
]],
float Displacement_CoveringHeight = 0.0
[[
string page = "Displacement",
string label = "Covering Height",
int slider = 1, float slidermin = 0.0, float slidermax = 5.0, float slidercenter = 0.5,
string help =
"Sets the height (in <strong>Mag Space</strong>) of a uniformly displaced surface that's "
"produced when this material is completely covered by an overlying material: i.e. when that "
"material's <strong>Thickness</strong> = 1. "
"<br/><br/>"
"It is the height of a level surface that's intended to cover the peaks of this "
"material's displacement. "
"A good starting number is (0.25 + 0.5*Position)*(Magnitude), or, assuming Position=0, "
"0.25*Magnitude. "
"<br/><br/>"
"If <strong>Covering Height</strong> is left at 0, the original geometric surface is used. "
]],
string Displacement_MagSpace = "world"
[[
int connectable = 0,
string page = "Displacement",
string label = "Mag Space",
string widget = "popup", int editable = 1,
string options = "common|world|object",
string help =
"Selects the <strong>Space</strong> in which the Displacement <strong>Covering Height</strong> "
"and Float and Vector <strong>Magnitude</strong> units are specified. "
]],
float Displacement_MagScale = 1.0
[[
string page = "Displacement",
string label = "Mag Scale",
int slider = 1, float slidermin = 0.0, float slidermax = 10.0, float slidercenter = 1.0,
string help =
"An overall <strong>Scale</strong> applied to <em>all</em> the Input Float "
"and Vector <strong>Magnitudes.</strong> "
]],
// Float displacements.
normal Displacement_Float_Nn = normal(0.0)
[[
string page = "Displacement.Float",
string label = "Nn",
string help =
"Use this <em>common</em> space surface normal for the <strong>Float</strong> displacement "
"directions. Defaults to the surface normal <strong>N</strong> if left un-connected. "
"<br/><br/>"
"Note: this <strong><em>must</em></strong> be connected to set it: "
"<u>manually entering values will not work</u>. "
]],
DISPLACE_FLOAT_UI_DECLARE(0),
DISPLACE_FLOAT_UI_DECLARE(1),
DISPLACE_FLOAT_UI_DECLARE(2),
DISPLACE_FLOAT_UI_DECLARE(3),
DISPLACE_FLOAT_UI_DECLARE(4),
// Vector displacements.
string Displacement_Vector_DirSpace = "Mag Space Value"
[[
int connectable = 0,
string page = "Displacement.Vector",
string label = "Dir Space",
string widget = "popup", int editable = 1,
string options = "Mag Space Value|common|world|object",
string help =
"The coordinate system in which the Vector <strong>Input</strong> <em>Directions</em> are specified. "
"You may also enter the name of your own coordinate system. "
"<br/><br/>"
"Note: it is assumed the <strong>Input</strong> vectors have a maximum length of 1. "
"<strong>Mag Space</strong> and <strong>Magnitude</strong> therefore determine their "
"amount of displacement. "
"<br/><br/>"
"<strong>Dir Space</strong> however, specifies their orientation (direction): "
"vector direction and magnitude are separate characteristics. "
]],
DISPLACE_VECTOR_UI_DECLARE(0),
DISPLACE_VECTOR_UI_DECLARE(1),
DISPLACE_VECTOR_UI_DECLARE(2),
DISPLACE_VECTOR_UI_DECLARE(3),
DISPLACE_VECTOR_UI_DECLARE(4),
// Utility socket.
int Socket = 0
[[
string help =
"Connect a shading node's <strong>Plug</strong> output here in order to execute that node and "
"any shading tree connected to it. "
]],
/*
* The Output Material data set.
*
* This consists of a vstruct parameter, a material struct parameter, and a set
* of enable parameters for each response. The material struct and response enable
* parameters are members of the vstruct parameter.
*/
output PXRSURFACE_MATERIAL_VSTRUCT( MaterialOutput, Material Output,
Connect this to another v2_PxrSurface material shader's <strong>Material Input</strong>
to layer this <em>OVER</em> it.
<br/><br/>
If this is the last in the material layering chain - connect it to a
<strong>v2_PxrSurfaceAdapter</strong> node.
),
// The struct parameter.
output PXRSURFACE_MATERIAL_STRUCT( MaterialOutput, MatOut ),
// Set the output vstruct Enable parameters based on the input Enable value and user parameter settings.
SET_ALL_ENABLE_PARAMS( MaterialOutput, MaterialInput, ClearCoat ),
SET_ALL_ENABLE_PARAMS( MaterialOutput, MaterialInput, PrimarySpecular ),
SET_ALL_ENABLE_PARAMS( MaterialOutput, MaterialInput, SecondarySpecular ),
SET_RESPONSE_ENABLE_PARAM( MaterialOutput, MaterialInput, Iridescence ),
SET_SHADINGNORMAL_ENABLE_PARAM( MaterialOutput, MaterialInput, Iridescence ),
SET_ANISOTROPYDIRECTION_ENABLE_PARAM( MaterialOutput, MaterialInput, Iridescence ),
SET_RESPONSE_ENABLE_PARAM( MaterialOutput, MaterialInput, Fuzz ),
SET_SHADINGNORMAL_ENABLE_PARAM( MaterialOutput, MaterialInput, Fuzz ),
SET_RESPONSE_ENABLE_PARAM( MaterialOutput, MaterialInput, Diffuse ),
SET_SHADINGNORMAL_ENABLE_PARAM( MaterialOutput, MaterialInput, Diffuse ),
SET_RESPONSE_ENABLE_PARAM( MaterialOutput, MaterialInput, Scatter ),
SET_RESPONSE_ENABLE_PARAM( MaterialOutput, MaterialInput, Subsurface ),
SET_RESPONSE_ENABLE_PARAM( MaterialOutput, MaterialInput, Glass ),
SET_SHADINGNORMAL_ENABLE_PARAM( MaterialOutput, MaterialInput, Glass ),
SET_ANISOTROPYDIRECTION_ENABLE_PARAM( MaterialOutput, MaterialInput, Glass ),
SET_RESPONSE_ENABLE_PARAM( MaterialOutput, MaterialInput, Glow )
)
/*
* Material functionality: Output = Input OVER this.
*/
{
// Pull on the Socket to make sure it's evaluated.
MatOut.socket = Socket;
// Short-circuit this material.
if( Enable == 0 )
{
MatOut = MatIn;
}
// Note: using a return statement in the if case above breaks functionality,
// so must use this else clause.
// My guess is the osl optimizer is mucking with the proper behavior.
else
{
// Max of all active material Mask values.
MatOut.maxMask = max( Mask, MatIn.maxMask );
// Initialize this material's mask values.
float bxdfMask = Mask; // this_bxdfMask
float dispMask = Mask; // this_dispMask
//
// Displacement.
//
vector this_deltaP;
vector this_coverV;
// The covering height surface offset vector for this material.
// Nmag is common space direction with length relative to Mag Space.
// Note: must use a normal transform to get the proper scale.
normal Nn = normalize(N);
normal Nmag = Nn * length( transform( "common", Displacement_MagSpace, Nn )); // normal
this_coverV = Nmag * Displacement_CoveringHeight;
// Float displacements.
if( isconnected( Displacement_Float_Nn ))
{
Nn = Displacement_Float_Nn;
Nmag = Nn * length( transform( "common", Displacement_MagSpace, Nn )); // normal
}
// Add float displacements to the deltaP displacement vector.
float floatDisp = DISPLACE_FLOAT_AMOUNT(0)
+ DISPLACE_FLOAT_AMOUNT(1)
+ DISPLACE_FLOAT_AMOUNT(2)
+ DISPLACE_FLOAT_AMOUNT(3)
+ DISPLACE_FLOAT_AMOUNT(4);
this_deltaP = Nmag * floatDisp;
// Vector displacements.
// Magnitude and Direction are handled separately.
string directionSpace = ( Displacement_Vector_DirSpace != "Mag Space Value" )
? Displacement_Vector_DirSpace : Displacement_MagSpace;
// Add vector displacements to the deltaP displacement vector.
vector vectorDisp = DISPLACE_VECTOR_AMOUNT( 0, directionSpace, Displacement_MagSpace )
+ DISPLACE_VECTOR_AMOUNT( 1, directionSpace, Displacement_MagSpace )
+ DISPLACE_VECTOR_AMOUNT( 2, directionSpace, Displacement_MagSpace )
+ DISPLACE_VECTOR_AMOUNT( 3, directionSpace, Displacement_MagSpace )
+ DISPLACE_VECTOR_AMOUNT( 4, directionSpace, Displacement_MagSpace );
this_deltaP += vectorDisp;
// Globally scale the displacement. Displacement_MagScale is unitless.
this_deltaP *= Displacement_MagScale;
// Pre-multiply by the displacement mask.
this_deltaP *= dispMask;
this_coverV *= dispMask;
// Note: coverV is not composited. It is only communicated
// with the immediately overlying material layer.
MatOut.coverV = this_coverV;
// Displacement compositing.
// Note: displacement is NOT Porter-Duff OVER operation composited.
MatOut.deltaP = MatIn.deltaP + mix(
this_deltaP,
this_coverV,
MatIn.thickness
);
// Thickness accumulates through all the layers, since layer displacements all accumulate.
// Any overlying layer's thickness will apply to all layers below it, so always pass on the
// largest thickness value.
MatOut.thickness = max( MatIn.thickness, Displacement_Thickness*dispMask );
// Composite the dispMask.
MatOut.dispMask = MatIn.dispMask + dispMask*( 1.0 - MatIn.dispMask );
//
// Bxdf shader parameters start here.
// Note: Gain = 1.0, and Color = Gain*Color. This eliminates false
// colors resulting from interpolating these parameters separately.
//
// Porter-Duff pre-multiplied alpha(mask) compositing OVER operation.
// Out = In over Ui:
// Out = In*In_Mask*1 + Ui*Ui_Mask*(1 - In_Mask)
// Out_Mask = In_Mask*1 + Ui_Mask*(1 - In_Mask)
//
// Composited output mask defines where the input material and this material exist.
MatOut.bxdfMask = MatIn.bxdfMask + bxdfMask*( 1.0 - MatIn.bxdfMask );
PARAM_OVER( MatOut, MatIn, Displacement, BumpPercent, bxdfMask );
PARAM_OVER( MatOut, MatIn, Global, ShadowColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, Global, UserColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, Global, ShadingNormal, bxdfMask );
// This material's Global_UseShadingNormal value is 0 if its Global_ShadingNormal is not connected.
float useShadingNormal = isconnected( Global_ShadingNormal ) ? Global_UseShadingNormal : 0.0;
MatOut.Global_UseShadingNormal = MatIn.Global_UseShadingNormal
+ useShadingNormal*bxdfMask*( 1.0 - MatIn.bxdfMask );
// ClearCoat
if( ClearCoat_Enable )
{
MatOut.ClearCoat_CG = MatIn.ClearCoat_CG
+ ( ClearCoat_Gain*ClearCoat_Color*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.ClearCoat_FaceCG = MatIn.ClearCoat_FaceCG
+ ( ClearCoat_Gain*ClearCoat_FaceColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.ClearCoat_RefractionCI = MatIn.ClearCoat_RefractionCI
+ ( ClearCoat_RefractionIndex*ClearCoat_RefractionColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
PARAM_OVER( MatOut, MatIn, ClearCoat, FresnelExponent, bxdfMask );
PARAM_OVER( MatOut, MatIn, ClearCoat, LayerThickness, bxdfMask );
PARAM_OVER( MatOut, MatIn, ClearCoat, LayerColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, ClearCoat, Roughness, bxdfMask );
PARAM_OVER( MatOut, MatIn, ClearCoat, Anisotropy, bxdfMask );
PARAM_OVER( MatOut, MatIn, ClearCoat, AnisotropyDirection, bxdfMask );
PARAM_OVER( MatOut, MatIn, ClearCoat, ShadingNormal, bxdfMask );
float useAnisotropyDirection = isconnected( ClearCoat_AnisotropyDirection ) ? 1.0 : 0.0;
MatOut.ClearCoat_UseAnisotropyDirection = MatIn.ClearCoat_UseAnisotropyDirection
+ useAnisotropyDirection*bxdfMask*( 1.0 - MatIn.bxdfMask );
float useShadingNormal = isconnected( ClearCoat_ShadingNormal ) ? ClearCoat_UseShadingNormal : 0.0;
MatOut.ClearCoat_UseShadingNormal = MatIn.ClearCoat_UseShadingNormal
+ useShadingNormal*bxdfMask*( 1.0 - MatIn.bxdfMask );
}
else
{
CLEARCOAT_COPY( MatOut, MatIn, ClearCoat );
}
// PrimarySpecular
if( PrimarySpecular_Enable )
{
MatOut.PrimarySpecular_CG = MatIn.PrimarySpecular_CG
+ ( PrimarySpecular_Gain*PrimarySpecular_Color*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.PrimarySpecular_FaceCG = MatIn.PrimarySpecular_FaceCG
+ ( PrimarySpecular_Gain*PrimarySpecular_FaceColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.PrimarySpecular_RefractionCI = MatIn.PrimarySpecular_RefractionCI
+ ( PrimarySpecular_RefractionIndex*PrimarySpecular_RefractionColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.PrimarySpecular_ExtinctionCC = MatIn.PrimarySpecular_ExtinctionCC
+ ( PrimarySpecular_ExtinctionCoeff*PrimarySpecular_ExtinctionColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
PARAM_OVER( MatOut, MatIn, PrimarySpecular, FresnelExponent, bxdfMask );
PARAM_OVER( MatOut, MatIn, PrimarySpecular, Roughness, bxdfMask );
PARAM_OVER( MatOut, MatIn, PrimarySpecular, Anisotropy, bxdfMask );
PARAM_OVER( MatOut, MatIn, PrimarySpecular, AnisotropyDirection, bxdfMask );
PARAM_OVER( MatOut, MatIn, PrimarySpecular, ShadingNormal, bxdfMask );
float useAnisotropyDirection = isconnected( PrimarySpecular_AnisotropyDirection ) ? 1.0 : 0.0;
MatOut.PrimarySpecular_UseAnisotropyDirection = MatIn.PrimarySpecular_UseAnisotropyDirection
+ useAnisotropyDirection*bxdfMask*( 1.0 - MatIn.bxdfMask );
float useShadingNormal = isconnected( PrimarySpecular_ShadingNormal ) ? PrimarySpecular_UseShadingNormal : 0.0;
MatOut.PrimarySpecular_UseShadingNormal = MatIn.PrimarySpecular_UseShadingNormal
+ useShadingNormal*bxdfMask*( 1.0 - MatIn.bxdfMask );
}
else
{
SPECULAR_COPY( MatOut, MatIn, PrimarySpecular );
}
// SecondarySpecular
if( SecondarySpecular_Enable )
{
MatOut.SecondarySpecular_CG = MatIn.SecondarySpecular_CG
+ ( SecondarySpecular_Gain*SecondarySpecular_Color*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.SecondarySpecular_FaceCG = MatIn.SecondarySpecular_FaceCG
+ ( SecondarySpecular_Gain*SecondarySpecular_FaceColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.SecondarySpecular_RefractionCI = MatIn.SecondarySpecular_RefractionCI
+ ( SecondarySpecular_RefractionIndex*SecondarySpecular_RefractionColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.SecondarySpecular_ExtinctionCC = MatIn.SecondarySpecular_ExtinctionCC
+ ( SecondarySpecular_ExtinctionCoeff*SecondarySpecular_ExtinctionColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
PARAM_OVER( MatOut, MatIn, SecondarySpecular, FresnelExponent, bxdfMask );
PARAM_OVER( MatOut, MatIn, SecondarySpecular, Roughness, bxdfMask );
PARAM_OVER( MatOut, MatIn, SecondarySpecular, Anisotropy, bxdfMask );
PARAM_OVER( MatOut, MatIn, SecondarySpecular, AnisotropyDirection, bxdfMask );
PARAM_OVER( MatOut, MatIn, SecondarySpecular, ShadingNormal, bxdfMask );
float useAnisotropyDirection = isconnected( SecondarySpecular_AnisotropyDirection ) ? 1.0 : 0.0;
MatOut.SecondarySpecular_UseAnisotropyDirection = MatIn.SecondarySpecular_UseAnisotropyDirection
+ useAnisotropyDirection*bxdfMask*( 1.0 - MatIn.bxdfMask );
float useShadingNormal = isconnected( SecondarySpecular_ShadingNormal ) ? SecondarySpecular_UseShadingNormal : 0.0;
MatOut.SecondarySpecular_UseShadingNormal = MatIn.SecondarySpecular_UseShadingNormal
+ useShadingNormal*bxdfMask*( 1.0 - MatIn.bxdfMask );
}
else
{
SPECULAR_COPY( MatOut, MatIn, SecondarySpecular );
}
// Iridescence
if( Iridescence_Enable )
{
PARAM_OVER( MatOut, MatIn, Iridescence, Gain, bxdfMask );
PARAM_OVER( MatOut, MatIn, Iridescence, FaceColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, Iridescence, EdgeColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, Iridescence, Exponent, bxdfMask );
PARAM_OVER( MatOut, MatIn, Iridescence, Repetitions, bxdfMask );
PARAM_OVER( MatOut, MatIn, Iridescence, Thickness, bxdfMask );
PARAM_OVER( MatOut, MatIn, Iridescence, Roughness, bxdfMask );
PARAM_OVER( MatOut, MatIn, Iridescence, Anisotropy, bxdfMask );
PARAM_OVER( MatOut, MatIn, Iridescence, AnisotropyDirection, bxdfMask );
PARAM_OVER( MatOut, MatIn, Iridescence, ShadingNormal, bxdfMask );
float useAnisotropyDirection = isconnected( Iridescence_AnisotropyDirection ) ? 1.0 : 0.0;
MatOut.Iridescence_UseAnisotropyDirection = MatIn.Iridescence_UseAnisotropyDirection
+ useAnisotropyDirection*bxdfMask*( 1.0 - MatIn.bxdfMask );
float useShadingNormal = isconnected( Iridescence_ShadingNormal ) ? Iridescence_UseShadingNormal : 0.0;
MatOut.Iridescence_UseShadingNormal = MatIn.Iridescence_UseShadingNormal
+ useShadingNormal*bxdfMask*( 1.0 - MatIn.bxdfMask );
}
else
{
IRIDESCENCE_COPY( MatOut, MatIn, Iridescence );
}
// Fuzz
if( Fuzz_Enable )
{
MatOut.Fuzz_CG = MatIn.Fuzz_CG
+ ( Fuzz_Gain*Fuzz_Color*bxdfMask )*( 1.0 - MatIn.bxdfMask );
PARAM_OVER( MatOut, MatIn, Fuzz, ConeAngle, bxdfMask );
PARAM_OVER( MatOut, MatIn, Fuzz, ShadingNormal, bxdfMask );
float useShadingNormal = isconnected( Fuzz_ShadingNormal ) ? Fuzz_UseShadingNormal : 0.0;
MatOut.Fuzz_UseShadingNormal = MatIn.Fuzz_UseShadingNormal
+ useShadingNormal*bxdfMask*( 1.0 - MatIn.bxdfMask );
}
else
{
FUZZ_COPY( MatOut, MatIn, Fuzz );
}
// Diffuse
if( Diffuse_Enable )
{
MatOut.Diffuse_CG = MatIn.Diffuse_CG
+ ( Diffuse_Gain*Diffuse_Color*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.Diffuse_BackfaceCG = MatIn.Diffuse_BackfaceCG
+ ( Diffuse_BackfaceGain*Diffuse_BackfaceColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.Diffuse_TransmitCG = MatIn.Diffuse_TransmitCG
+ ( Diffuse_TransmitGain*Diffuse_TransmitColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
PARAM_OVER( MatOut, MatIn, Diffuse, Roughness, bxdfMask );
PARAM_OVER( MatOut, MatIn, Diffuse, Exponent, bxdfMask );
PARAM_OVER( MatOut, MatIn, Diffuse, ShadingNormal, bxdfMask );
float useShadingNormal = isconnected( Diffuse_ShadingNormal ) ? Diffuse_UseShadingNormal : 0.0;
MatOut.Diffuse_UseShadingNormal = MatIn.Diffuse_UseShadingNormal
+ useShadingNormal*bxdfMask*( 1.0 - MatIn.bxdfMask );
}
else
{
DIFFUSE_COPY( MatOut, MatIn, Diffuse );
}
// Scatter
if( Scatter_Enable )
{
MatOut.Scatter_CG = MatIn.Scatter_CG
+ ( Scatter_Gain*Scatter_Color*bxdfMask )*( 1.0 - MatIn.bxdfMask );
// Backside_CG = (Backside) IlluminationGain * (Backside) IlluminationTint
MatOut.Scatter_BacksideCG = MatIn.Scatter_BacksideCG
+ ( Scatter_IlluminationGain*Scatter_IlluminationTint*bxdfMask )*( 1.0 - MatIn.bxdfMask );
PARAM_OVER( MatOut, MatIn, Scatter, PathLength, bxdfMask );
PARAM_OVER( MatOut, MatIn, Scatter, PathColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, Scatter, Direction, bxdfMask );
PARAM_OVER( MatOut, MatIn, Scatter, Roughness, bxdfMask );
PARAM_OVER( MatOut, MatIn, Scatter, RefractionIndex, bxdfMask );
}
else
{
SCATTER_COPY( MatOut, MatIn, Scatter );
}
// Subsurface
if( Subsurface_Enable )
{
PARAM_OVER( MatOut, MatIn, Subsurface, Gain, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, Color, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, PathLength, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, PathColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, PostTint, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, TransmitGain, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, ShortGain, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, ShortColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, ShortLength, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, LongGain, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, LongColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, LongLength, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, Directionality, bxdfMask );
// XXX PARAM_OVER( MatOut, MatIn, Subsurface, DiffuseBlend, bxdfMask );
PARAM_OVER( MatOut, MatIn, Subsurface, Bleed, bxdfMask );
}
else
{
SUBSURFACE_COPY( MatOut, MatIn, Subsurface );
}
// Scatter & Subsurface
if( Scatter_Enable || Subsurface_Enable )
{
PARAM_OVER( MatOut, MatIn, ScatterAndSubsurface, IlluminationTint, bxdfMask );
PARAM_OVER( MatOut, MatIn, ScatterAndSubsurface, Roughness, bxdfMask );
}
else
{
MatOut.ScatterAndSubsurface_IlluminationTint = MatIn.ScatterAndSubsurface_IlluminationTint;
MatOut.ScatterAndSubsurface_Roughness = MatIn.ScatterAndSubsurface_Roughness;
}
// Glass
if( Glass_Enable )
{
PARAM_OVER( MatOut, MatIn, Glass, ReflectionGain, bxdfMask );
PARAM_OVER( MatOut, MatIn, Glass, Roughness, bxdfMask );
PARAM_OVER( MatOut, MatIn, Glass, Anisotropy, bxdfMask );
PARAM_OVER( MatOut, MatIn, Glass, AnisotropyDirection, bxdfMask );
PARAM_OVER( MatOut, MatIn, Glass, ShadingNormal, bxdfMask );
float useAnisotropyDirection = isconnected( Glass_AnisotropyDirection ) ? 1.0 : 0.0;
MatOut.Glass_UseAnisotropyDirection = MatIn.Glass_UseAnisotropyDirection
+ useAnisotropyDirection*bxdfMask*( 1.0 - MatIn.bxdfMask );
float useShadingNormal = isconnected( Glass_ShadingNormal ) ? Glass_UseShadingNormal : 0.0;
MatOut.Glass_UseShadingNormal = MatIn.Glass_UseShadingNormal
+ useShadingNormal*bxdfMask*( 1.0 - MatIn.bxdfMask );
// Refraction.
MatOut.Glass_RefractionCG = MatIn.Glass_RefractionCG
+ ( Glass_RefractionGain*Glass_RefractionColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
MatOut.Glass_ExtinctionCC = MatIn.Glass_ExtinctionCC
+ ( Glass_ExtinctionCoeff*Glass_ExtinctionColor*bxdfMask )*( 1.0 - MatIn.bxdfMask );
PARAM_OVER( MatOut, MatIn, Glass, RefractionIndex, bxdfMask );
PARAM_OVER( MatOut, MatIn, Glass, ScatterColor, bxdfMask );
PARAM_OVER( MatOut, MatIn, Glass, ManifoldExplorationIOR, bxdfMask );
}
else
{
GLASS_COPY( MatOut, MatIn, Glass );
}
// Glow
if( Glow_Enable )
{
MatOut.Glow_CG = MatIn.Glow_CG
+ ( Glow_Gain*Glow_Color*bxdfMask )*( 1.0 - MatIn.bxdfMask );
}
else
{
GLOW_COPY( MatOut, MatIn, Glow );
}
// This bxdfMask is only where this material is.
bxdfMask = bxdfMask*( 1.0 - MatIn.bxdfMask );
}
}