-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLightShaderClass.cpp
182 lines (131 loc) · 4.14 KB
/
LightShaderClass.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
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
#include "LightShaderClass.hpp"
LightShaderClass::LightShaderClass()
{
this->VertexShader = nullptr;
this->PixelShader = nullptr;
this->BackBufferRTV = nullptr;
}
LightShaderClass::~LightShaderClass()
{
}
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// //
// PUBLIC FUNCTIONS //
// //
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ID3D11RenderTargetView* *LightShaderClass::GetBackBufferRTV()
{
return &this->BackBufferRTV;
}
void LightShaderClass::InitializeAll(ID3D11Device* *Device)
{
this->InitializeShaders(Device);
this->InitializeSampler(Device);
}
void LightShaderClass::Render(
ID3D11DeviceContext* *DeviceContext
)
{
// Set inputlayout and vertexbuffers to null so that we can use vertexId to generate the quad
// in the vertexshader.
(*DeviceContext)->IASetInputLayout(nullptr);
(*DeviceContext)->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); // SUPER IMPORTANT!
(*DeviceContext)->IASetVertexBuffers(
0,
0,
nullptr,
nullptr,
nullptr
);
(*DeviceContext)->Draw(4, 0);
}
void LightShaderClass::SetRenderTargets(
ID3D11DeviceContext* *DeviceContext,
ID3D11RenderTargetView* *BackBufferRTV,
ID3D11DepthStencilView* *DepthStencilView
)
{
(*DeviceContext)->OMSetRenderTargets(
1,
BackBufferRTV,
*DepthStencilView
);
}
void LightShaderClass::SetPipeline(
ID3D11DeviceContext* *DeviceContext
)
{
// Set Shaders
(*DeviceContext)->VSSetShader(this->VertexShader, nullptr, 0);
(*DeviceContext)->HSSetShader(nullptr, nullptr, 0);
(*DeviceContext)->DSSetShader(nullptr, nullptr, 0);
(*DeviceContext)->GSSetShader(nullptr, nullptr, 0);
(*DeviceContext)->PSSetShader(this->PixelShader, nullptr, 0);
// Set Sampler
(*DeviceContext)->PSSetSamplers(0, 1, &this->SamplerStateCLAMP);
}
void LightShaderClass::ReleaseAll()
{
this->VertexShader->Release();
this->PixelShader->Release();
this->SamplerStateCLAMP->Release();
}
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// //
// PRIVATE FUNCTIONS //
// //
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
void LightShaderClass::InitializeShaders(ID3D11Device* *Device)
{
HRESULT hr;
//C R E A T E V E R T E X S H A D E R
ID3DBlob* pVS = nullptr;
D3DCompileFromFile(
L"Light_Vertex.hlsl",
nullptr,
nullptr,
"LIGHT_VS_main",
"vs_5_0",
0,
0,
&pVS,
nullptr
);
(*Device)->CreateVertexShader(pVS->GetBufferPointer(), pVS->GetBufferSize(), nullptr, &this->VertexShader);
// we do not need anymore this COM object, so we release it.
pVS->Release();
//----------------------------------------------------------------------------------------------------------------------------------
//C R E A T E P I X E L S H A D E R
ID3DBlob* pPS = nullptr;
D3DCompileFromFile(
L"Light_Pixel.hlsl",
nullptr,
nullptr,
"LIGHT_PS_main",
"ps_5_0",
0,
0,
&pPS,
nullptr
);
hr = (*Device)->CreatePixelShader(pPS->GetBufferPointer(), pPS->GetBufferSize(), nullptr, &this->PixelShader);
if (FAILED(hr))
MessageBox(NULL, L"Failed to create 'Pixel Shader'.", L"ERROR: 'CreateShaders()'", MB_OK);
// we do not need anymore this COM object, so we release it.
pPS->Release();
}
void LightShaderClass::InitializeSampler(ID3D11Device* *Device)
{
D3D11_SAMPLER_DESC SamplerState_Description;
SamplerState_Description.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
SamplerState_Description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
SamplerState_Description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
SamplerState_Description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
SamplerState_Description.MipLODBias = 0.0f;
SamplerState_Description.MaxAnisotropy = 1.0f;
SamplerState_Description.ComparisonFunc = D3D11_COMPARISON_NEVER;
SamplerState_Description.BorderColor[4] = (1.0f, 1.0f, 1.0f, 1.0f);
SamplerState_Description.MinLOD = -3.402823466e+38F;
SamplerState_Description.MaxLOD = 3.402823466e+38F;
(*Device)->CreateSamplerState(&SamplerState_Description, &this->SamplerStateCLAMP);
}