/
MixedRealityStandard.shader
1259 lines (1094 loc) · 50.6 KB
/
MixedRealityStandard.shader
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) Microsoft Corporation.
// Licensed under the MIT License.
// NOTE: MRTK Shaders are versioned via the MRTK.Shaders.sentinel file.
// When making changes to any shader's source file, the value in the sentinel _must_ be incremented.
Shader "Mixed Reality Toolkit/Standard"
{
Properties
{
// Main maps.
_Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
_MainTex("Albedo", 2D) = "white" {}
[Enum(AlbedoAlphaMode)] _AlbedoAlphaMode("Albedo Alpha Mode", Float) = 0 // "Transparency"
[Toggle] _AlbedoAssignedAtRuntime("Albedo Assigned at Runtime", Float) = 0.0
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_Metallic("Metallic", Range(0.0, 1.0)) = 0.0
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
[Toggle(_CHANNEL_MAP)] _EnableChannelMap("Enable Channel Map", Float) = 0.0
[NoScaleOffset] _ChannelMap("Channel Map", 2D) = "white" {}
[Toggle(_NORMAL_MAP)] _EnableNormalMap("Enable Normal Map", Float) = 0.0
[NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {}
_NormalMapScale("Scale", Float) = 1.0
[Toggle(_EMISSION)] _EnableEmission("Enable Emission", Float) = 0.0
[HDR]_EmissiveColor("Emissive Color", Color) = (0.0, 0.0, 0.0, 1.0)
[Toggle(_TRIPLANAR_MAPPING)] _EnableTriplanarMapping("Triplanar Mapping", Float) = 0.0
[Toggle(_USE_SSAA)] _EnableSSAA("Super Sample Anti Aliasing", Float) = 0.0
_MipmapBias("Mipmap Bias", Range(-5.0, 0.0)) = -2.0
[Toggle(_LOCAL_SPACE_TRIPLANAR_MAPPING)] _EnableLocalSpaceTriplanarMapping("Local Space", Float) = 0.0
_TriplanarMappingBlendSharpness("Blend Sharpness", Range(1.0, 16.0)) = 4.0
// Rendering options.
[Toggle(_DIRECTIONAL_LIGHT)] _DirectionalLight("Directional Light", Float) = 1.0
[Toggle(_SPECULAR_HIGHLIGHTS)] _SpecularHighlights("Specular Highlights", Float) = 1.0
[Toggle(_SPHERICAL_HARMONICS)] _SphericalHarmonics("Spherical Harmonics", Float) = 0.0
[Toggle(_REFLECTIONS)] _Reflections("Reflections", Float) = 0.0
[Toggle(_REFRACTION)] _Refraction("Refraction", Float) = 0.0
_RefractiveIndex("Refractive Index", Range(0.0, 3.0)) = 0.0
[Toggle(_RIM_LIGHT)] _RimLight("Rim Light", Float) = 0.0
_RimColor("Rim Color", Color) = (0.5, 0.5, 0.5, 1.0)
_RimPower("Rim Power", Range(0.0, 8.0)) = 0.25
[Toggle(_VERTEX_COLORS)] _VertexColors("Vertex Colors", Float) = 0.0
[Toggle(_VERTEX_EXTRUSION)] _VertexExtrusion("Vertex Extrusion", Float) = 0.0
_VertexExtrusionValue("Vertex Extrusion Value", Float) = 0.0
[Toggle(_VERTEX_EXTRUSION_SMOOTH_NORMALS)] _VertexExtrusionSmoothNormals("Vertex Extrusion Smooth Normals", Float) = 0.0
_BlendedClippingWidth("Blended Clipping With", Range(0.0, 10.0)) = 1.0
[Toggle(_CLIPPING_BORDER)] _ClippingBorder("Clipping Border", Float) = 0.0
_ClippingBorderWidth("Clipping Border Width", Range(0.0, 1.0)) = 0.025
_ClippingBorderColor("Clipping Border Color", Color) = (1.0, 0.2, 0.0, 1.0)
[Toggle(_NEAR_PLANE_FADE)] _NearPlaneFade("Near Plane Fade", Float) = 0.0
[Toggle(_NEAR_LIGHT_FADE)] _NearLightFade("Near Light Fade", Float) = 0.0
_FadeBeginDistance("Fade Begin Distance", Range(0.0, 10.0)) = 0.85
_FadeCompleteDistance("Fade Complete Distance", Range(0.0, 10.0)) = 0.5
_FadeMinValue("Fade Min Value", Range(0.0, 1.0)) = 0.0
// Fluent options.
[Toggle(_HOVER_LIGHT)] _HoverLight("Hover Light", Float) = 1.0
[Toggle(_HOVER_COLOR_OVERRIDE)] _EnableHoverColorOverride("Hover Color Override", Float) = 0.0
_HoverColorOverride("Hover Color Override", Color) = (1.0, 1.0, 1.0, 1.0)
[Toggle(_PROXIMITY_LIGHT)] _ProximityLight("Proximity Light", Float) = 0.0
[Toggle(_PROXIMITY_LIGHT_COLOR_OVERRIDE)] _EnableProximityLightColorOverride("Proximity Light Color Override", Float) = 0.0
[HDR]_ProximityLightCenterColorOverride("Proximity Light Center Color Override", Color) = (1.0, 0.0, 0.0, 0.0)
[HDR]_ProximityLightMiddleColorOverride("Proximity Light Middle Color Override", Color) = (0.0, 1.0, 0.0, 0.5)
[HDR]_ProximityLightOuterColorOverride("Proximity Light Outer Color Override", Color) = (0.0, 0.0, 1.0, 1.0)
[Toggle(_PROXIMITY_LIGHT_SUBTRACTIVE)] _ProximityLightSubtractive("Proximity Light Subtractive", Float) = 0.0
[Toggle(_PROXIMITY_LIGHT_TWO_SIDED)] _ProximityLightTwoSided("Proximity Light Two Sided", Float) = 0.0
_FluentLightIntensity("Fluent Light Intensity", Range(0.0, 1.0)) = 1.0
[Toggle(_ROUND_CORNERS)] _RoundCorners("Round Corners", Float) = 0.0
_RoundCornerRadius("Round Corner Radius", Range(0.0, 0.5)) = 0.25
_RoundCornerMargin("Round Corner Margin", Range(0.0, 0.5)) = 0.01
[Toggle(_INDEPENDENT_CORNERS)] _IndependentCorners("Independent Corners", Float) = 0.0
_RoundCornersRadius("Round Corners Radius", Vector) = (0.5 ,0.5, 0.5, 0.5)
[Toggle(_BORDER_LIGHT)] _BorderLight("Border Light", Float) = 0.0
[Toggle(_BORDER_LIGHT_USES_HOVER_COLOR)] _BorderLightUsesHoverColor("Border Light Uses Hover Color", Float) = 0.0
[Toggle(_BORDER_LIGHT_REPLACES_ALBEDO)] _BorderLightReplacesAlbedo("Border Light Replaces Albedo", Float) = 0.0
[Toggle(_BORDER_LIGHT_OPAQUE)] _BorderLightOpaque("Border Light Opaque", Float) = 0.0
_BorderWidth("Border Width", Range(0.0, 1.0)) = 0.1
_BorderMinValue("Border Min Value", Range(0.0, 1.0)) = 0.1
_EdgeSmoothingValue("Edge Smoothing Value", Range(0.0, 0.2)) = 0.002
_BorderLightOpaqueAlpha("Border Light Opaque Alpha", Range(0.0, 1.0)) = 1.0
[Toggle(_INNER_GLOW)] _InnerGlow("Inner Glow", Float) = 0.0
_InnerGlowColor("Inner Glow Color (RGB) and Intensity (A)", Color) = (1.0, 1.0, 1.0, 0.75)
_InnerGlowPower("Inner Glow Power", Range(2.0, 32.0)) = 4.0
[Toggle(_IRIDESCENCE)] _Iridescence("Iridescence", Float) = 0.0
[NoScaleOffset] _IridescentSpectrumMap("Iridescent Spectrum Map", 2D) = "white" {}
_IridescenceIntensity("Iridescence Intensity", Range(0.0, 1.0)) = 0.5
_IridescenceThreshold("Iridescence Threshold", Range(0.0, 1.0)) = 0.05
_IridescenceAngle("Iridescence Angle", Range(-0.78, 0.78)) = -0.78
[Toggle(_ENVIRONMENT_COLORING)] _EnvironmentColoring("Environment Coloring", Float) = 0.0
_EnvironmentColorThreshold("Environment Color Threshold", Range(0.0, 3.0)) = 1.5
_EnvironmentColorIntensity("Environment Color Intensity", Range(0.0, 1.0)) = 0.5
_EnvironmentColorX("Environment Color X (RGB)", Color) = (1.0, 0.0, 0.0, 1.0)
_EnvironmentColorY("Environment Color Y (RGB)", Color) = (0.0, 1.0, 0.0, 1.0)
_EnvironmentColorZ("Environment Color Z (RGB)", Color) = (0.0, 0.0, 1.0, 1.0)
// Advanced options.
[Enum(RenderingMode)] _Mode("Rendering Mode", Float) = 0 // "Opaque"
[Enum(CustomRenderingMode)] _CustomMode("Mode", Float) = 0 // "Opaque"
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Source Blend", Float) = 1 // "One"
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Destination Blend", Float) = 0 // "Zero"
[Enum(UnityEngine.Rendering.BlendOp)] _BlendOp("Blend Operation", Float) = 0 // "Add"
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("Depth Test", Float) = 4 // "LessEqual"
[Enum(DepthWrite)] _ZWrite("Depth Write", Float) = 1 // "On"
_ZOffsetFactor("Depth Offset Factor", Float) = 0 // "Zero"
_ZOffsetUnits("Depth Offset Units", Float) = 0 // "Zero"
[Enum(UnityEngine.Rendering.ColorWriteMask)] _ColorWriteMask("Color Write Mask", Float) = 15 // "All"
[Enum(UnityEngine.Rendering.CullMode)] _CullMode("Cull Mode", Float) = 2 // "Back"
_RenderQueueOverride("Render Queue Override", Range(-1.0, 5000)) = -1
[Toggle(_IGNORE_Z_SCALE)] _IgnoreZScale("Ignore Z Scale", Float) = 0.0
[Toggle(_STENCIL)] _Stencil("Enable Stencil Testing", Float) = 0.0
_StencilReference("Stencil Reference", Range(0, 255)) = 0
[Enum(UnityEngine.Rendering.CompareFunction)]_StencilComparison("Stencil Comparison", Int) = 0
[Enum(UnityEngine.Rendering.StencilOp)]_StencilOperation("Stencil Operation", Int) = 0
}
SubShader
{
Pass
{
Name "Main"
Tags{ "RenderType" = "Opaque" "LightMode" = "ForwardBase" }
LOD 100
Blend[_SrcBlend][_DstBlend]
BlendOp[_BlendOp]
ZTest[_ZTest]
ZWrite[_ZWrite]
Cull[_CullMode]
Offset[_ZOffsetFactor],[_ZOffsetUnits]
ColorMask[_ColorWriteMask]
Stencil
{
Ref[_StencilReference]
Comp[_StencilComparison]
Pass[_StencilOperation]
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ UNITY_UI_CLIP_RECT
#pragma multi_compile _ _HOVER_LIGHT_MEDIUM _HOVER_LIGHT_HIGH
#pragma multi_compile _ _CLIPPING_PLANE _CLIPPING_SPHERE _CLIPPING_BOX
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON
#pragma shader_feature _DISABLE_ALBEDO_MAP
#pragma shader_feature _ _METALLIC_TEXTURE_ALBEDO_CHANNEL_A _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _CHANNEL_MAP
#pragma shader_feature _NORMAL_MAP
#pragma shader_feature _EMISSION
#pragma shader_feature _TRIPLANAR_MAPPING
#pragma shader_feature _LOCAL_SPACE_TRIPLANAR_MAPPING
#pragma shader_feature _USE_SSAA
#pragma shader_feature _DIRECTIONAL_LIGHT
#pragma shader_feature _SPECULAR_HIGHLIGHTS
#pragma shader_feature _SPHERICAL_HARMONICS
#pragma shader_feature _REFLECTIONS
#pragma shader_feature _REFRACTION
#pragma shader_feature _RIM_LIGHT
#pragma shader_feature _VERTEX_COLORS
#pragma shader_feature _VERTEX_EXTRUSION
#pragma shader_feature _VERTEX_EXTRUSION_SMOOTH_NORMALS
#pragma shader_feature _CLIPPING_BORDER
#pragma shader_feature _NEAR_PLANE_FADE
#pragma shader_feature _NEAR_LIGHT_FADE
#pragma shader_feature _HOVER_LIGHT
#pragma shader_feature _HOVER_COLOR_OVERRIDE
#pragma shader_feature _PROXIMITY_LIGHT
#pragma shader_feature _PROXIMITY_LIGHT_COLOR_OVERRIDE
#pragma shader_feature _PROXIMITY_LIGHT_SUBTRACTIVE
#pragma shader_feature _PROXIMITY_LIGHT_TWO_SIDED
#pragma shader_feature _ROUND_CORNERS
#pragma shader_feature _INDEPENDENT_CORNERS
#pragma shader_feature _BORDER_LIGHT
#pragma shader_feature _BORDER_LIGHT_USES_HOVER_COLOR
#pragma shader_feature _BORDER_LIGHT_REPLACES_ALBEDO
#pragma shader_feature _BORDER_LIGHT_OPAQUE
#pragma shader_feature _INNER_GLOW
#pragma shader_feature _IRIDESCENCE
#pragma shader_feature _ENVIRONMENT_COLORING
#pragma shader_feature _IGNORE_Z_SCALE
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#include "UnityStandardConfig.cginc"
#include "UnityStandardUtils.cginc"
#include "MixedRealityShaderUtils.cginc"
// This define will get commented in by the UpgradeShaderForUniversalRenderPipeline method.
//#define _RENDER_PIPELINE
#if defined(_TRIPLANAR_MAPPING) || defined(_DIRECTIONAL_LIGHT) || defined(_SPHERICAL_HARMONICS) || defined(_REFLECTIONS) || defined(_RIM_LIGHT) || defined(_PROXIMITY_LIGHT) || defined(_ENVIRONMENT_COLORING)
#define _NORMAL
#else
#undef _NORMAL
#endif
#if defined(_CLIPPING_PLANE) || defined(_CLIPPING_SPHERE) || defined(_CLIPPING_BOX)
#define _CLIPPING_PRIMITIVE
#else
#undef _CLIPPING_PRIMITIVE
#endif
#if defined(_NORMAL) || defined(_CLIPPING_PRIMITIVE) || defined(_NEAR_PLANE_FADE) || defined(_HOVER_LIGHT) || defined(_PROXIMITY_LIGHT)
#define _WORLD_POSITION
#else
#undef _WORLD_POSITION
#endif
#if defined(UNITY_UI_CLIP_RECT)
#define _LOCAL_POSITION
#else
#undef _LOCAL_POSITION
#endif
#if defined(_ALPHATEST_ON) || defined(UNITY_UI_CLIP_RECT) || defined(_CLIPPING_PRIMITIVE) || defined(_ROUND_CORNERS)
#define _ALPHA_CLIP
#else
#undef _ALPHA_CLIP
#endif
#if defined(_ALPHABLEND_ON)
#define _TRANSPARENT
#undef _ALPHA_CLIP
#else
#undef _TRANSPARENT
#endif
#if defined(_VERTEX_EXTRUSION) || defined(_ROUND_CORNERS) || defined(_BORDER_LIGHT)
#define _SCALE
#else
#undef _SCALE
#endif
#if defined(_DIRECTIONAL_LIGHT) || defined(_RIM_LIGHT)
#define _FRESNEL
#else
#undef _FRESNEL
#endif
#if defined(_ROUND_CORNERS) || defined(_BORDER_LIGHT) || defined(_INNER_GLOW)
#define _DISTANCE_TO_EDGE
#else
#undef _DISTANCE_TO_EDGE
#endif
#if !defined(_DISABLE_ALBEDO_MAP) || defined(_TRIPLANAR_MAPPING) || defined(_CHANNEL_MAP) || defined(_NORMAL_MAP) || defined(_DISTANCE_TO_EDGE) || defined(_IRIDESCENCE)
#define _UV
#else
#undef _UV
#endif
struct appdata_t
{
float4 vertex : POSITION;
// The default UV channel used for texturing.
float2 uv : TEXCOORD0;
#if defined(LIGHTMAP_ON)
// Reserved for Unity's light map UVs.
float2 uv1 : TEXCOORD1;
#endif
// Used for smooth normal data (or UGUI scaling data).
float4 uv2 : TEXCOORD2;
// Used for UGUI scaling data.
float2 uv3 : TEXCOORD3;
#if defined(_VERTEX_COLORS)
fixed4 color : COLOR0;
#endif
fixed3 normal : NORMAL;
#if defined(_NORMAL_MAP)
fixed4 tangent : TANGENT;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 position : SV_POSITION;
#if defined(_BORDER_LIGHT)
float4 uv : TEXCOORD0;
#elif defined(_UV)
float2 uv : TEXCOORD0;
#endif
#if defined(LIGHTMAP_ON)
float2 lightMapUV : TEXCOORD1;
#endif
#if defined(_VERTEX_COLORS)
fixed4 color : COLOR0;
#endif
#if defined(_SPHERICAL_HARMONICS)
fixed3 ambient : COLOR1;
#endif
#if defined(_IRIDESCENCE)
fixed3 iridescentColor : COLOR2;
#endif
#if defined(_WORLD_POSITION)
#if defined(_NEAR_PLANE_FADE)
float4 worldPosition : TEXCOORD2;
#else
float3 worldPosition : TEXCOORD2;
#endif
#endif
#if defined(_LOCAL_POSITION)
float3 localPosition : TEXCOORD7;
#endif
#if defined(_SCALE)
float3 scale : TEXCOORD3;
#endif
#if defined(_NORMAL)
#if defined(_TRIPLANAR_MAPPING)
fixed3 worldNormal : COLOR3;
fixed3 triplanarNormal : COLOR4;
float3 triplanarPosition : TEXCOORD6;
#elif defined(_NORMAL_MAP)
fixed3 tangentX : COLOR3;
fixed3 tangentY : COLOR4;
fixed3 tangentZ : COLOR5;
#else
fixed3 worldNormal : COLOR3;
#endif
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float4, _Color)
#if defined(_CLIPPING_PLANE)
UNITY_DEFINE_INSTANCED_PROP(fixed, _ClipPlaneSide)
UNITY_DEFINE_INSTANCED_PROP(float4, _ClipPlane)
#endif
#if defined(_CLIPPING_SPHERE)
UNITY_DEFINE_INSTANCED_PROP(fixed, _ClipSphereSide)
UNITY_DEFINE_INSTANCED_PROP(float4x4, _ClipSphereInverseTransform)
#endif
#if defined(_CLIPPING_BOX)
UNITY_DEFINE_INSTANCED_PROP(fixed, _ClipBoxSide)
UNITY_DEFINE_INSTANCED_PROP(float4x4, _ClipBoxInverseTransform)
#endif
UNITY_INSTANCING_BUFFER_END(Props)
sampler2D _MainTex;
fixed4 _MainTex_ST;
#if defined(_ALPHA_CLIP)
fixed _Cutoff;
#endif
#if defined(UNITY_UI_CLIP_RECT)
float4 _ClipRect;
#endif
fixed _Metallic;
fixed _Smoothness;
#if defined(_CHANNEL_MAP)
sampler2D _ChannelMap;
#endif
#if defined(_NORMAL_MAP)
sampler2D _NormalMap;
float _NormalMapScale;
#endif
#if defined(_EMISSION)
fixed4 _EmissiveColor;
#endif
#if defined(_USE_SSAA)
float _MipmapBias;
#endif
#if defined(_TRIPLANAR_MAPPING)
float _TriplanarMappingBlendSharpness;
#endif
#if defined(_DIRECTIONAL_LIGHT)
#if defined(_RENDER_PIPELINE)
CBUFFER_START(_LightBuffer)
float4 _MainLightPosition;
half4 _MainLightColor;
CBUFFER_END
#else
fixed4 _LightColor0;
#endif
#endif
#if defined(_REFRACTION)
fixed _RefractiveIndex;
#endif
#if defined(_RIM_LIGHT)
fixed3 _RimColor;
fixed _RimPower;
#endif
#if defined(_VERTEX_EXTRUSION)
float _VertexExtrusionValue;
#endif
#if defined(_CLIPPING_PRIMITIVE)
float _BlendedClippingWidth;
#endif
#if defined(_CLIPPING_BORDER)
fixed _ClippingBorderWidth;
fixed3 _ClippingBorderColor;
#endif
#if defined(_NEAR_PLANE_FADE)
float _FadeBeginDistance;
float _FadeCompleteDistance;
fixed _FadeMinValue;
#endif
#if defined(_HOVER_LIGHT) || defined(_NEAR_LIGHT_FADE)
#if defined(_HOVER_LIGHT_HIGH)
#define HOVER_LIGHT_COUNT 10
#elif defined(_HOVER_LIGHT_MEDIUM)
#define HOVER_LIGHT_COUNT 4
#else
#define HOVER_LIGHT_COUNT 2
#endif
#define HOVER_LIGHT_DATA_SIZE 2
float4 _HoverLightData[HOVER_LIGHT_COUNT * HOVER_LIGHT_DATA_SIZE];
#if defined(_HOVER_COLOR_OVERRIDE)
fixed3 _HoverColorOverride;
#endif
#endif
#if defined(_PROXIMITY_LIGHT) || defined(_NEAR_LIGHT_FADE)
#define PROXIMITY_LIGHT_COUNT 2
#define PROXIMITY_LIGHT_DATA_SIZE 6
float4 _ProximityLightData[PROXIMITY_LIGHT_COUNT * PROXIMITY_LIGHT_DATA_SIZE];
#if defined(_PROXIMITY_LIGHT_COLOR_OVERRIDE)
float4 _ProximityLightCenterColorOverride;
float4 _ProximityLightMiddleColorOverride;
float4 _ProximityLightOuterColorOverride;
#endif
#endif
#if defined(_HOVER_LIGHT) || defined(_PROXIMITY_LIGHT) || defined(_BORDER_LIGHT)
fixed _FluentLightIntensity;
#endif
#if defined(_ROUND_CORNERS)
#if defined(_INDEPENDENT_CORNERS)
float4 _RoundCornersRadius;
#else
fixed _RoundCornerRadius;
#endif
fixed _RoundCornerMargin;
#endif
#if defined(_BORDER_LIGHT)
fixed _BorderWidth;
fixed _BorderMinValue;
#endif
#if defined(_BORDER_LIGHT_OPAQUE)
fixed _BorderLightOpaqueAlpha;
#endif
#if defined(_ROUND_CORNERS) || defined(_BORDER_LIGHT)
float _EdgeSmoothingValue;
#endif
#if defined(_INNER_GLOW)
fixed4 _InnerGlowColor;
fixed _InnerGlowPower;
#endif
#if defined(_IRIDESCENCE)
sampler2D _IridescentSpectrumMap;
fixed _IridescenceIntensity;
fixed _IridescenceThreshold;
fixed _IridescenceAngle;
#endif
#if defined(_ENVIRONMENT_COLORING)
fixed _EnvironmentColorThreshold;
fixed _EnvironmentColorIntensity;
fixed3 _EnvironmentColorX;
fixed3 _EnvironmentColorY;
fixed3 _EnvironmentColorZ;
#endif
#if defined(_DIRECTIONAL_LIGHT)
static const fixed _MinMetallicLightContribution = 0.7;
static const fixed _IblContribution = 0.1;
#endif
#if defined(_SPECULAR_HIGHLIGHTS)
static const float _Shininess = 800.0;
#endif
#if defined(_FRESNEL)
static const float _FresnelPower = 8.0;
#endif
#if defined(_NEAR_LIGHT_FADE)
static const float _MaxNearLightDistance = 10.0;
inline float NearLightDistance(float4 light, float3 worldPosition)
{
return distance(worldPosition, light.xyz) + ((1.0 - light.w) * _MaxNearLightDistance);
}
#endif
#if defined(_HOVER_LIGHT)
inline float HoverLight(float4 hoverLight, float inverseRadius, float3 worldPosition)
{
return (1.0 - saturate(length(hoverLight.xyz - worldPosition) * inverseRadius)) * hoverLight.w;
}
#endif
#if defined(_PROXIMITY_LIGHT)
inline float ProximityLight(float4 proximityLight, float4 proximityLightParams, float4 proximityLightPulseParams, float3 worldPosition, float3 worldNormal, out fixed colorValue)
{
float proximityLightDistance = dot(proximityLight.xyz - worldPosition, worldNormal);
#if defined(_PROXIMITY_LIGHT_TWO_SIDED)
worldNormal = proximityLightDistance < 0.0 ? -worldNormal : worldNormal;
proximityLightDistance = abs(proximityLightDistance);
#endif
float normalizedProximityLightDistance = saturate(proximityLightDistance * proximityLightParams.y);
float3 projectedProximityLight = proximityLight.xyz - (worldNormal * abs(proximityLightDistance));
float projectedProximityLightDistance = length(projectedProximityLight - worldPosition);
float attenuation = (1.0 - normalizedProximityLightDistance) * proximityLight.w;
colorValue = saturate(projectedProximityLightDistance * proximityLightParams.z);
float pulse = step(proximityLightPulseParams.x, projectedProximityLightDistance) * proximityLightPulseParams.y;
return smoothstep(1.0, 0.0, projectedProximityLightDistance / (proximityLightParams.x * max(pow(normalizedProximityLightDistance, 0.25), proximityLightParams.w))) * pulse * attenuation;
}
inline fixed3 MixProximityLightColor(fixed4 centerColor, fixed4 middleColor, fixed4 outerColor, fixed t)
{
fixed3 color = lerp(centerColor.rgb, middleColor.rgb, smoothstep(centerColor.a, middleColor.a, t));
return lerp(color, outerColor, smoothstep(middleColor.a, outerColor.a, t));
}
#endif
#if defined(_ROUND_CORNERS)
inline float PointVsRoundedBox(float2 position, float2 cornerCircleDistance, float cornerCircleRadius)
{
return length(max(abs(position) - cornerCircleDistance, 0.0)) - cornerCircleRadius;
}
inline float RoundCornersSmooth(float2 position, float2 cornerCircleDistance, float cornerCircleRadius)
{
return smoothstep(1.0, 0.0, PointVsRoundedBox(position, cornerCircleDistance, cornerCircleRadius) / _EdgeSmoothingValue);
}
inline float RoundCorners(float2 position, float2 cornerCircleDistance, float cornerCircleRadius)
{
#if defined(_TRANSPARENT)
return RoundCornersSmooth(position, cornerCircleDistance, cornerCircleRadius);
#else
return (PointVsRoundedBox(position, cornerCircleDistance, cornerCircleRadius) < 0.0);
#endif
}
#endif
#if defined(_IRIDESCENCE)
fixed3 Iridescence(float tangentDotIncident, sampler2D spectrumMap, float threshold, float2 uv, float angle, float intensity)
{
float k = tangentDotIncident * 0.5 + 0.5;
float4 left = tex2D(spectrumMap, float2(lerp(0.0, 1.0 - threshold, k), 0.5), float2(0.0, 0.0), float2(0.0, 0.0));
float4 right = tex2D(spectrumMap, float2(lerp(threshold, 1.0, k), 0.5), float2(0.0, 0.0), float2(0.0, 0.0));
float2 XY = uv - float2(0.5, 0.5);
float s = (cos(angle) * XY.x - sin(angle) * XY.y) / cos(angle);
return (left.rgb + s * (right.rgb - left.rgb)) * intensity;
}
#endif
v2f vert(appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
UNITY_TRANSFER_INSTANCE_ID(v, o);
float4 vertexPosition = v.vertex;
#if defined(_WORLD_POSITION) || defined(_VERTEX_EXTRUSION)
float3 worldVertexPosition = mul(unity_ObjectToWorld, vertexPosition).xyz;
#endif
#if defined(_SCALE)
o.scale.x = length(mul(unity_ObjectToWorld, float4(1.0, 0.0, 0.0, 0.0)));
o.scale.y = length(mul(unity_ObjectToWorld, float4(0.0, 1.0, 0.0, 0.0)));
#if defined(_IGNORE_Z_SCALE)
o.scale.z = o.scale.x;
#else
o.scale.z = length(mul(unity_ObjectToWorld, float4(0.0, 0.0, 1.0, 0.0)));
#endif
#if !defined(_VERTEX_EXTRUSION_SMOOTH_NORMALS)
// uv3.y will contain a negative value when rendered by a UGUI and ScaleMeshEffect.
if (v.uv3.y < 0.0)
{
o.scale.x *= v.uv2.x;
o.scale.y *= v.uv2.y;
o.scale.z *= v.uv3.x;
}
#endif
#endif
fixed3 localNormal = v.normal;
#if defined(_NORMAL) || defined(_VERTEX_EXTRUSION)
fixed3 worldNormal = UnityObjectToWorldNormal(localNormal);
#endif
#if defined(_VERTEX_EXTRUSION)
#if defined(_VERTEX_EXTRUSION_SMOOTH_NORMALS)
worldVertexPosition += UnityObjectToWorldNormal(v.uv2 * o.scale) * _VertexExtrusionValue;
#else
worldVertexPosition += worldNormal * _VertexExtrusionValue;
#endif
vertexPosition = mul(unity_WorldToObject, float4(worldVertexPosition, 1.0));
#endif
o.position = UnityObjectToClipPos(vertexPosition);
#if defined(_WORLD_POSITION)
o.worldPosition.xyz = worldVertexPosition;
#endif
#if defined(_LOCAL_POSITION)
o.localPosition.xyz = vertexPosition;
#endif
#if defined(_NEAR_PLANE_FADE)
float rangeInverse = 1.0 / (_FadeBeginDistance - _FadeCompleteDistance);
#if defined(_NEAR_LIGHT_FADE)
float fadeDistance = _MaxNearLightDistance;
[unroll]
for (int hoverLightIndex = 0; hoverLightIndex < HOVER_LIGHT_COUNT; ++hoverLightIndex)
{
int dataIndex = hoverLightIndex * HOVER_LIGHT_DATA_SIZE;
fadeDistance = min(fadeDistance, NearLightDistance(_HoverLightData[dataIndex], o.worldPosition));
}
[unroll]
for (int proximityLightIndex = 0; proximityLightIndex < PROXIMITY_LIGHT_COUNT; ++proximityLightIndex)
{
int dataIndex = proximityLightIndex * PROXIMITY_LIGHT_DATA_SIZE;
fadeDistance = min(fadeDistance, NearLightDistance(_ProximityLightData[dataIndex], o.worldPosition));
}
#else
float fadeDistance = -UnityObjectToViewPos(vertexPosition).z;
#endif
o.worldPosition.w = max(saturate(mad(fadeDistance, rangeInverse, -_FadeCompleteDistance * rangeInverse)), _FadeMinValue);
#endif
#if defined(_BORDER_LIGHT) || defined(_ROUND_CORNERS)
o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
float minScale = min(min(o.scale.x, o.scale.y), o.scale.z);
#if defined(_BORDER_LIGHT)
float maxScale = max(max(o.scale.x, o.scale.y), o.scale.z);
float minOverMiddleScale = minScale / (o.scale.x + o.scale.y + o.scale.z - minScale - maxScale);
float areaYZ = o.scale.y * o.scale.z;
float areaXZ = o.scale.z * o.scale.x;
float areaXY = o.scale.x * o.scale.y;
float borderWidth = _BorderWidth;
#endif
if (abs(localNormal.x) == 1.0) // Y,Z plane.
{
o.scale.x = o.scale.z;
o.scale.y = o.scale.y;
#if defined(_BORDER_LIGHT)
if (areaYZ > areaXZ && areaYZ > areaXY)
{
borderWidth *= minOverMiddleScale;
}
#endif
}
else if (abs(localNormal.y) == 1.0) // X,Z plane.
{
o.scale.x = o.scale.x;
o.scale.y = o.scale.z;
#if defined(_BORDER_LIGHT)
if (areaXZ > areaXY && areaXZ > areaYZ)
{
borderWidth *= minOverMiddleScale;
}
#endif
}
else // X,Y plane.
{
o.scale.x = o.scale.x;
o.scale.y = o.scale.y;
#if defined(_BORDER_LIGHT)
if (areaXY > areaYZ && areaXY > areaXZ)
{
borderWidth *= minOverMiddleScale;
}
#endif
}
o.scale.z = minScale;
#if defined(_BORDER_LIGHT)
float scaleRatio = min(o.scale.x, o.scale.y) / max(o.scale.x, o.scale.y);
o.uv.z = o.scale.x > o.scale.y ? 1.0 - (borderWidth * scaleRatio) : 1.0 - borderWidth;
o.uv.w = o.scale.x > o.scale.y ? 1.0 - borderWidth : 1.0 - (borderWidth * scaleRatio);
#endif
#elif defined(_UV)
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
#endif
#if defined(LIGHTMAP_ON)
o.lightMapUV.xy = v.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
#if defined(_VERTEX_COLORS)
o.color = v.color;
#endif
#if defined(_SPHERICAL_HARMONICS)
o.ambient = ShadeSH9(float4(worldNormal, 1.0));
#endif
#if defined(_IRIDESCENCE)
float3 rightTangent = normalize(mul((float3x3)unity_ObjectToWorld, float3(1.0, 0.0, 0.0)));
float3 incidentWithCenter = normalize(mul(unity_ObjectToWorld, float4(0.0, 0.0, 0.0, 1.0)) - _WorldSpaceCameraPos);
float tangentDotIncident = dot(rightTangent, incidentWithCenter);
o.iridescentColor = Iridescence(tangentDotIncident, _IridescentSpectrumMap, _IridescenceThreshold, v.uv, _IridescenceAngle, _IridescenceIntensity);
#endif
#if defined(_NORMAL)
#if defined(_TRIPLANAR_MAPPING)
o.worldNormal = worldNormal;
#if defined(_LOCAL_SPACE_TRIPLANAR_MAPPING)
o.triplanarNormal = localNormal;
o.triplanarPosition = vertexPosition;
#else
o.triplanarNormal = worldNormal;
o.triplanarPosition = o.worldPosition;
#endif
#elif defined(_NORMAL_MAP)
fixed3 worldTangent = UnityObjectToWorldDir(v.tangent.xyz);
fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
fixed3 worldBitangent = cross(worldNormal, worldTangent) * tangentSign;
o.tangentX = fixed3(worldTangent.x, worldBitangent.x, worldNormal.x);
o.tangentY = fixed3(worldTangent.y, worldBitangent.y, worldNormal.y);
o.tangentZ = fixed3(worldTangent.z, worldBitangent.z, worldNormal.z);
#else
o.worldNormal = worldNormal;
#endif
#endif
return o;
}
fixed4 frag(v2f i, fixed facing : VFACE) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
#if defined(_TRIPLANAR_MAPPING)
// Calculate triplanar uvs and apply texture scale and offset values like TRANSFORM_TEX.
fixed3 triplanarBlend = pow(abs(i.triplanarNormal), _TriplanarMappingBlendSharpness);
triplanarBlend /= dot(triplanarBlend, fixed3(1.0, 1.0, 1.0));
float2 uvX = i.triplanarPosition.zy * _MainTex_ST.xy + _MainTex_ST.zw;
float2 uvY = i.triplanarPosition.xz * _MainTex_ST.xy + _MainTex_ST.zw;
float2 uvZ = i.triplanarPosition.xy * _MainTex_ST.xy + _MainTex_ST.zw;
// Ternary operator is 2 instructions faster than sign() when we don't care about zero returning a zero sign.
float3 axisSign = i.triplanarNormal < 0 ? -1 : 1;
uvX.x *= axisSign.x;
uvY.x *= axisSign.y;
uvZ.x *= -axisSign.z;
#endif
// Texturing.
#if defined(_DISABLE_ALBEDO_MAP)
fixed4 albedo = fixed4(1.0, 1.0, 1.0, 1.0);
#else
#if defined(_TRIPLANAR_MAPPING)
fixed4 albedo = tex2D(_MainTex, uvX) * triplanarBlend.x +
tex2D(_MainTex, uvY) * triplanarBlend.y +
tex2D(_MainTex, uvZ) * triplanarBlend.z;
#else
#if defined(_USE_SSAA)
// Does SSAA on the texture, implementation based off this article: https://medium.com/@bgolus/sharper-mipmapping-using-shader-based-supersampling-ed7aadb47bec
// per pixel screen space partial derivatives
float2 dx = ddx(i.uv.xy) * 0.25; // horizontal offset
float2 dy = ddy(i.uv.xy) * 0.25; // vertical offset
// supersampled 2x2 ordered grid
fixed4 albedo = 0;
albedo += tex2Dbias(_MainTex, float4(i.uv.xy + dx + dy, 0.0, _MipmapBias));
albedo += tex2Dbias(_MainTex, float4(i.uv.xy - dx + dy, 0.0, _MipmapBias));
albedo += tex2Dbias(_MainTex, float4(i.uv.xy + dx - dy, 0.0, _MipmapBias));
albedo += tex2Dbias(_MainTex, float4(i.uv.xy - dx - dy, 0.0, _MipmapBias));
albedo *= 0.25;
#else
fixed4 albedo = tex2D(_MainTex, i.uv);
#endif
#endif
#endif
#ifdef LIGHTMAP_ON
albedo.rgb *= DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.lightMapUV));
#endif
#if defined(_CHANNEL_MAP)
fixed4 channel = tex2D(_ChannelMap, i.uv);
_Metallic = channel.r;
albedo.rgb *= channel.g;
_Smoothness = channel.a;
#else
#if defined(_METALLIC_TEXTURE_ALBEDO_CHANNEL_A)
_Metallic = albedo.a;
albedo.a = 1.0;
#elif defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A)
_Smoothness = albedo.a;
albedo.a = 1.0;
#endif
#endif
// Primitive clipping.
#if defined(_CLIPPING_PRIMITIVE)
float primitiveDistance = 1.0;
#if defined(_CLIPPING_PLANE)
fixed clipPlaneSide = UNITY_ACCESS_INSTANCED_PROP(Props, _ClipPlaneSide);
float4 clipPlane = UNITY_ACCESS_INSTANCED_PROP(Props, _ClipPlane);
primitiveDistance = min(primitiveDistance, PointVsPlane(i.worldPosition.xyz, clipPlane) * clipPlaneSide);
#endif
#if defined(_CLIPPING_SPHERE)
fixed clipSphereSide = UNITY_ACCESS_INSTANCED_PROP(Props, _ClipSphereSide);
float4x4 clipSphereInverseTransform = UNITY_ACCESS_INSTANCED_PROP(Props, _ClipSphereInverseTransform);
primitiveDistance = min(primitiveDistance, PointVsSphere(i.worldPosition.xyz, clipSphereInverseTransform) * clipSphereSide);
#endif
#if defined(_CLIPPING_BOX)
fixed clipBoxSide = UNITY_ACCESS_INSTANCED_PROP(Props, _ClipBoxSide);
float4x4 clipBoxInverseTransform = UNITY_ACCESS_INSTANCED_PROP(Props, _ClipBoxInverseTransform);
primitiveDistance = min(primitiveDistance, PointVsBox(i.worldPosition.xyz, clipBoxInverseTransform) * clipBoxSide);
#endif
#if defined(_CLIPPING_BORDER)
fixed3 primitiveBorderColor = lerp(_ClippingBorderColor, fixed3(0.0, 0.0, 0.0), primitiveDistance / _ClippingBorderWidth);
albedo.rgb += primitiveBorderColor * (primitiveDistance < _ClippingBorderWidth ? 1.0 : 0.0);
#endif
#endif
#if defined(_DISTANCE_TO_EDGE)
fixed2 distanceToEdge;
distanceToEdge.x = abs(i.uv.x - 0.5) * 2.0;
distanceToEdge.y = abs(i.uv.y - 0.5) * 2.0;
#endif
// Rounded corner clipping.
#if defined(_ROUND_CORNERS)
float2 halfScale = i.scale.xy * 0.5;
float2 roundCornerPosition = distanceToEdge * halfScale;
fixed currentCornerRadius;
#if defined(_INDEPENDENT_CORNERS)
_RoundCornersRadius = clamp(_RoundCornersRadius, 0, 0.5);
if (i.uv.x < 0.5)
{
if (i.uv.y > 0.5)
{
currentCornerRadius = _RoundCornersRadius.x;
}
else
{
currentCornerRadius = _RoundCornersRadius.w;
}
}
else
{
if (i.uv.y > 0.5)
{
currentCornerRadius = _RoundCornersRadius.y;
}
else
{
currentCornerRadius = _RoundCornersRadius.z;
}
}
#else
currentCornerRadius = _RoundCornerRadius;
#endif
float cornerCircleRadius = saturate(max(currentCornerRadius - _RoundCornerMargin, 0.01)) * i.scale.z;
float2 cornerCircleDistance = halfScale - (_RoundCornerMargin * i.scale.z) - cornerCircleRadius;
float roundCornerClip = RoundCorners(roundCornerPosition, cornerCircleDistance, cornerCircleRadius);
#endif
albedo *= UNITY_ACCESS_INSTANCED_PROP(Props, _Color);
#if defined(_VERTEX_COLORS)
albedo *= i.color;
#endif
#if defined(_IRIDESCENCE)
albedo.rgb += i.iridescentColor;
#endif
// Normal calculation.
#if defined(_NORMAL)
fixed3 worldViewDir = normalize(UnityWorldSpaceViewDir(i.worldPosition.xyz));
#if defined(_REFLECTIONS) || defined(_ENVIRONMENT_COLORING)
fixed3 incident = -worldViewDir;
#endif
fixed3 worldNormal;
#if defined(_NORMAL_MAP)
#if defined(_TRIPLANAR_MAPPING)
fixed3 tangentNormalX = UnpackScaleNormal(tex2D(_NormalMap, uvX), _NormalMapScale);
fixed3 tangentNormalY = UnpackScaleNormal(tex2D(_NormalMap, uvY), _NormalMapScale);
fixed3 tangentNormalZ = UnpackScaleNormal(tex2D(_NormalMap, uvZ), _NormalMapScale);
tangentNormalX.x *= axisSign.x;
tangentNormalY.x *= axisSign.y;
tangentNormalZ.x *= -axisSign.z;
// Swizzle world normals to match tangent space and apply Whiteout normal blend.
tangentNormalX = fixed3(tangentNormalX.xy + i.worldNormal.zy, tangentNormalX.z * i.worldNormal.x);
tangentNormalY = fixed3(tangentNormalY.xy + i.worldNormal.xz, tangentNormalY.z * i.worldNormal.y);
tangentNormalZ = fixed3(tangentNormalZ.xy + i.worldNormal.xy, tangentNormalZ.z * i.worldNormal.z);
// Swizzle tangent normals to match world normal and blend together.
worldNormal = normalize(tangentNormalX.zyx * triplanarBlend.x +
tangentNormalY.xzy * triplanarBlend.y +
tangentNormalZ.xyz * triplanarBlend.z);
#else
fixed3 tangentNormal = UnpackScaleNormal(tex2D(_NormalMap, i.uv), _NormalMapScale);
worldNormal.x = dot(i.tangentX, tangentNormal);
worldNormal.y = dot(i.tangentY, tangentNormal);
worldNormal.z = dot(i.tangentZ, tangentNormal);
worldNormal = normalize(worldNormal) * facing;
#endif
#else
worldNormal = normalize(i.worldNormal) * facing;
#endif
#endif
fixed pointToLight = 1.0;
fixed3 fluentLightColor = fixed3(0.0, 0.0, 0.0);
// Hover light.
#if defined(_HOVER_LIGHT)
pointToLight = 0.0;
[unroll]
for (int hoverLightIndex = 0; hoverLightIndex < HOVER_LIGHT_COUNT; ++hoverLightIndex)
{
int dataIndex = hoverLightIndex * HOVER_LIGHT_DATA_SIZE;
fixed hoverValue = HoverLight(_HoverLightData[dataIndex], _HoverLightData[dataIndex + 1].w, i.worldPosition.xyz);
pointToLight += hoverValue;
#if !defined(_HOVER_COLOR_OVERRIDE)
fluentLightColor += lerp(fixed3(0.0, 0.0, 0.0), _HoverLightData[dataIndex + 1].rgb, hoverValue);
#endif
}
#if defined(_HOVER_COLOR_OVERRIDE)
fluentLightColor = _HoverColorOverride.rgb * pointToLight;
#endif
#endif
// Proximity light.
#if defined(_PROXIMITY_LIGHT)
#if !defined(_HOVER_LIGHT)
pointToLight = 0.0;
#endif
[unroll]
for (int proximityLightIndex = 0; proximityLightIndex < PROXIMITY_LIGHT_COUNT; ++proximityLightIndex)
{
int dataIndex = proximityLightIndex * PROXIMITY_LIGHT_DATA_SIZE;
fixed colorValue;
fixed proximityValue = ProximityLight(_ProximityLightData[dataIndex], _ProximityLightData[dataIndex + 1], _ProximityLightData[dataIndex + 2], i.worldPosition.xyz, worldNormal, colorValue);
pointToLight += proximityValue;
#if defined(_PROXIMITY_LIGHT_COLOR_OVERRIDE)
fixed3 proximityColor = MixProximityLightColor(_ProximityLightCenterColorOverride, _ProximityLightMiddleColorOverride, _ProximityLightOuterColorOverride, colorValue);
#else
fixed3 proximityColor = MixProximityLightColor(_ProximityLightData[dataIndex + 3], _ProximityLightData[dataIndex + 4], _ProximityLightData[dataIndex + 5], colorValue);