Repository navigation
Expand file tree
/
Copy pathSkinnedEffect.cpp
More file actions
618 lines (492 loc) · 21.1 KB
/
Copy pathSkinnedEffect.cpp
File metadata and controls
618 lines (492 loc) · 21.1 KB
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
//--------------------------------------------------------------------------------------
// File: SkinnedEffect.cpp
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//
// https://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "EffectCommon.h"
using namespace DirectX;
namespace
{
// Constant buffer layout. Must match the shader!
struct SkinnedEffectConstants
{
XMVECTOR diffuseColor;
XMVECTOR emissiveColor;
XMVECTOR specularColorAndPower;
XMVECTOR lightDirection[IEffectLights::MaxDirectionalLights];
XMVECTOR lightDiffuseColor[IEffectLights::MaxDirectionalLights];
XMVECTOR lightSpecularColor[IEffectLights::MaxDirectionalLights];
XMVECTOR eyePosition;
XMVECTOR fogColor;
XMVECTOR fogVector;
XMMATRIX world;
XMVECTOR worldInverseTranspose[3];
XMMATRIX worldViewProj;
XMVECTOR bones[SkinnedEffect::MaxBones][3];
};
static_assert((sizeof(SkinnedEffectConstants) % 16) == 0, "CB size not padded correctly");
// Traits type describes our characteristics to the EffectBase template.
struct SkinnedEffectTraits
{
using ConstantBufferType = SkinnedEffectConstants;
static constexpr int VertexShaderCount = 18;
static constexpr int PixelShaderCount = 3;
static constexpr int ShaderPermutationCount = 36;
};
} // namespace
// Internal SkinnedEffect implementation class.
class SkinnedEffect::Impl : public EffectBase<SkinnedEffectTraits>
{
public:
explicit Impl(_In_ ID3D11Device* device);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
bool preferPerPixelLighting;
bool biasedVertexNormals;
int weightsPerVertex;
EffectLights lights;
int GetCurrentShaderPermutation() const noexcept;
void Apply(_In_ ID3D11DeviceContext* deviceContext);
};
#pragma region Shaders
// Include the precompiled shader code.
namespace
{
#if defined(_XBOX_ONE) && defined(_TITLE)
#include "XboxOneSkinnedEffect_VSSkinnedVertexLightingOneBone.inc"
#include "XboxOneSkinnedEffect_VSSkinnedVertexLightingTwoBones.inc"
#include "XboxOneSkinnedEffect_VSSkinnedVertexLightingFourBones.inc"
#include "XboxOneSkinnedEffect_VSSkinnedOneLightOneBone.inc"
#include "XboxOneSkinnedEffect_VSSkinnedOneLightTwoBones.inc"
#include "XboxOneSkinnedEffect_VSSkinnedOneLightFourBones.inc"
#include "XboxOneSkinnedEffect_VSSkinnedPixelLightingOneBone.inc"
#include "XboxOneSkinnedEffect_VSSkinnedPixelLightingTwoBones.inc"
#include "XboxOneSkinnedEffect_VSSkinnedPixelLightingFourBones.inc"
#include "XboxOneSkinnedEffect_VSSkinnedVertexLightingOneBoneBn.inc"
#include "XboxOneSkinnedEffect_VSSkinnedVertexLightingTwoBonesBn.inc"
#include "XboxOneSkinnedEffect_VSSkinnedVertexLightingFourBonesBn.inc"
#include "XboxOneSkinnedEffect_VSSkinnedOneLightOneBoneBn.inc"
#include "XboxOneSkinnedEffect_VSSkinnedOneLightTwoBonesBn.inc"
#include "XboxOneSkinnedEffect_VSSkinnedOneLightFourBonesBn.inc"
#include "XboxOneSkinnedEffect_VSSkinnedPixelLightingOneBoneBn.inc"
#include "XboxOneSkinnedEffect_VSSkinnedPixelLightingTwoBonesBn.inc"
#include "XboxOneSkinnedEffect_VSSkinnedPixelLightingFourBonesBn.inc"
#include "XboxOneSkinnedEffect_PSSkinnedVertexLighting.inc"
#include "XboxOneSkinnedEffect_PSSkinnedVertexLightingNoFog.inc"
#include "XboxOneSkinnedEffect_PSSkinnedPixelLighting.inc"
#else
#include "SkinnedEffect_VSSkinnedVertexLightingOneBone.inc"
#include "SkinnedEffect_VSSkinnedVertexLightingTwoBones.inc"
#include "SkinnedEffect_VSSkinnedVertexLightingFourBones.inc"
#include "SkinnedEffect_VSSkinnedOneLightOneBone.inc"
#include "SkinnedEffect_VSSkinnedOneLightTwoBones.inc"
#include "SkinnedEffect_VSSkinnedOneLightFourBones.inc"
#include "SkinnedEffect_VSSkinnedPixelLightingOneBone.inc"
#include "SkinnedEffect_VSSkinnedPixelLightingTwoBones.inc"
#include "SkinnedEffect_VSSkinnedPixelLightingFourBones.inc"
#include "SkinnedEffect_VSSkinnedVertexLightingOneBoneBn.inc"
#include "SkinnedEffect_VSSkinnedVertexLightingTwoBonesBn.inc"
#include "SkinnedEffect_VSSkinnedVertexLightingFourBonesBn.inc"
#include "SkinnedEffect_VSSkinnedOneLightOneBoneBn.inc"
#include "SkinnedEffect_VSSkinnedOneLightTwoBonesBn.inc"
#include "SkinnedEffect_VSSkinnedOneLightFourBonesBn.inc"
#include "SkinnedEffect_VSSkinnedPixelLightingOneBoneBn.inc"
#include "SkinnedEffect_VSSkinnedPixelLightingTwoBonesBn.inc"
#include "SkinnedEffect_VSSkinnedPixelLightingFourBonesBn.inc"
#include "SkinnedEffect_PSSkinnedVertexLighting.inc"
#include "SkinnedEffect_PSSkinnedVertexLightingNoFog.inc"
#include "SkinnedEffect_PSSkinnedPixelLighting.inc"
#endif
} // namespace
template<>
const ShaderBytecode EffectBase<SkinnedEffectTraits>::VertexShaderBytecode[] = {
{ SkinnedEffect_VSSkinnedVertexLightingOneBone, sizeof(SkinnedEffect_VSSkinnedVertexLightingOneBone) },
{ SkinnedEffect_VSSkinnedVertexLightingTwoBones, sizeof(SkinnedEffect_VSSkinnedVertexLightingTwoBones) },
{ SkinnedEffect_VSSkinnedVertexLightingFourBones, sizeof(SkinnedEffect_VSSkinnedVertexLightingFourBones) },
{ SkinnedEffect_VSSkinnedOneLightOneBone, sizeof(SkinnedEffect_VSSkinnedOneLightOneBone) },
{ SkinnedEffect_VSSkinnedOneLightTwoBones, sizeof(SkinnedEffect_VSSkinnedOneLightTwoBones) },
{ SkinnedEffect_VSSkinnedOneLightFourBones, sizeof(SkinnedEffect_VSSkinnedOneLightFourBones) },
{ SkinnedEffect_VSSkinnedPixelLightingOneBone, sizeof(SkinnedEffect_VSSkinnedPixelLightingOneBone) },
{ SkinnedEffect_VSSkinnedPixelLightingTwoBones, sizeof(SkinnedEffect_VSSkinnedPixelLightingTwoBones) },
{ SkinnedEffect_VSSkinnedPixelLightingFourBones, sizeof(SkinnedEffect_VSSkinnedPixelLightingFourBones) },
{ SkinnedEffect_VSSkinnedVertexLightingOneBoneBn, sizeof(SkinnedEffect_VSSkinnedVertexLightingOneBoneBn) },
{ SkinnedEffect_VSSkinnedVertexLightingTwoBonesBn, sizeof(SkinnedEffect_VSSkinnedVertexLightingTwoBonesBn) },
{ SkinnedEffect_VSSkinnedVertexLightingFourBonesBn, sizeof(SkinnedEffect_VSSkinnedVertexLightingFourBonesBn) },
{ SkinnedEffect_VSSkinnedOneLightOneBoneBn, sizeof(SkinnedEffect_VSSkinnedOneLightOneBoneBn) },
{ SkinnedEffect_VSSkinnedOneLightTwoBonesBn, sizeof(SkinnedEffect_VSSkinnedOneLightTwoBonesBn) },
{ SkinnedEffect_VSSkinnedOneLightFourBonesBn, sizeof(SkinnedEffect_VSSkinnedOneLightFourBonesBn) },
{ SkinnedEffect_VSSkinnedPixelLightingOneBoneBn, sizeof(SkinnedEffect_VSSkinnedPixelLightingOneBoneBn) },
{ SkinnedEffect_VSSkinnedPixelLightingTwoBonesBn, sizeof(SkinnedEffect_VSSkinnedPixelLightingTwoBonesBn) },
{ SkinnedEffect_VSSkinnedPixelLightingFourBonesBn, sizeof(SkinnedEffect_VSSkinnedPixelLightingFourBonesBn) },
};
template<>
const int EffectBase<SkinnedEffectTraits>::VertexShaderIndices[] = {
0, // vertex lighting, one bone
0, // vertex lighting, one bone, no fog
1, // vertex lighting, two bones
1, // vertex lighting, two bones, no fog
2, // vertex lighting, four bones
2, // vertex lighting, four bones, no fog
3, // one light, one bone
3, // one light, one bone, no fog
4, // one light, two bones
4, // one light, two bones, no fog
5, // one light, four bones
5, // one light, four bones, no fog
6, // pixel lighting, one bone
6, // pixel lighting, one bone, no fog
7, // pixel lighting, two bones
7, // pixel lighting, two bones, no fog
8, // pixel lighting, four bones
8, // pixel lighting, four bones, no fog
9, // vertex lighting (biased vertex normals), one bone
9, // vertex lighting (biased vertex normals), one bone, no fog
10, // vertex lighting (biased vertex normals), two bones
10, // vertex lighting (biased vertex normals), two bones, no fog
11, // vertex lighting (biased vertex normals), four bones
11, // vertex lighting (biased vertex normals), four bones, no fog
12, // one light (biased vertex normals), one bone
12, // one light (biased vertex normals), one bone, no fog
13, // one light (biased vertex normals), two bones
13, // one light (biased vertex normals), two bones, no fog
14, // one light (biased vertex normals), four bones
14, // one light (biased vertex normals), four bones, no fog
15, // pixel lighting (biased vertex normals), one bone
15, // pixel lighting (biased vertex normals), one bone, no fog
16, // pixel lighting (biased vertex normals), two bones
16, // pixel lighting (biased vertex normals), two bones, no fog
17, // pixel lighting (biased vertex normals), four bones
17, // pixel lighting (biased vertex normals), four bones, no fog
};
template<>
const ShaderBytecode EffectBase<SkinnedEffectTraits>::PixelShaderBytecode[] = {
{ SkinnedEffect_PSSkinnedVertexLighting, sizeof(SkinnedEffect_PSSkinnedVertexLighting) },
{ SkinnedEffect_PSSkinnedVertexLightingNoFog, sizeof(SkinnedEffect_PSSkinnedVertexLightingNoFog) },
{ SkinnedEffect_PSSkinnedPixelLighting, sizeof(SkinnedEffect_PSSkinnedPixelLighting) },
};
template<>
const int EffectBase<SkinnedEffectTraits>::PixelShaderIndices[] = {
0, // vertex lighting, one bone
1, // vertex lighting, one bone, no fog
0, // vertex lighting, two bones
1, // vertex lighting, two bones, no fog
0, // vertex lighting, four bones
1, // vertex lighting, four bones, no fog
0, // one light, one bone
1, // one light, one bone, no fog
0, // one light, two bones
1, // one light, two bones, no fog
0, // one light, four bones
1, // one light, four bones, no fog
2, // pixel lighting, one bone
2, // pixel lighting, one bone, no fog
2, // pixel lighting, two bones
2, // pixel lighting, two bones, no fog
2, // pixel lighting, four bones
2, // pixel lighting, four bones, no fog
0, // vertex lighting (biased vertex normals), one bone
1, // vertex lighting (biased vertex normals), one bone, no fog
0, // vertex lighting (biased vertex normals), two bones
1, // vertex lighting (biased vertex normals), two bones, no fog
0, // vertex lighting (biased vertex normals), four bones
1, // vertex lighting (biased vertex normals), four bones, no fog
0, // one light (biased vertex normals), one bone
1, // one light (biased vertex normals), one bone, no fog
0, // one light (biased vertex normals), two bones
1, // one light (biased vertex normals), two bones, no fog
0, // one light (biased vertex normals), four bones
1, // one light (biased vertex normals), four bones, no fog
2, // pixel lighting (biased vertex normals), one bone
2, // pixel lighting (biased vertex normals), one bone, no fog
2, // pixel lighting (biased vertex normals), two bones
2, // pixel lighting (biased vertex normals), two bones, no fog
2, // pixel lighting (biased vertex normals), four bones
2, // pixel lighting (biased vertex normals), four bones, no fog
};
#pragma endregion
// Global pool of per-device SkinnedEffect resources.
template<>
SharedResourcePool<ID3D11Device*, EffectBase<SkinnedEffectTraits>::DeviceResources> EffectBase<SkinnedEffectTraits>::deviceResourcesPool
= {};
// Constructor.
SkinnedEffect::Impl::Impl(_In_ ID3D11Device* device)
: EffectBase(device),
preferPerPixelLighting(false),
biasedVertexNormals(false),
weightsPerVertex(4)
{
static_assert(static_cast<int>(std::size(EffectBase<SkinnedEffectTraits>::VertexShaderIndices))
== SkinnedEffectTraits::ShaderPermutationCount,
"array/max mismatch");
static_assert(static_cast<int>(std::size(EffectBase<SkinnedEffectTraits>::VertexShaderBytecode))
== SkinnedEffectTraits::VertexShaderCount,
"array/max mismatch");
static_assert(static_cast<int>(std::size(EffectBase<SkinnedEffectTraits>::PixelShaderBytecode))
== SkinnedEffectTraits::PixelShaderCount,
"array/max mismatch");
static_assert(static_cast<int>(std::size(EffectBase<SkinnedEffectTraits>::PixelShaderIndices))
== SkinnedEffectTraits::ShaderPermutationCount,
"array/max mismatch");
lights.InitializeConstants(constants.specularColorAndPower,
constants.lightDirection,
constants.lightDiffuseColor,
constants.lightSpecularColor);
for (int i = 0; i < MaxBones; i++)
{
constants.bones[i][0] = g_XMIdentityR0;
constants.bones[i][1] = g_XMIdentityR1;
constants.bones[i][2] = g_XMIdentityR2;
}
}
int SkinnedEffect::Impl::GetCurrentShaderPermutation() const noexcept
{
int permutation = 0;
// Use optimized shaders if fog is disabled.
if (!fog.enabled)
{
permutation += 1;
}
// Evaluate 1, 2, or 4 weights per vertex?
if (weightsPerVertex == 2)
{
permutation += 2;
}
else if (weightsPerVertex == 4)
{
permutation += 4;
}
if (preferPerPixelLighting)
{
// Do lighting in the pixel shader.
permutation += 12;
}
else if (!lights.lightEnabled[1] && !lights.lightEnabled[2])
{
// Use the only-bother-with-the-first-light shader optimization.
permutation += 6;
}
if (biasedVertexNormals)
{
// Compressed normals need to be scaled and biased in the vertex shader.
permutation += 18;
}
return permutation;
}
// Sets our state onto the D3D device.
void SkinnedEffect::Impl::Apply(_In_ ID3D11DeviceContext* deviceContext)
{
assert(deviceContext != nullptr);
// Compute derived parameter values.
matrices.SetConstants(dirtyFlags, constants.worldViewProj);
fog.SetConstants(dirtyFlags, matrices.worldView, constants.fogVector);
lights.SetConstants(dirtyFlags,
matrices,
constants.world,
constants.worldInverseTranspose,
constants.eyePosition,
constants.diffuseColor,
constants.emissiveColor,
true);
// Set the texture.
ID3D11ShaderResourceView* textures[1] = { (texture) ? texture.Get() : GetDefaultTexture() };
deviceContext->PSSetShaderResources(0, 1, textures);
// Set shaders and constant buffers.
ApplyShaders(deviceContext, GetCurrentShaderPermutation());
}
// Public constructor.
SkinnedEffect::SkinnedEffect(_In_ ID3D11Device* device)
: pImpl(std::make_unique<Impl>(device))
{}
SkinnedEffect::SkinnedEffect(SkinnedEffect&&) noexcept = default;
SkinnedEffect& SkinnedEffect::operator=(SkinnedEffect&&) noexcept = default;
SkinnedEffect::~SkinnedEffect() = default;
// IEffect methods.
void SkinnedEffect::Apply(_In_ ID3D11DeviceContext* deviceContext)
{
pImpl->Apply(deviceContext);
}
void SkinnedEffect::GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength)
{
pImpl->GetVertexShaderBytecode(pImpl->GetCurrentShaderPermutation(), pShaderByteCode, pByteCodeLength);
}
// Camera settings.
void XM_CALLCONV SkinnedEffect::SetWorld(FXMMATRIX value)
{
pImpl->matrices.world = value;
pImpl->dirtyFlags |= EffectDirtyFlags::WorldViewProj | EffectDirtyFlags::WorldInverseTranspose | EffectDirtyFlags::FogVector;
}
void XM_CALLCONV SkinnedEffect::SetView(FXMMATRIX value)
{
pImpl->matrices.view = value;
pImpl->dirtyFlags |= EffectDirtyFlags::WorldViewProj | EffectDirtyFlags::EyePosition | EffectDirtyFlags::FogVector;
}
void XM_CALLCONV SkinnedEffect::SetProjection(FXMMATRIX value)
{
pImpl->matrices.projection = value;
pImpl->dirtyFlags |= EffectDirtyFlags::WorldViewProj;
}
void XM_CALLCONV SkinnedEffect::SetMatrices(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection)
{
pImpl->matrices.world = world;
pImpl->matrices.view = view;
pImpl->matrices.projection = projection;
pImpl->dirtyFlags |= EffectDirtyFlags::WorldViewProj | EffectDirtyFlags::WorldInverseTranspose | EffectDirtyFlags::EyePosition
| EffectDirtyFlags::FogVector;
}
// Material settings.
void XM_CALLCONV SkinnedEffect::SetDiffuseColor(FXMVECTOR value)
{
pImpl->lights.diffuseColor = value;
pImpl->dirtyFlags |= EffectDirtyFlags::MaterialColor;
}
void XM_CALLCONV SkinnedEffect::SetEmissiveColor(FXMVECTOR value)
{
pImpl->lights.emissiveColor = value;
pImpl->dirtyFlags |= EffectDirtyFlags::MaterialColor;
}
void XM_CALLCONV SkinnedEffect::SetSpecularColor(FXMVECTOR value)
{
// Set xyz to new value, but preserve existing w (specular power).
pImpl->constants.specularColorAndPower = XMVectorSelect(pImpl->constants.specularColorAndPower, value, g_XMSelect1110);
pImpl->dirtyFlags |= EffectDirtyFlags::ConstantBuffer;
}
void SkinnedEffect::SetSpecularPower(float value)
{
// Set w to new value, but preserve existing xyz (specular color).
pImpl->constants.specularColorAndPower = XMVectorSetW(pImpl->constants.specularColorAndPower, value);
pImpl->dirtyFlags |= EffectDirtyFlags::ConstantBuffer;
}
void SkinnedEffect::DisableSpecular()
{
// Set specular color to black, power to 1
// Note: Don't use a power of 0 or the shader will generate strange highlights on non-specular materials
pImpl->constants.specularColorAndPower = g_XMIdentityR3;
pImpl->dirtyFlags |= EffectDirtyFlags::ConstantBuffer;
}
void SkinnedEffect::SetAlpha(float value)
{
pImpl->lights.alpha = value;
pImpl->dirtyFlags |= EffectDirtyFlags::MaterialColor;
}
void XM_CALLCONV SkinnedEffect::SetColorAndAlpha(FXMVECTOR value)
{
pImpl->lights.diffuseColor = value;
pImpl->lights.alpha = XMVectorGetW(value);
pImpl->dirtyFlags |= EffectDirtyFlags::MaterialColor;
}
// Light settings.
void SkinnedEffect::SetLightingEnabled(bool value)
{
if (!value)
{
throw std::invalid_argument("SkinnedEffect does not support turning off lighting");
}
}
void SkinnedEffect::SetPerPixelLighting(bool value)
{
pImpl->preferPerPixelLighting = value;
}
void XM_CALLCONV SkinnedEffect::SetAmbientLightColor(FXMVECTOR value)
{
pImpl->lights.ambientLightColor = value;
pImpl->dirtyFlags |= EffectDirtyFlags::MaterialColor;
}
void SkinnedEffect::SetLightEnabled(int whichLight, bool value)
{
pImpl->dirtyFlags
|= pImpl->lights.SetLightEnabled(whichLight, value, pImpl->constants.lightDiffuseColor, pImpl->constants.lightSpecularColor);
}
void XM_CALLCONV SkinnedEffect::SetLightDirection(int whichLight, FXMVECTOR value)
{
EffectLights::ValidateLightIndex(whichLight);
pImpl->constants.lightDirection[whichLight] = value;
pImpl->dirtyFlags |= EffectDirtyFlags::ConstantBuffer;
}
void XM_CALLCONV SkinnedEffect::SetLightDiffuseColor(int whichLight, FXMVECTOR value)
{
pImpl->dirtyFlags |= pImpl->lights.SetLightDiffuseColor(whichLight, value, pImpl->constants.lightDiffuseColor);
}
void XM_CALLCONV SkinnedEffect::SetLightSpecularColor(int whichLight, FXMVECTOR value)
{
pImpl->dirtyFlags |= pImpl->lights.SetLightSpecularColor(whichLight, value, pImpl->constants.lightSpecularColor);
}
void SkinnedEffect::EnableDefaultLighting()
{
EffectLights::EnableDefaultLighting(this);
}
// Fog settings.
void SkinnedEffect::SetFogEnabled(bool value)
{
pImpl->fog.enabled = value;
pImpl->dirtyFlags |= EffectDirtyFlags::FogEnable;
}
void SkinnedEffect::SetFogStart(float value)
{
pImpl->fog.start = value;
pImpl->dirtyFlags |= EffectDirtyFlags::FogVector;
}
void SkinnedEffect::SetFogEnd(float value)
{
pImpl->fog.end = value;
pImpl->dirtyFlags |= EffectDirtyFlags::FogVector;
}
void XM_CALLCONV SkinnedEffect::SetFogColor(FXMVECTOR value)
{
pImpl->constants.fogColor = value;
pImpl->dirtyFlags |= EffectDirtyFlags::ConstantBuffer;
}
// Texture settings.
void SkinnedEffect::SetTexture(_In_opt_ ID3D11ShaderResourceView* value)
{
pImpl->texture = value;
}
// Animation settings.
void SkinnedEffect::SetWeightsPerVertex(int value)
{
if ((value != 1) && (value != 2) && (value != 4))
{
throw std::invalid_argument("WeightsPerVertex must be 1, 2, or 4");
}
pImpl->weightsPerVertex = value;
}
void SkinnedEffect::SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count)
{
if (count > MaxBones)
throw std::invalid_argument("count parameter exceeds MaxBones");
auto boneConstant = pImpl->constants.bones;
for (size_t i = 0; i < count; i++)
{
#if DIRECTX_MATH_VERSION >= 313
XMStoreFloat3x4A(reinterpret_cast<XMFLOAT3X4A*>(&boneConstant[i]), value[i]);
#else
// Xbox One XDK has an older version of DirectXMath
XMMATRIX boneMatrix = XMMatrixTranspose(value[i]);
boneConstant[i][0] = boneMatrix.r[0];
boneConstant[i][1] = boneMatrix.r[1];
boneConstant[i][2] = boneMatrix.r[2];
#endif
}
pImpl->dirtyFlags |= EffectDirtyFlags::ConstantBuffer;
}
void SkinnedEffect::ResetBoneTransforms()
{
auto boneConstant = pImpl->constants.bones;
for (size_t i = 0; i < MaxBones; ++i)
{
boneConstant[i][0] = g_XMIdentityR0;
boneConstant[i][1] = g_XMIdentityR1;
boneConstant[i][2] = g_XMIdentityR2;
}
pImpl->dirtyFlags |= EffectDirtyFlags::ConstantBuffer;
}
// Normal compression settings.
void SkinnedEffect::SetBiasedVertexNormals(bool value)
{
pImpl->biasedVertexNormals = value;
}