forked from FAForever/nomads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nomads_mesh.fx
6116 lines (5156 loc) · 175 KB
/
nomads_mesh.fx
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
///////////////////////////////////////////////////////////////////////////////
///
/// File : mesh.fx
/// Author(s): Ivan Rumsey, Gordon Duclos
///
/// Summary : Effect file for mesh rendering.
///
/// Copyright © 2006 Gas Powered Games, Inc. All rights reserved.
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////
///
/// Defines
///
///////////////////////////////////////
#define BONE_MAXIMUM 80
#define FIDELITY_LOW 0x00
#define FIDELITY_MEDIUM 0x01
#define FIDELITY_HIGH 0x02
#define STAGE_DEPTH 0x01
#define STAGE_REFLECTION 0x02
#define STAGE_PREEFFECT 0x04
#define STAGE_POSTEFFECT 0x08
#define STAGE_PREWATER 0x10
#define STAGE_POSTWATER 0x20
#define PARAM_UNUSED 0
#define PARAM_FRACTIONCOMPLETE 1
#define PARAM_FRACTIONHEALTH 2
#define PARAM_LIFETIME 3
#define SELF_SHADOW
///////////////////////////////////////
///
/// Typedefs
///
///////////////////////////////////////
#ifdef DIRECT3D10
typedef uint4 anim_t;
#else
typedef float4 anim_t;
#endif
///////////////////////////////////////
///
/// Shader constants
///
///////////////////////////////////////
float glowMultiplier = 2.000;
float glowMinimum = 0.010;
texture fogTexture;
float4 terrainScale;
texture hypsometricTexture;
texture environmentTexture;
texture anisotropicTexture;
texture insectTexture;
float time;
float4 lodBasis;
float4x4 viewMatrix;
float4x4 projMatrix;
float3 windDirection = float3(0.707, 0.0, 0.707);
float lightMultiplier;
float3 sunDirection;
float3 sunDiffuse;
float3 sunAmbient;
float3 shadowFill;
int shadowsEnabled;
float4x4 shadowMatrix;
texture shadowTexture;
int shadowBlur;
float shadowSize;
float shadowBias;
int mirrored;
texture waterRamp;
float1 minimumElevation;
float1 maximumElevation;
float surfaceElevation;
float abyssElevation;
texture dissolveTexture;
texture albedoTexture;
texture normalsTexture;
texture specularTexture;
texture lookupTexture;
texture secondaryTexture;
float4 transPalette[BONE_MAXIMUM];
float4 rotPalette[BONE_MAXIMUM];
///////////////////////////////////////
///
/// Samplers
///
///////////////////////////////////////
sampler1D hypsometricSampler = sampler_state
{
Texture = (hypsometricTexture);
MipFilter = POINT;
MinFilter = NONE;
MagFilter = NONE;
AddressU = CLAMP;
AddressV = CLAMP;
};
samplerCUBE environmentSampler = sampler_state
{
Texture = (environmentTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler2D dissolveSampler = sampler_state
{
Texture = (dissolveTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler2D fogSampler = sampler_state
{
Texture = (fogTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
sampler2D shadowSampler = sampler_state
{
Texture = (shadowTexture);
MipFilter = POINT;
MinFilter = POINT;
MagFilter = POINT;
AddressU = CLAMP;
AddressV = CLAMP;
};
sampler2D shadowPCFSampler = sampler_state
{
Texture = (shadowTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = BORDER;
AddressV = BORDER;
#ifndef DIRECT3D10
BorderColor = 0xFFFFFFFF;
#else
BorderColor = float4(1,1,1,1);
#endif
};
sampler2D albedoSampler = sampler_state
{
Texture = (albedoTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler2D normalsSampler = sampler_state
{
Texture = (normalsTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler2D specularSampler = sampler_state
{
Texture = (specularTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler2D lookupSampler = sampler_state
{
Texture = (lookupTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler2D secondarySampler = sampler_state
{
Texture = (secondaryTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler2D anisotropicSampler = sampler_state
{
Texture = (anisotropicTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
sampler2D insectSampler = sampler_state
{
Texture = (insectTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
sampler2D falloffSampler = sampler_state
{
Texture = (lookupTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
///////////////////////////////////////
///
/// Structures
///
///////////////////////////////////////
struct DEPTH_VERTEX
{
float4 position : POSITION0;
float4 texcoord0 : TEXCOORD0;
float depth : TEXCOORD2;
};
struct SILHOUETTE_VERTEX
{
float4 position : POSITION0;
};
struct CLUTTER_VERTEX
{
float4 position : POSITION0;
float3 normal : TEXCOORD3;
float3 tangent : TEXCOORD4;
float3 binormal : TEXCOORD5;
float4 texcoord0 : TEXCOORD0;
float4 shadow : TEXCOORD2;
float dissolve : TEXCOORD7;
};
struct CARTOGRAPHIC_VERTEX
{
float4 position : POSITION0;
float1 elevation : TEXCOORD0;
float2 uv : TEXCOORD1;
float1 tone : TEXCOORD2;
float4 color : COLOR0;
};
struct FLAT_VERTEX
{
float4 position : POSITION0;
float4 texcoord0 : TEXCOORD0;
float4 color : COLOR0;
float4 material : TEXCOORD1;
float2 depth : TEXCOORD2;
float2 fog : TEXCOORD3;
};
struct VERTEXNORMAL_VERTEX
{
float4 position : POSITION0;
float3 normal : TEXCOORD3;
float4 texcoord0 : TEXCOORD0;
float4 shadow : TEXCOORD2;
float4 color : COLOR0;
float4 material : TEXCOORD1;
float depth : TEXCOORD4;
float2 fog : TEXCOORD5;
};
struct NORMALMAPPED_VERTEX
{
float4 position : POSITION0;
float3 normal : TEXCOORD3;
float3 tangent : TEXCOORD4;
float3 binormal : TEXCOORD5;
float4 texcoord0 : TEXCOORD0;
float3 viewDirection : TEXCOORD6;
float4 shadow : TEXCOORD2;
float4 color : COLOR0;
float4 material : TEXCOORD1;
float4 depth : TEXCOORD7;
};
#if 0
struct VERTEXNORMAL_VERTEX
{
float4 position : POSITION0;
float3 normal : TEXCOORD3;
float4 texcoord0 : TEXCOORD0;
float4 shadow : TEXCOORD2;
float4 color : COLOR0;
float4 material : TEXCOORD1;
float depth : TEXCOORD4;
float2 fog : TEXCOORD5;
};
#endif
struct EFFECT_VERTEX
{
float4 position : POSITION0;
float3 normal : TEXCOORD3;
float3 color : COLOR0;
float4 texcoord0 : TEXCOORD0;
float4 texcoord1 : TEXCOORD2;
float4 material : TEXCOORD1;
float depth : TEXCOORD4;
};
struct EFFECT_NORMALMAPPED_VERTEX
{
float4 position : POSITION0;
float3 normal : TEXCOORD3;
float3 tangent : TEXCOORD4;
float3 binormal : TEXCOORD5;
float4 texcoord0 : TEXCOORD0;
float4 texcoord1 : TEXCOORD2;
float3 viewDirection : TEXCOORD6;
float4 color : COLOR0;
float4 material : TEXCOORD1;
float2 depth : TEXCOORD7;
};
struct LOFIEFFECT_VERTEX
{
float4 position : POSITION0;
float3 normal : TEXCOORD3;
float3 color : COLOR0;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD2;
float2 texcoord2 : TEXCOORD5;
float4 material : TEXCOORD1;
float depth : TEXCOORD4;
};
struct SHIELDIMPACT_VERTEX
{
float4 position : POSITION0;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float4 material : TEXCOORD3;
float depth : TEXCOORD4;
};
///////////////////////////////////////
///
/// Functions
///
///////////////////////////////////////
/// ComputeMatrix
///
/// Compute matrix from scale, translation, and quaternion.
float4x4 ComputeMatrix( float s, float3 T, float4 Q)
{
float4x4 M;
float x = Q.x, y = Q.y, z = Q.z, w = Q.w;
float x2 = 2 * x, y2 = 2 * y, z2 = 2 * z, w2 = 2 * w;
float xx2 = x * x2, yy2 = y * y2, zz2 = z * z2;
float xy2 = x * y2, xz2 = x * z2, xw2 = x * w2, yz2 = y * z2, yw2 = y * w2, zw2 = z * w2;
M._m00 = s * ( 1 - ( yy2 + zz2 ));
M._m01 = s * ( xy2 + zw2 );
M._m02 = s * ( xz2 - yw2 );
M._m03 = 0;
M._m10 = s * ( xy2 - zw2 );
M._m11 = s * ( 1 - ( xx2 + zz2 ));
M._m12 = s * ( yz2 + xw2 );
M._m13 = 0;
M._m20 = s * ( xz2 + yw2 );
M._m21 = s * ( yz2 - xw2 );
M._m22 = s * ( 1 - ( xx2 + yy2 ));
M._m23 = 0;
M._m30 = T.x;
M._m31 = T.y;
M._m32 = T.z;
M._m33 = 1;
return M;
}
/// ComputePaletteMatrix
///
/// Compute matrix from an index into the bone palette.
float4x4 ComputePaletteMatrix( int index)
{
float4 translation = transPalette[index];
return ComputeMatrix( translation.w, translation.xyz, rotPalette[index]);
}
/// ComputeWorldMatrix
///
/// Computes the bone-to-world matrix given the bone index and
/// rows of the model to world matrix.
float4x4 ComputeWorldMatrix( int index, float3 row0, float3 row1, float3 row2, float3 row3)
{
return mul(ComputePaletteMatrix(index),float4x4(float4(row0,0),float4(row1,0),float4(row2,0),float4(row3,1)));
}
/// ComputeShadowTexcoord
///
/// Computes the shadow texture coordinate of a point given in world space.
float4 ComputeShadowTexcoord( float4 worldPosition)
{
float4 texcoord = mul( worldPosition, shadowMatrix);
texcoord.x = ( +texcoord.x + texcoord.w ) * 0.5;
texcoord.y = ( -texcoord.y + texcoord.w ) * 0.5;
texcoord.z /= texcoord.w;
return texcoord;
}
/// ComputeScrolledTexcoord
///
///
float4 ComputeScrolledTexcoord( float4 texcoord, float4 material)
{
float4 scrolled = texcoord;
if ( texcoord.y > 0.95 )
{
scrolled.x += material.z;
scrolled.z += material.z;
}
else if ( texcoord.y > 0.90 )
{
scrolled.x += material.w;
scrolled.z += material.w;
}
return scrolled;
}
/// ComputeFogTexcoord
///
///
float2 ComputeFogTexcoord(float3 position)
{
return terrainScale.xz * position.xz;
}
/// ComputeShadow
///
/// Computes the "light attenuation factor" for a pixel given its shadow
/// texture coordinate and depth from light.
// *** Standard Shadow Mapping ***
float ComputeShadowStandard( float4 shadowCoords)
{
#ifdef SELF_SHADOW
shadowCoords.xy /= shadowCoords.w;
// Standard shadow map comparison
float shadow = 1.0f;
if( shadowsEnabled && shadowCoords.z > tex2D( shadowSampler, shadowCoords.xy ).r + shadowBias )
{
shadow = 0.0f;
}
return shadow;
#else
return 1;
#endif
}
// *** Percentage Closer Filtering Shadow Mapping ***
float ComputeShadowPCF( float4 shadowCoords)
{
#ifdef SELF_SHADOW
shadowCoords.xy /= shadowCoords.w;
// *** PCF Percentage Closer Filtering ***
// If we only support 1024x1024 shadow maps we can take out the
// 'shadowSize' var dependancy. and use a lookup table.
// Would make this function faster.
//
// Altered PCF Kernal:
//
// 4
//
// .---1---.
// | |
// 2 0 X | 3
// | |
// '-------'
//
//
float shadow = 0.0f;
float texel = 1.0f / shadowSize;
float offset = texel; // make this larger if you want a bigger 'blur'.
float depthArray[5];
depthArray[0] = tex2D( shadowPCFSampler, shadowCoords.xy + float2( -(texel * 0.5f), 0.0f ) ).r;
depthArray[1] = tex2D( shadowPCFSampler, shadowCoords.xy + float2( 0.0f, -(texel * 0.5f)) ).r;
depthArray[2] = tex2D( shadowPCFSampler, shadowCoords.xy + float2( -offset, 0.0f ) ).r;
depthArray[3] = tex2D( shadowPCFSampler, shadowCoords.xy + float2( offset, 0.0f ) ).r;
depthArray[4] = tex2D( shadowPCFSampler, shadowCoords.xy + float2( 0.0f, offset ) ).r;
// Sample each of them checking whether the pixel under test is shadowed or not
for( int i = 0; i < 5; i++ )
{
float A = depthArray[i] + shadowBias;
float B = (shadowCoords.z - 0.001f);
if( A > B )
{
shadow += 1.0f;
}
}
// Get the average
return shadow * (1.0f / 5.0f);
#else
return 1;
#endif
}
float ComputeShadow( float4 shadowCoords, uniform bool hiDefFiltering )
{
#ifdef SELF_SHADOW
// If we are allowed to use hiDefFiltering then allow ShadowPCF
if( hiDefFiltering )
{
return shadowBlur ? (shadowsEnabled ? ComputeShadowPCF( shadowCoords) : 1.0f) : ComputeShadowStandard( shadowCoords);
}
else
{
return ComputeShadowStandard( shadowCoords);
}
#else
return 1;
#endif
}
/// ComputeLight
///
/// Computes the sun's contribution to the pixel's color given the dot product
/// of the light direction and surface normal. The dot product is precomputed
/// since other portions of the pixel shader might need it (and we need to reuse
/// as many calculations as possible.)
float3 ComputeLight( float dotLightNormal, float attenuation)
{
/// Typical L.N calculation.
float3 light = sunDiffuse * saturate( dotLightNormal ) * attenuation + sunAmbient;
/// The following will "fill in" the shadow color proportional to the absence of light.
/// This considers the absence of light due to shadows and surface normals pointing away from the light.
/// This way all dark areas match (very cool.)
return lightMultiplier * light + ( 1 - light ) * shadowFill;
}
/// ComputeFogColor
///
/// Compute "fog of war" color
float3 ComputeFogColor(float3 color,float2 texcoord)
{
float fog = 1 - tex2D(fogSampler,texcoord).r;
return fog * color;
}
/// ComputeNormal
///
///
float3 ComputeNormal( sampler2D source, float2 uv, float3x3 rotationMatrix)
{
float3 normal = 2 * tex2D( source, uv).gaa - 1;
normal.z = sqrt( 1 - normal.x*normal.x - normal.y*normal.y );
return normalize( mul( normal, rotationMatrix));
}
///////////////////////////////////////
///
/// Vertex Shaders
///
///////////////////////////////////////
/// DepthVS
///
/// Depth vertex shader
DEPTH_VERTEX DepthVS(
float3 position : POSITION0,
float3 UnusedNormal : NORMAL, // tighten up the linkages for D3D10
float3 UnusedTangent : TANGENT,
float3 UnusedBinormal : BINORMAL,
float4 texcoord0 : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5
)
{
DEPTH_VERTEX vertex = (DEPTH_VERTEX)0;
float4x4 worldMatrix = ComputeWorldMatrix( anim.y + boneIndex[0], row0, row1, row2, row3);
vertex.position = mul( float4(position,1), worldMatrix);
vertex.position = mul( vertex.position, mul( viewMatrix, projMatrix));
vertex.depth = vertex.position.z;
vertex.texcoord0 = texcoord0;
return vertex;
}
/// UndulatingDepthVS
///
/// Depth vertex shader
DEPTH_VERTEX UndulatingDepthVS(
float3 position : POSITION0,
float3 UnusedNormal : NORMAL, // tighten up the linkages for D3D10
float3 UnusedTangent : TANGENT,
float3 UnusedBinormal : BINORMAL,
float4 texcoord0 : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5
)
{
DEPTH_VERTEX vertex = (DEPTH_VERTEX)0;
float weight = 0.003 * position.y;
float4x4 worldMatrix = ComputeWorldMatrix( anim.y + boneIndex[0], row0, row1, row2, row3);
vertex.position = mul( float4(position,1), worldMatrix);
float sinSq = sin( 0.05 * time - dot(windDirection,row3.xyz));
sinSq *= sinSq;
vertex.position.xyz += weight * sinSq * windDirection;
vertex.position = mul( vertex.position, mul( viewMatrix, projMatrix));
vertex.depth = vertex.position.z / vertex.position.w;
vertex.texcoord0 = texcoord0;
return vertex;
}
/// SilhouetteVS
///
///
SILHOUETTE_VERTEX SilhouetteVS(
float3 position : POSITION0,
float3 UnusedNormal : NORMAL, // tighten up the linkages for D3D10
float3 UnusedTangent : TANGENT,
float3 UnusedBinormal : BINORMAL,
float4 UnusedTexcoord : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5
)
{
SILHOUETTE_VERTEX vertex = (SILHOUETTE_VERTEX)0;
float4x4 worldMatrix = ComputeWorldMatrix( anim.y + boneIndex[0], row0, row1, row2, row3);
vertex.position = mul( float4(position,1), worldMatrix);
vertex.position = mul( vertex.position, mul( viewMatrix, projMatrix));
return vertex;
}
/// ClutterVS
///
///
CLUTTER_VERTEX ClutterVS(
float3 position : POSITION0,
float3 normal : NORMAL0,
float3 tangent : TANGENT0,
float3 binormal : BINORMAL0,
float4 texcoord0 : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5,
float4 material : TEXCOORD6
)
{
CLUTTER_VERTEX vertex = (CLUTTER_VERTEX)0;
float4x4 worldMatrix = ComputeWorldMatrix( anim.y + boneIndex[0], row0, row1, row2, row3);
vertex.position = mul( float4(position,1), worldMatrix);
vertex.shadow = ComputeShadowTexcoord( vertex.position);
vertex.position = mul( vertex.position, mul( viewMatrix, projMatrix));
vertex.texcoord0 = texcoord0;
vertex.normal = normalize( mul( normal, (float3x3)worldMatrix));
vertex.dissolve = 0.003922 * anim.z;
float3x3 rotationMatrix = (float3x3)worldMatrix;
vertex.normal = mul( normal, rotationMatrix);
vertex.tangent = mul( tangent, rotationMatrix);
vertex.binormal = mul( binormal, rotationMatrix);
return vertex;
}
/// UndulatingClutterVS
///
///
CLUTTER_VERTEX UndulatingClutterVS(
float3 position : POSITION0,
float3 normal : NORMAL0,
float3 tangent : TANGENT0,
float3 binormal : BINORMAL0,
float4 texcoord0 : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5,
float4 material : TEXCOORD6
)
{
CLUTTER_VERTEX vertex = (CLUTTER_VERTEX)0;
float weight = 0.1 * position.y;
float4x4 worldMatrix = ComputeWorldMatrix( anim.y + boneIndex[0], row0, row1, row2, row3);
vertex.position = mul( float4(position,1), worldMatrix);
float sinSq = sin( 0.0625 * time - dot( windDirection, row3.xyz));
sinSq *= sinSq;
vertex.position.xyz += weight * sinSq * windDirection;
vertex.shadow = ComputeShadowTexcoord( vertex.position);
vertex.position = mul( vertex.position, mul( viewMatrix, projMatrix));
vertex.texcoord0 = texcoord0;
vertex.normal = normalize( mul( normal, (float3x3)worldMatrix));
vertex.dissolve = 0.003922 * anim.z;
float3x3 rotationMatrix = (float3x3)worldMatrix;
vertex.normal = mul( normal, rotationMatrix);
vertex.tangent = mul( tangent, rotationMatrix);
vertex.binormal = mul( binormal, rotationMatrix);
return vertex;
}
/// CartographicVS
///
///
CARTOGRAPHIC_VERTEX CartographicVS(
float3 position : POSITION0,
float3 normal : NORMAL,
float3 UnusedTangent : TANGENT,
float3 UnusedBinormal : BINORMAL,
float4 texcoord0 : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5,
float4 color : COLOR0,
float4 material : TEXCOORD6
)
{
CARTOGRAPHIC_VERTEX vertex = (CARTOGRAPHIC_VERTEX)0;
CompatSwizzle(color);
float4x4 worldMatrix = ComputeWorldMatrix(anim.y+boneIndex[0],row0,row1,row2,row3);
vertex.position = mul(float4(position,1),worldMatrix);
vertex.elevation = vertex.position.y;
vertex.position = mul(vertex.position,mul(viewMatrix,projMatrix));
vertex.uv = texcoord0.xy;
vertex.color = color;
normal = normalize(mul(normal,(float3x3)worldMatrix));
vertex.tone = dot(normal,normalize(float3(-1,3,-1)));
return vertex;
}
/// FlatVS
///
/// Flat vertex shader (no lighting)
FLAT_VERTEX FlatVS(
float3 position : POSITION0,
float3 UnusedNormal : NORMAL, // tighten up the linkages for D3D10
float3 UnusedTangent : TANGENT,
float3 UnusedBinormal : BINORMAL,
float4 texcoord0 : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5,
float4 color : COLOR0,
float4 material : TEXCOORD6
)
{
FLAT_VERTEX vertex = (FLAT_VERTEX)0;
CompatSwizzle(color);
float4x4 worldMatrix = ComputeWorldMatrix( anim.y + boneIndex[0], row0, row1, row2, row3);
vertex.position = mul( float4(position,1), worldMatrix);
vertex.fog = ComputeFogTexcoord(vertex.position.xyz);
vertex.depth = vertex.position.y - surfaceElevation;
vertex.position = mul( vertex.position, mul( viewMatrix, projMatrix));
vertex.texcoord0 = ( anim.w > 0.5 ) ? ComputeScrolledTexcoord( texcoord0, material) : texcoord0;
vertex.color = color;
vertex.material = float4( time - material.x, material.yzw);
return vertex;
}
/// VertexNormalVS
///
/// Vertex normal lighting only
VERTEXNORMAL_VERTEX VertexNormalVS(
float3 position : POSITION0,
float3 normal : NORMAL0,
float3 UnusedTangent : TANGENT, // tighten up the linkages for D3D10
float3 UnusedBinormal : BINORMAL,
float4 texcoord0 : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5,
float4 material : TEXCOORD6,
float4 color : COLOR0
)
{
VERTEXNORMAL_VERTEX vertex = (VERTEXNORMAL_VERTEX)0;
CompatSwizzle(color);
float4x4 worldMatrix = ComputeWorldMatrix( anim.y + boneIndex[0], row0, row1, row2, row3);
vertex.position = mul( float4(position,1), worldMatrix);
vertex.fog = ComputeFogTexcoord(vertex.position.xyz);
vertex.depth = vertex.position.y - surfaceElevation;
vertex.shadow = ComputeShadowTexcoord( vertex.position);
vertex.position = mul( vertex.position, mul( viewMatrix, projMatrix));
vertex.texcoord0 = ( anim.w > 0.5 ) ? ComputeScrolledTexcoord( texcoord0, material) : texcoord0;
vertex.color = color;
vertex.material = float4( time - material.x, material.yzw);
vertex.normal = normalize( mul( normal, (float3x3)worldMatrix));
return vertex;
}
/// NormalMappedVS
///
/// Normal mapped lighting
NORMALMAPPED_VERTEX NormalMappedVS(
float3 position : POSITION0,
float3 normal : NORMAL0,
float3 tangent : TANGENT0,
float3 binormal : BINORMAL0,
float4 texcoord0 : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5,
float4 material : TEXCOORD6,
float4 color : COLOR0
)
{
NORMALMAPPED_VERTEX vertex = (NORMALMAPPED_VERTEX)0;
CompatSwizzle(color);
float4x4 worldMatrix = ComputeWorldMatrix( anim.y + boneIndex[0], row0, row1, row2, row3);
vertex.position = mul( float4(position,1), worldMatrix);
vertex.depth.zw = ComputeFogTexcoord(vertex.position.xyz);
vertex.depth.xy = float2(vertex.position.y - surfaceElevation,material.x);
vertex.shadow = ComputeShadowTexcoord( vertex.position);
vertex.position = mul( vertex.position, mul( viewMatrix, projMatrix));
vertex.viewDirection = normalize( vertex.position.xyz / vertex.position.w);
vertex.viewDirection = mul( viewMatrix, vertex.viewDirection);
vertex.texcoord0 = ( anim.w > 0.5 ) ? ComputeScrolledTexcoord( texcoord0, material) : texcoord0;
vertex.color = color;
vertex.material = float4( time - material.x, material.yzw);
float3x3 rotationMatrix = (float3x3)worldMatrix;
vertex.normal = mul( normal, rotationMatrix);
vertex.tangent = mul( tangent, rotationMatrix);
vertex.binormal = mul( binormal, rotationMatrix);
return vertex;
}
/// UndulatingNormalMappedVS
///
/// Normal mapped lighting with
NORMALMAPPED_VERTEX UndulatingNormalMappedVS(
float3 position : POSITION0,
float3 normal : NORMAL0,
float3 tangent : TANGENT0,
float3 binormal : BINORMAL0,
float4 texcoord0 : TEXCOORD0,
int boneIndex[4] : BLENDINDICES,
float3 row0 : TEXCOORD1,
float3 row1 : TEXCOORD2,
float3 row2 : TEXCOORD3,
float3 row3 : TEXCOORD4,
anim_t anim : TEXCOORD5,
float4 material : TEXCOORD6,
float4 color : COLOR0
)
{
NORMALMAPPED_VERTEX vertex = (NORMALMAPPED_VERTEX)0;
CompatSwizzle(color);
float weight = 0.003 * position.y;
float4x4 worldMatrix = ComputeWorldMatrix( anim.y + boneIndex[0], row0, row1, row2, row3);
vertex.position = mul( float4(position,1), worldMatrix);
float sinSq = sin( 0.05 * time - dot(windDirection, row3.xyz));
sinSq *= sinSq;
vertex.position.xyz += weight * sinSq * windDirection;
vertex.depth.zw = ComputeFogTexcoord(vertex.position.xyz);
vertex.depth.xy = float2(vertex.position.y - surfaceElevation,material.x);
vertex.shadow = ComputeShadowTexcoord( vertex.position);
vertex.position = mul( vertex.position, mul( viewMatrix, projMatrix));
vertex.viewDirection = normalize( vertex.position.xyz / vertex.position.w);
vertex.viewDirection = mul( viewMatrix, vertex.viewDirection);
vertex.texcoord0 = texcoord0;
vertex.color = color;
vertex.material = float4( time - material.x, material.yzw);
float3x3 rotationMatrix = (float3x3)worldMatrix;
vertex.normal = mul( normal, rotationMatrix);
vertex.tangent = mul( tangent, rotationMatrix);
vertex.binormal = mul( binormal, rotationMatrix);
return vertex;
}
/// BloatingNormalMappedVS
///
///
NORMALMAPPED_VERTEX BloatingNormalMappedVS(
float3 position : POSITION0,