-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEffects.cpp
94 lines (76 loc) · 3.27 KB
/
Effects.cpp
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
//***************************************************************************************
// Effects.cpp by Frank Luna (C) 2011 All Rights Reserved.
//***************************************************************************************
#include "Effects.h"
#pragma region Effect
Effect::Effect(ID3D11Device* device, const std::wstring& filename)
: mFX(0)
{
std::ifstream fin(filename, std::ios::binary);
fin.seekg(0, std::ios_base::end);
int size = (int)fin.tellg();
fin.seekg(0, std::ios_base::beg);
std::vector<char> compiledShader(size);
fin.read(&compiledShader[0], size);
fin.close();
HR(D3DX11CreateEffectFromMemory(&compiledShader[0], size,
0, device, &mFX));
}
Effect::~Effect()
{
ReleaseCOM(mFX);
}
#pragma endregion
#pragma region BasicEffect
BasicEffect::BasicEffect(ID3D11Device* device, const std::wstring& filename)
: Effect(device, filename)
{
Light1Tech = mFX->GetTechniqueByName("Light1");
Light2Tech = mFX->GetTechniqueByName("Light2");
Light3Tech = mFX->GetTechniqueByName("Light3");
Light0TexTech = mFX->GetTechniqueByName("Light0Tex");
Light1TexTech = mFX->GetTechniqueByName("Light1Tex");
Light2TexTech = mFX->GetTechniqueByName("Light2Tex");
Light3TexTech = mFX->GetTechniqueByName("Light3Tex");
Light0TexAlphaClipTech = mFX->GetTechniqueByName("Light0TexAlphaClip");
Light1TexAlphaClipTech = mFX->GetTechniqueByName("Light1TexAlphaClip");
Light2TexAlphaClipTech = mFX->GetTechniqueByName("Light2TexAlphaClip");
Light3TexAlphaClipTech = mFX->GetTechniqueByName("Light3TexAlphaClip");
Light1FogTech = mFX->GetTechniqueByName("Light1Fog");
Light2FogTech = mFX->GetTechniqueByName("Light2Fog");
Light3FogTech = mFX->GetTechniqueByName("Light3Fog");
Light0TexFogTech = mFX->GetTechniqueByName("Light0TexFog");
Light1TexFogTech = mFX->GetTechniqueByName("Light1TexFog");
Light2TexFogTech = mFX->GetTechniqueByName("Light2TexFog");
Light3TexFogTech = mFX->GetTechniqueByName("Light3TexFog");
Light0TexAlphaClipFogTech = mFX->GetTechniqueByName("Light0TexAlphaClipFog");
Light1TexAlphaClipFogTech = mFX->GetTechniqueByName("Light1TexAlphaClipFog");
Light2TexAlphaClipFogTech = mFX->GetTechniqueByName("Light2TexAlphaClipFog");
Light3TexAlphaClipFogTech = mFX->GetTechniqueByName("Light3TexAlphaClipFog");
WorldViewProj = mFX->GetVariableByName("gWorldViewProj")->AsMatrix();
World = mFX->GetVariableByName("gWorld")->AsMatrix();
WorldInvTranspose = mFX->GetVariableByName("gWorldInvTranspose")->AsMatrix();
TexTransform = mFX->GetVariableByName("gTexTransform")->AsMatrix();
EyePosW = mFX->GetVariableByName("gEyePosW")->AsVector();
FogColor = mFX->GetVariableByName("gFogColor")->AsVector();
FogStart = mFX->GetVariableByName("gFogStart")->AsScalar();
FogRange = mFX->GetVariableByName("gFogRange")->AsScalar();
DirLights = mFX->GetVariableByName("gDirLights");
Mat = mFX->GetVariableByName("gMaterial");
DiffuseMap = mFX->GetVariableByName("gDiffuseMap")->AsShaderResource();
}
BasicEffect::~BasicEffect()
{
}
#pragma endregion
#pragma region Effects
BasicEffect* Effects::BasicFX = 0;
void Effects::InitAll(ID3D11Device* device)
{
BasicFX = new BasicEffect(device, L"FX/Basic.fxo");
}
void Effects::DestroyAll()
{
SafeDelete(BasicFX);
}
#pragma endregion