Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SkinnedEffect.cs
Go to the documentation of this file.
1using System;
3
5
7{
8 public const int MaxBones = 72;
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
38 private bool oneLight;
39
40 private bool fogEnabled;
41
43
45
47
49
51
53
55
56 private float alpha = 1f;
57
59
61
63
64 private float fogStart;
65
66 private float fogEnd = 1f;
67
68 private int weightsPerVertex = 4;
69
71
73 {
74 get
75 {
76 return world;
77 }
78 set
79 {
80 world = value;
81 dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.World | EffectDirtyFlags.Fog;
82 }
83 }
84
85 public Matrix View
86 {
87 get
88 {
89 return view;
90 }
91 set
92 {
93 view = value;
94 dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.EyePosition | EffectDirtyFlags.Fog;
95 }
96 }
97
99 {
100 get
101 {
102 return projection;
103 }
104 set
105 {
107 dirtyFlags |= EffectDirtyFlags.WorldViewProj;
108 }
109 }
110
112 {
113 get
114 {
115 return diffuseColor;
116 }
117 set
118 {
120 dirtyFlags |= EffectDirtyFlags.MaterialColor;
121 }
122 }
123
125 {
126 get
127 {
128 return emissiveColor;
129 }
130 set
131 {
133 dirtyFlags |= EffectDirtyFlags.MaterialColor;
134 }
135 }
136
138 {
139 get
140 {
142 }
143 set
144 {
146 }
147 }
148
149 public float SpecularPower
150 {
151 get
152 {
154 }
155 set
156 {
158 }
159 }
160
161 public float Alpha
162 {
163 get
164 {
165 return alpha;
166 }
167 set
168 {
169 alpha = value;
170 dirtyFlags |= EffectDirtyFlags.MaterialColor;
171 }
172 }
173
175 {
176 get
177 {
179 }
180 set
181 {
183 {
185 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
186 }
187 }
188 }
189
191 {
192 get
193 {
194 return ambientLightColor;
195 }
196 set
197 {
199 dirtyFlags |= EffectDirtyFlags.MaterialColor;
200 }
201 }
202
204
206
208
209 public bool FogEnabled
210 {
211 get
212 {
213 return fogEnabled;
214 }
215 set
216 {
217 if (fogEnabled != value)
218 {
220 dirtyFlags |= EffectDirtyFlags.FogEnable | EffectDirtyFlags.ShaderIndex;
221 }
222 }
223 }
224
225 public float FogStart
226 {
227 get
228 {
229 return fogStart;
230 }
231 set
232 {
233 fogStart = value;
235 }
236 }
237
238 public float FogEnd
239 {
240 get
241 {
242 return fogEnd;
243 }
244 set
245 {
246 fogEnd = value;
248 }
249 }
250
252 {
253 get
254 {
256 }
257 set
258 {
260 }
261 }
262
264 {
265 get
266 {
268 }
269 set
270 {
272 }
273 }
274
276 {
277 get
278 {
279 return weightsPerVertex;
280 }
281 set
282 {
283 if (value != 1 && value != 2 && value != 4)
284 {
286 }
288 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
289 }
290 }
291
292 bool IEffectLights.LightingEnabled
293 {
294 get
295 {
296 return true;
297 }
298 set
299 {
300 if (!value)
301 {
302 throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, FrameworkResources.CantDisableLighting, new object[1] { typeof(SkinnedEffect).Name }));
303 }
304 }
305 }
306
307 public void SetBoneTransforms(Matrix[] boneTransforms)
308 {
309 if (boneTransforms == null || boneTransforms.Length == 0)
310 {
311 throw new ArgumentNullException("boneTransforms", FrameworkResources.NullNotAllowed);
312 }
313 if (boneTransforms.Length > 72)
314 {
316 }
317 bonesParam.SetValue(boneTransforms);
318 }
319
321 {
322 if (count <= 0)
323 {
324 throw new ArgumentOutOfRangeException("count");
325 }
326 if (count > 72)
327 {
329 }
330 Matrix[] valueMatrixArray = bonesParam.GetValueMatrixArray(count);
331 for (int i = 0; i < valueMatrixArray.Length; i++)
332 {
333 valueMatrixArray[i].M44 = 1f;
334 }
335 return valueMatrixArray;
336 }
337
339 : base(device, SkinnedEffectCode.Code)
340 {
342 DirectionalLight0.Enabled = true;
344 SpecularPower = 16f;
345 Matrix[] array = new Matrix[72];
346 for (int i = 0; i < 72; i++)
347 {
348 ref Matrix reference = ref array[i];
349 reference = Matrix.Identity;
350 }
352 }
353
354 protected SkinnedEffect(SkinnedEffect cloneSource)
355 : base(cloneSource)
356 {
357 CacheEffectParameters(cloneSource);
359 fogEnabled = cloneSource.fogEnabled;
360 world = cloneSource.world;
361 view = cloneSource.view;
362 projection = cloneSource.projection;
363 diffuseColor = cloneSource.diffuseColor;
364 emissiveColor = cloneSource.emissiveColor;
366 alpha = cloneSource.alpha;
367 fogStart = cloneSource.fogStart;
368 fogEnd = cloneSource.fogEnd;
370 }
371
372 public override Effect Clone()
373 {
374 return new SkinnedEffect(this);
375 }
376
381
382 private void CacheEffectParameters(SkinnedEffect cloneSource)
383 {
384 textureParam = base.Parameters["Texture"];
385 diffuseColorParam = base.Parameters["DiffuseColor"];
386 emissiveColorParam = base.Parameters["EmissiveColor"];
387 specularColorParam = base.Parameters["SpecularColor"];
388 specularPowerParam = base.Parameters["SpecularPower"];
389 eyePositionParam = base.Parameters["EyePosition"];
390 fogColorParam = base.Parameters["FogColor"];
391 fogVectorParam = base.Parameters["FogVector"];
392 worldParam = base.Parameters["World"];
393 worldInverseTransposeParam = base.Parameters["WorldInverseTranspose"];
394 worldViewProjParam = base.Parameters["WorldViewProj"];
395 bonesParam = base.Parameters["Bones"];
396 shaderIndexParam = base.Parameters["ShaderIndex"];
397 light0 = new DirectionalLight(base.Parameters["DirLight0Direction"], base.Parameters["DirLight0DiffuseColor"], base.Parameters["DirLight0SpecularColor"], cloneSource?.light0);
398 light1 = new DirectionalLight(base.Parameters["DirLight1Direction"], base.Parameters["DirLight1DiffuseColor"], base.Parameters["DirLight1SpecularColor"], cloneSource?.light1);
399 light2 = new DirectionalLight(base.Parameters["DirLight2Direction"], base.Parameters["DirLight2DiffuseColor"], base.Parameters["DirLight2SpecularColor"], cloneSource?.light2);
400 }
401
402 internal override bool WantParameter(EffectParameter parameter)
403 {
404 if (parameter.Name != "VSIndices")
405 {
406 return parameter.Name != "PSIndices";
407 }
408 return false;
409 }
410
411 protected internal override void OnApply()
412 {
415 if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0)
416 {
418 dirtyFlags &= ~EffectDirtyFlags.MaterialColor;
419 }
420 bool flag = !light1.Enabled && !light2.Enabled;
421 if (oneLight != flag)
422 {
423 oneLight = flag;
424 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
425 }
426 if ((dirtyFlags & EffectDirtyFlags.ShaderIndex) != 0)
427 {
428 int num = 0;
429 if (!fogEnabled)
430 {
431 num++;
432 }
433 if (weightsPerVertex == 2)
434 {
435 num += 2;
436 }
437 else if (weightsPerVertex == 4)
438 {
439 num += 4;
440 }
442 {
443 num += 12;
444 }
445 else if (oneLight)
446 {
447 num += 6;
448 }
450 dirtyFlags &= ~EffectDirtyFlags.ShaderIndex;
451 }
452 }
453}
static Vector3 EnableDefaultLighting(DirectionalLight light0, DirectionalLight light1, DirectionalLight light2)
static void SetMaterialColor(bool lightingEnabled, float alpha, ref Vector3 diffuseColor, ref Vector3 emissiveColor, ref Vector3 ambientLightColor, EffectParameter diffuseColorParam, EffectParameter emissiveColorParam)
static EffectDirtyFlags SetLightingMatrices(EffectDirtyFlags dirtyFlags, ref Matrix world, ref Matrix view, EffectParameter worldParam, EffectParameter worldInverseTransposeParam, EffectParameter eyePositionParam)
static EffectDirtyFlags SetWorldViewProjAndFog(EffectDirtyFlags dirtyFlags, ref Matrix world, ref Matrix view, ref Matrix projection, ref Matrix worldView, bool fogEnabled, float fogStart, float fogEnd, EffectParameter worldViewProjParam, EffectParameter fogVectorParam)
void CacheEffectParameters(SkinnedEffect cloneSource)
void SetBoneTransforms(Matrix[] boneTransforms)
override bool WantParameter(EffectParameter parameter)
static CultureInfo CurrentCulture