-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEx.txt
90 lines (73 loc) · 2.74 KB
/
Ex.txt
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
//
// Skinned Mesh Effect file
// Copyright (c) 2000-2002 Microsoft Corporation. All rights reserved.
//
float4 CRAmbient : CRAmbient = {0.1f, 0.1f, 0.1f, 1.0f};
float4 CRDiffuse : CRDiffuse = {0.8f, 0.8f, 0.8f, 1.0f};
float4 Lights;
// Matrix Pallette
static const int MAX_MATRICES = 30;
float4x4 mViewProj : VIEWPROJECTION;
float4x3 WoldViewProjs[MAX_MATRICES] : WORLDMATRIXARRAY;
///////////////////////////////////////////////////////
struct VS_INPUT
{
float4 Pos : POSITION;
float4 BlendWeights : BLENDWEIGHT;
float4 BlendIndices : BLENDINDICES;
float3 Normal : NORMAL;
float3 Tex0 : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 Diffuse : COLOR;
float2 Tex0 : TEXCOORD0;
};
VS_OUTPUT VShade(VS_INPUT i, uniform int NumBones)
{
VS_OUTPUT o;
float3 Pos = 0.0f;
float3 Normal = 0.0f;
float LastWeight = 0.0f;
// Compensate for lack of UBYTE4 on Geforce3
int4 IndexVector = D3DCOLORtoUBYTE4(i.BlendIndices);
// cast the vectors to arrays for use in the for loop below
float BlendWeightsArray[4] = (float[4])i.BlendWeights;
int IndexArray[4] = (int[4])IndexVector;
// calculate the pos/normal using the "normal" weights
// and accumulate the weights to calculate the last weight
for (int iBone = 0; iBone < NumBones-1; iBone++)
{
LastWeight = LastWeight + BlendWeightsArray[iBone];
Pos += mul(i.Pos, WoldViewProjs[IndexArray[iBone]]) * BlendWeightsArray[iBone];
Normal += mul(i.Normal, WoldViewProjs[IndexArray[iBone]]) * BlendWeightsArray[iBone];
}
LastWeight = 1.0f - LastWeight;
// Now that we have the calculated weight, add in the final influence
Pos += (mul(i.Pos, WoldViewProjs[IndexArray[NumBones-1]]) * LastWeight);
Normal += mul(i.Normal, WoldViewProjs[IndexArray[NumBones-1]]) * LastWeight;
// transform position from world space into view and then projection space
o.Pos = mul(float4(Pos.xyz, 1.0f), mViewProj);
o.Diffuse.xyz = CRAmbient.xyz + CRDiffuse.xyz*max(0.f,dot(Lights.xyz, Normal));
o.Diffuse.w = 1.0f;
// copy the input texture coordinate through
o.Tex0 = i.Tex0.xy;
return o;
}
int CurrentNumWeights = 3;
VertexShader vsArray[4] = { compile vs_1_1 VShade(1),
compile vs_1_1 VShade(2),
compile vs_1_1 VShade(3),
compile vs_1_1 VShade(4)
};
//////////////////////////////////////
// Techniques specs follow
//////////////////////////////////////
technique IndexedHLSL
{
pass p0
{
VertexShader = compile vs_2_0 VShade(CurrentNumWeights );
}
}