-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEffect_Character.fx
158 lines (133 loc) · 3.31 KB
/
Effect_Character.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
float4x3 WorldArray[28];
float4x4 World;
float4x4 ViewProj;
float4x4 ShadowViewProj;
float4 Light;
float4 ColorDiffuse;
float4 ColorAmbient;
int CurrentNumWeights;
struct VS_IN
{
float4 Pos : POSITION;
float4 BWeights: BLENDWEIGHT;
float4 BIndices: BLENDINDICES;
float3 Normal : NORMAL;
float2 Tex0 : TEXCOORD0;
};
struct VS_IN_NOSKINNING
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
float2 Tex0 : TEXCOORD0;
};
struct VS_OUT
{
float4 Pos : POSITION;
float4 Diffuse : COLOR0;
float2 Tex0 : TEXCOORD0;
};
struct SHADOW_OUT
{
float4 Pos : POSITION;
float4 Diffuse : COLOR0;
};
VS_OUT HLSLSkinning( VS_IN In, uniform int NumWeights )
{
VS_OUT O = (VS_OUT)0;
float3 Pos = 0.f;
float3 Normal = 0.f;
float SumWeights = 0.f;
// 애플리케이션에서 UBYTE4->D3DCOLOR 해준것을 다시 UBYTE4로 바꿔준다.
int BIndices[4] = (int[4])D3DCOLORtoUBYTE4(In.BIndices);
float BWeights[4] = (float[4])In.BWeights;
for( int I=0; I<NumWeights; ++I )
{
SumWeights += BWeights[I];
Pos += BWeights[I]*mul(In.Pos, WorldArray[BIndices[I]]);
Normal += BWeights[I]*mul(In.Normal, WorldArray[BIndices[I]]);
}
SumWeights = 1-SumWeights;
Pos += SumWeights*mul(In.Pos, WorldArray[BIndices[NumWeights]]);
Normal += SumWeights*mul(In.Normal, WorldArray[BIndices[NumWeights]]);
O.Pos = mul( float4(Pos,1.f), ViewProj);
O.Diffuse = ColorAmbient+(ColorDiffuse*max(0.1f, dot(Normal,Light)));
O.Tex0 = In.Tex0;
return O;
};
VS_OUT HLSLNoSkinning( VS_IN_NOSKINNING In )
{
VS_OUT O = (VS_OUT)0;
float4 Pos = mul( In.Pos, World);
O.Pos = mul( Pos, ViewProj);
float3 N = mul( In.Normal, World);
O.Diffuse = ColorAmbient+(ColorDiffuse*max(0.1f, dot(N,Light)));
O.Tex0 = In.Tex0;
return O;
};
SHADOW_OUT DrawShadow( VS_IN In )
{
SHADOW_OUT O = (SHADOW_OUT)0;
float3 Pos = 0.f;
// 애플리케이션에서 UBYTE4->D3DCOLOR 해준것을 다시 UBYTE4로 바꿔준다.
int BIndices[4] = (int[4])D3DCOLORtoUBYTE4(In.BIndices);
float BWeights[4] = (float[4])In.BWeights;
Pos = mul( In.Pos, WorldArray[BIndices[0]] );
O.Pos = mul( float4(Pos,1.f), ShadowViewProj);
O.Diffuse= float4(0.2f, 0.2f, 0.2f, .8f );
return O;
};
SHADOW_OUT DrawShadowNoSkinning( VS_IN_NOSKINNING In )
{
SHADOW_OUT O = (SHADOW_OUT)0;
float4 Pos = mul( In.Pos, World);
O.Pos = mul( Pos, ViewProj);
O.Diffuse = float4(0.2f, 0.2f, 0.2f, .8f );
return O;
};
float4 DrawShadowPs( SHADOW_OUT In ) : COLOR
{
return In.Diffuse;
};
technique IndexedSkinning
{
pass P0
{
VertexShader = compile vs_2_0 HLSLSkinning( CurrentNumWeights );
}
pass P1
{
StencilEnable = TRUE;
StencilFunc = Equal;
StencilRef = 0x0;
StencilMask = 0xFFFFFFFF;
StencilFail = keep;
StencilZFail = keep;
StencilPass = Incr;
AlphaBlendEnable= TRUE;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
ZWriteEnable = False;
VertexShader = compile vs_2_0 DrawShadow();
PixelShader = compile ps_2_0 DrawShadowPs();
}
pass P2
{
VertexShader = compile vs_2_0 HLSLNoSkinning();
}
pass P3
{
StencilEnable = TRUE;
StencilFunc = Equal;
StencilRef = 0x0;
StencilMask = 0xFFFFFFFF;
StencilFail = keep;
StencilZFail = keep;
StencilPass = Incr;
AlphaBlendEnable= TRUE;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
ZWriteEnable = False;
VertexShader = compile vs_2_0 DrawShadowNoSkinning();
PixelShader = compile ps_2_0 DrawShadowPs();
}
}