-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMES40 SpotLight.fxsub
281 lines (196 loc) · 15.3 KB
/
MES40 SpotLight.fxsub
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
#if LIGHTSOURCES == 1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float SpotLight_Intensity = 1;
float SpotLight_Angle = 50;
float SpotLight_Range = 50;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float3 SpotLight1_Pos : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "light"; >;
float4x4 SpotLight1_Dir : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "light"; >;
float SpotLight1_Intensity_P : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "Intensity +"; >;
float SpotLight1_Intensity_M : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "Intensity -"; >;
static float SpotLight1_Intensity = SpotLight_Intensity + SpotLight1_Intensity_P*SpotLight_Intensity - SpotLight1_Intensity_M*SpotLight_Intensity;
float SpotLight1_Range_P : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "Range +"; >;
float SpotLight1_Range_M : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "Range -"; >;
static float SpotLight1_Range = SpotLight_Range + SpotLight1_Range_P*SpotLight_Range - SpotLight1_Range_M*SpotLight_Range;
float SpotLight1_Angle_P : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "Angle +"; >;
float SpotLight1_Angle_M : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "Angle -"; >;
static float SpotLight1_Angle = SpotLight_Angle - SpotLight1_Angle_P*SpotLight_Angle + SpotLight1_Angle_M*SpotLight_Angle*10 + SpotLight_Angle/10;
float SpotLight1_Red : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "Red +"; >;
float SpotLight1_Green : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "Green +"; >;
float SpotLight1_Blue : CONTROLOBJECT < string name = "MES40 SpotLight1.pmx"; string item = "Blue +"; >;
static float3 SpotLight1_Color = float3(SpotLight1_Red,SpotLight1_Green,SpotLight1_Blue);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float3 SpotLight2_Pos : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "light"; >;
float4x4 SpotLight2_Dir : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "light"; >;
float SpotLight2_Intensity_P : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "Intensity +"; >;
float SpotLight2_Intensity_M : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "Intensity -"; >;
static float SpotLight2_Intensity = SpotLight_Intensity + SpotLight2_Intensity_P*SpotLight_Intensity - SpotLight2_Intensity_M*SpotLight_Intensity;
float SpotLight2_Range_P : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "Range +"; >;
float SpotLight2_Range_M : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "Range -"; >;
static float SpotLight2_Range = SpotLight_Range + SpotLight2_Range_P*SpotLight_Range - SpotLight2_Range_M*SpotLight_Range;
float SpotLight2_Angle_P : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "Angle +"; >;
float SpotLight2_Angle_M : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "Angle -"; >;
static float SpotLight2_Angle = SpotLight_Angle - SpotLight2_Angle_P*SpotLight_Angle + SpotLight2_Angle_M*SpotLight_Angle*10 + SpotLight_Angle/10;
float SpotLight2_Red : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "Red +"; >;
float SpotLight2_Green : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "Green +"; >;
float SpotLight2_Blue : CONTROLOBJECT < string name = "MES40 SpotLight2.pmx"; string item = "Blue +"; >;
static float3 SpotLight2_Color = float3(SpotLight2_Red,SpotLight2_Green,SpotLight2_Blue);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float3 SpotLight3_Pos : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "light"; >;
float4x4 SpotLight3_Dir : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "light"; >;
float SpotLight3_Intensity_P : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "Intensity +"; >;
float SpotLight3_Intensity_M : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "Intensity -"; >;
static float SpotLight3_Intensity = SpotLight_Intensity + SpotLight3_Intensity_P*SpotLight_Intensity - SpotLight3_Intensity_M*SpotLight_Intensity;
float SpotLight3_Range_P : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "Range +"; >;
float SpotLight3_Range_M : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "Range -"; >;
static float SpotLight3_Range = SpotLight_Range + SpotLight3_Range_P*SpotLight_Range - SpotLight3_Range_M*SpotLight_Range;
float SpotLight3_Angle_P : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "Angle +"; >;
float SpotLight3_Angle_M : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "Angle -"; >;
static float SpotLight3_Angle = SpotLight_Angle - SpotLight3_Angle_P*SpotLight_Angle + SpotLight3_Angle_M*SpotLight_Angle*10 + SpotLight_Angle/10;
float SpotLight3_Red : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "Red +"; >;
float SpotLight3_Green : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "Green +"; >;
float SpotLight3_Blue : CONTROLOBJECT < string name = "MES40 SpotLight3.pmx"; string item = "Blue +"; >;
static float3 SpotLight3_Color = float3(SpotLight3_Red,SpotLight3_Green,SpotLight3_Blue);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float3 SpotLight4_Pos : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "light"; >;
float4x4 SpotLight4_Dir : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "light"; >;
float SpotLight4_Intensity_P : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "Intensity +"; >;
float SpotLight4_Intensity_M : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "Intensity -"; >;
static float SpotLight4_Intensity = SpotLight_Intensity + SpotLight4_Intensity_P*SpotLight_Intensity - SpotLight4_Intensity_M*SpotLight_Intensity;
float SpotLight4_Range_P : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "Range +"; >;
float SpotLight4_Range_M : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "Range -"; >;
static float SpotLight4_Range = SpotLight_Range + SpotLight4_Range_P*SpotLight_Range - SpotLight4_Range_M*SpotLight_Range;
float SpotLight4_Angle_P : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "Angle +"; >;
float SpotLight4_Angle_M : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "Angle -"; >;
static float SpotLight4_Angle = SpotLight_Angle - SpotLight4_Angle_P*SpotLight_Angle + SpotLight4_Angle_M*SpotLight_Angle*10 + SpotLight_Angle/10;
float SpotLight4_Red : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "Red +"; >;
float SpotLight4_Green : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "Green +"; >;
float SpotLight4_Blue : CONTROLOBJECT < string name = "MES40 SpotLight4.pmx"; string item = "Blue +"; >;
static float3 SpotLight4_Color = float3(SpotLight4_Red,SpotLight4_Green,SpotLight4_Blue);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float3 SpotLight5_Pos : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "light"; >;
float4x4 SpotLight5_Dir : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "light"; >;
float SpotLight5_Intensity_P : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "Intensity +"; >;
float SpotLight5_Intensity_M : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "Intensity -"; >;
static float SpotLight5_Intensity = SpotLight_Intensity + SpotLight5_Intensity_P*SpotLight_Intensity - SpotLight5_Intensity_M*SpotLight_Intensity;
float SpotLight5_Range_P : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "Range +"; >;
float SpotLight5_Range_M : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "Range -"; >;
static float SpotLight5_Range = SpotLight_Range + SpotLight5_Range_P*SpotLight_Range - SpotLight5_Range_M*SpotLight_Range;
float SpotLight5_Angle_P : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "Angle +"; >;
float SpotLight5_Angle_M : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "Angle -"; >;
static float SpotLight5_Angle = SpotLight_Angle - SpotLight5_Angle_P*SpotLight_Angle + SpotLight5_Angle_M*SpotLight_Angle*10 + SpotLight_Angle/10;
float SpotLight5_Red : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "Red +"; >;
float SpotLight5_Green : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "Green +"; >;
float SpotLight5_Blue : CONTROLOBJECT < string name = "MES40 SpotLight5.pmx"; string item = "Blue +"; >;
static float3 SpotLight5_Color = float3(SpotLight5_Red,SpotLight5_Green,SpotLight5_Blue);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct SpotLightVS_OUTPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 Normal : TEXCOORD1;
float3 Eye : TEXCOORD2;
float3 SpotLightPos1 : TEXCOORD3;
float3 SpotLightPos2 : TEXCOORD4;
float3 SpotLightPos3 : TEXCOORD5;
float3 SpotLightPos4 : TEXCOORD6;
float3 SpotLightPos5 : TEXCOORD7;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SpotLightVS_OUTPUT SpotLight_VS(float4 Pos : POSITION, float3 Normal : NORMAL, float2 Tex : TEXCOORD0)
{
SpotLightVS_OUTPUT Out = (SpotLightVS_OUTPUT)0;
Out.Pos = mul( Pos, WorldViewProjMatrix_Final() );
Out.Normal = normalize( mul( Normal, (float3x3)WorldMatrix ) );
Out.Tex = Tex;
Out.SpotLightPos1 = SpotLight1_Pos - mul( Pos, WorldMatrix );
Out.SpotLightPos2 = SpotLight2_Pos - mul( Pos, WorldMatrix );
Out.SpotLightPos3 = SpotLight3_Pos - mul( Pos, WorldMatrix );
Out.SpotLightPos4 = SpotLight4_Pos - mul( Pos, WorldMatrix );
Out.SpotLightPos5 = SpotLight5_Pos - mul( Pos, WorldMatrix );
return Out;
}
float3 SpotLight(float3 SpotLightPos, float4x4 SpotLightDir, float3 Color, float Range, float Angle, float3 Normal)
{
float3 SpotLight_Pos = normalize(SpotLightPos);
float3 SpotLight_Pos_ = SpotLightPos;
float3 SpotLight_Dir = normalize(SpotLightDir._31_32_33);
#if LightSource_Use_Toon_Gradient == 0
float Gradient = 1;
#else
float Gradient = Toon_Gradient;
#endif
float3 Shade = saturate(dot(SpotLight_Pos,Normal)*Gradient);
float Distance = length(SpotLight_Pos_.xyz);
float Fade = saturate((1/(Distance+Distance))*Range);
float3 SpotLight = pow(saturate(dot(SpotLight_Pos,SpotLight_Dir)),Angle) * Fade * Shade;
SpotLight *= Color;
return SpotLight;
}
// ピクセルシェーダ
float4 SpotLight_PS(SpotLightVS_OUTPUT IN) : COLOR
{
///////////////////////////////////////////////////////////////////////////////////////
#if LightSource_Use_NormalMap == 1
#ifdef NormalMapTexture
float4 NormalColor;
NormalColor.xyz = tex2D(NormalMapSamp,IN.Tex).rgb*2;
NormalColor.a = 1;
NormalColor.xyz = lerp(float3(0.5,0.5,1)*2,NormalColor.xyz,NormalMap_Intensity);
float3 Normal_Mapped = normalize(IN.Normal);
float3 v = normalize(IN.Eye);
float3x3 tangentFrame = compute_tangent_frame(Normal_Mapped, v, IN.Tex);
Normal_Mapped = (mul(NormalColor - 1.0f, tangentFrame));
#else
float3 Normal_Mapped = normalize(IN.Normal);
#endif
#else
float3 Normal_Mapped = normalize(IN.Normal);
#endif
///////////////////////////////////////////////////////////////////////////////////////
float3 SpotLight1 = SpotLight( IN.SpotLightPos1, SpotLight1_Dir, SpotLight1_Color, SpotLight1_Range, SpotLight1_Angle, Normal_Mapped) *0.5;
float3 SpotLight2 = SpotLight( IN.SpotLightPos2, SpotLight2_Dir, SpotLight2_Color, SpotLight2_Range, SpotLight2_Angle, Normal_Mapped) *0.5;
float3 SpotLight3 = SpotLight( IN.SpotLightPos3, SpotLight3_Dir, SpotLight3_Color, SpotLight3_Range, SpotLight3_Angle, Normal_Mapped) *0.5;
float3 SpotLight4 = SpotLight( IN.SpotLightPos4, SpotLight4_Dir, SpotLight4_Color, SpotLight4_Range, SpotLight4_Angle, Normal_Mapped) *0.5;
float3 SpotLight5 = SpotLight( IN.SpotLightPos5, SpotLight5_Dir, SpotLight5_Color, SpotLight5_Range, SpotLight5_Angle, Normal_Mapped) *0.5;
///////////////////////////////////////////////////////////////////////////////////////
float4 Color = float4(0,0,0,1);
Color.rgb = (SpotLight1*SpotLight1_Intensity) + (SpotLight2*SpotLight2_Intensity) + (SpotLight3*SpotLight3_Intensity) + (SpotLight4*SpotLight4_Intensity) + (SpotLight5*SpotLight5_Intensity);
///////////////////////////////////////////////////////////////////////////////////////
#if LightSource_Use_SpecularMap == 1
#ifdef SpecularMapTexture
float4 SpecularLevel = tex2D(SpecularMapSamp, IN.Tex);
float SpecularLevelMono = (SpecularLevel.r+SpecularLevel.g+SpecularLevel.b)/3;
SpecularLevel.rgb = lerp(SpecularLevelMono,SpecularLevel.rgb,SpecularMap_Saturation);
#else
float4 SpecularLevel = float4(1,1,1,1);
#endif
Color.rgb *= SpecularLevel;
#endif
///////////////////////////////////////////////////////////////////////////////////////
return Color;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#else
struct SpotLightVS_OUTPUT
{
float4 Pos : POSITION;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SpotLightVS_OUTPUT SpotLight_VS(float4 Pos : POSITION)
{
SpotLightVS_OUTPUT Out = (SpotLightVS_OUTPUT)0;
Out.Pos = mul( Pos, WorldViewProjMatrix_Final() );
return Out;
}
float4 SpotLight_PS() : COLOR
{
return float4(0,0,0,1);
}
#endif