Khaotic Engine Reborn
Loading...
Searching...
No Matches
shader_manager_class.cpp
1#include "shader_manager_class.h"
2
3shader_manager_class::shader_manager_class()
4{
5 texture_shader_ = 0;
6 normal_map_shader_ = 0;
7 multitexture_shader_ = 0;
8 translate_shader_ = 0;
9 alpha_map_shader_ = 0;
10 spec_map_shader_ = 0;
11 transparent_shader_ = 0;
12 light_shader_ = 0;
13 light_map_shader_ = 0;
14 refraction_shader_ = 0;
15 water_shader_ = 0;
16 cel_shading_shader_ = 0;
17 sunlight_shader_ = 0;
18 skybox_shader_ = 0;
19 refraction_shader_ = 0;
20 depth_shader_ = 0;
21}
22
23shader_manager_class::shader_manager_class(const shader_manager_class& other)
24{
25}
26
27shader_manager_class::~shader_manager_class()
28{
29}
30
31bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
32{
33 Logger::Get().Log("Initializing shader_manager_class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
34
35 bool result;
36
37 // Create and initialize the texture shader object.
38 texture_shader_ = new texture_shader_class;
39 result = texture_shader_->initialize(device, hwnd);
40 if (!result)
41 {
42 Logger::Get().Log("Error initializing texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
43 return false;
44 }
45
46 // Create and initialize the normal map shader object.
47 normal_map_shader_ = new normal_map_shader_class;
48 result = normal_map_shader_->initialize(device, hwnd);
49 if (!result)
50 {
51 Logger::Get().Log("Error initializing normal_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
52 return false;
53 }
54
55 // Create and initialize the multitexture shader object.
56 multitexture_shader_ = new multi_texture_shader_class;
57 result = multitexture_shader_->initialize(device, hwnd);
58 if (!result)
59 {
60 Logger::Get().Log("Error initializing multi_texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
61 return false;
62 }
63
64 // Create and initialize the translate shader object.
65 translate_shader_ = new translate_shader_class;
66 result = translate_shader_->initialize(device, hwnd);
67 if (!result)
68 {
69 Logger::Get().Log("Error initializing translate_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
70 return false;
71 }
72
73 // Create and initialize the alpha map shader object.
74 alpha_map_shader_ = new alpha_map_shader_class;
75 result = alpha_map_shader_->initialize(device, hwnd);
76 if (!result)
77 {
78 Logger::Get().Log("Error initializing alpha_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
79 return false;
80 }
81
82 // Create and initialize the specular map shader object.
83 spec_map_shader_ = new spec_map_shader_class;
84 result = spec_map_shader_->initialize(device, hwnd);
85 if (!result)
86 {
87 Logger::Get().Log("Error initializing spec_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
88 return false;
89 }
90
91 // Create and initialize the transparent shader object.
92 transparent_shader_ = new transparent_shader_class;
93 result = transparent_shader_->initialize(device, hwnd);
94 if (!result)
95 {
96 Logger::Get().Log("Error initializing transparent_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
97 return false;
98 }
99
100 // Create and initialize the light shader object.
101 light_shader_ = new light_shader_class;
102 result = light_shader_->initialize(device, hwnd);
103 if (!result)
104 {
105 Logger::Get().Log("Error initializing light_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
106 return false;
107 }
108
109 // Create and initialize the light map shader object.
110 light_map_shader_ = new light_map_shader_class;
111 result = light_map_shader_->initialize(device, hwnd);
112 if (!result)
113 {
114 Logger::Get().Log("Error initializing light_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
115 return false;
116 }
117
118 // Create and initialize the refraction shader object.
119 refraction_shader_ = new refraction_shader_class;
120 result = refraction_shader_->initialize(device, hwnd);
121 if (!result)
122 {
123 return false;
124 }
125
126 // Create and initialize the water shader object.
127 water_shader_ = new water_shader_class;
128 result = water_shader_->initialize(device, hwnd);
129 if (!result)
130 {
131 return false;
132 }
133
134 cel_shading_shader_ = new celshade_class;
135 result = cel_shading_shader_->initialize(device, hwnd);
136 if (!result)
137 {
138 return false;
139 }
140
141 sunlight_shader_ = new sunlight_shader_class;
142 result = sunlight_shader_->initialize(device, hwnd);
143 if (!result)
144 {
145 return false;
146 }
147
148 skybox_shader_ = new skybox_shader_class;
149 result = skybox_shader_->Initialize(device, hwnd);
150 if (!result)
151 {
152 Logger::Get().Log("Error initializing skybox_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
153 return false;
154 }
155
156 depth_shader_ = new depth_shader_class;
157 result = depth_shader_->initialize(device, hwnd);
158 if (!result)
159 {
160 Logger::Get().Log("Error initializing depth_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
161 return false;
162 }
163
164 Logger::Get().Log("shader_manager_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
165
166 return true;
167}
168
169void shader_manager_class::shutdown()
170{
171 Logger::Get().Log("Shutting down shader_manager_class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
172
173 // Release the normal map shader object.
174 if (normal_map_shader_)
175 {
176 normal_map_shader_->shutdown();
177 delete normal_map_shader_;
178 normal_map_shader_ = 0;
179 }
180
181 // Release the texture shader object.
182 if (texture_shader_)
183 {
184 texture_shader_->shutdown();
185 delete texture_shader_;
186 texture_shader_ = 0;
187 }
188
189 // Release the multitexture shader object.
190 if (multitexture_shader_)
191 {
192 multitexture_shader_->shutdown();
193 delete multitexture_shader_;
194 multitexture_shader_ = 0;
195 }
196
197 // Release the translate shader object.
198 if (translate_shader_)
199 {
200 translate_shader_->shutdown();
201 delete translate_shader_;
202 translate_shader_ = 0;
203 }
204
205 // Release the alpha map shader object.
206 if (alpha_map_shader_)
207 {
208 alpha_map_shader_->shutdown();
209 delete alpha_map_shader_;
210 alpha_map_shader_ = 0;
211 }
212
213 // Release the specular map shader object.
214 if (spec_map_shader_)
215 {
216 spec_map_shader_->shutdown();
217 delete spec_map_shader_;
218 spec_map_shader_ = 0;
219 }
220
221 // Release the transparent shader object.
222 if (transparent_shader_)
223 {
224 transparent_shader_->shutdown();
225 delete transparent_shader_;
226 transparent_shader_ = 0;
227 }
228
229 // Release the light shader object.
230 if (light_shader_)
231 {
232 light_shader_->shutdown();
233 delete light_shader_;
234 light_shader_ = 0;
235 }
236
237 // Release the light map shader object.
238 if (light_map_shader_)
239 {
240 light_map_shader_->shutdown();
241 delete light_map_shader_;
242 light_map_shader_ = 0;
243 }
244
245 // Release the refraction shader object.
246 if (refraction_shader_)
247 {
248 refraction_shader_->shutdown();
249 delete refraction_shader_;
250 refraction_shader_ = 0;
251 }
252
253 // Release the water shader object.
254 if (water_shader_)
255 {
256 water_shader_->shutdown();
257 delete water_shader_;
258 water_shader_ = 0;
259 }
260
261 // Release the cel shading shader object.
262 if (cel_shading_shader_)
263 {
264 cel_shading_shader_->shutdown();
265 delete cel_shading_shader_;
266 cel_shading_shader_ = 0;
267 }
268
269 if (sunlight_shader_)
270 {
271 sunlight_shader_->shutdown();
272 delete sunlight_shader_;
273 sunlight_shader_ = 0;
274 }
275
276 if (skybox_shader_)
277 {
278 skybox_shader_->Shutdown();
279 delete skybox_shader_;
280 skybox_shader_ = 0;
281 }
282
283 if (depth_shader_)
284 {
285 depth_shader_->shutdown();
286 delete depth_shader_;
287 depth_shader_ = 0;
288 }
289
290 Logger::Get().Log("shader_manager_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
291}
292
293bool shader_manager_class::render_texture_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
294 ID3D11ShaderResourceView* texture)
295{
296 bool result;
297
298 result = texture_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture);
299 if (!result)
300 {
301 Logger::Get().Log("Error rendering texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
302 return false;
303 }
304
305 return true;
306}
307
308bool shader_manager_class::render_normal_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
309 ID3D11ShaderResourceView* colorTexture, ID3D11ShaderResourceView* normalTexture, XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor)
310{
311 bool result;
312
313 result = normal_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, colorTexture, normalTexture, lightDirection, diffuseColor);
314 if (!result)
315 {
316 Logger::Get().Log("Error rendering normal_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
317 return false;
318 }
319
320 return true;
321}
322
323bool shader_manager_class::render_multitexture_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
324 ID3D11ShaderResourceView* texture1, ID3D11ShaderResourceView* texture2)
325{
326 bool result;
327
328 result = multitexture_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
329 if (!result)
330 {
331 Logger::Get().Log("Error rendering multi_texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
332 return false;
333 }
334
335 return true;
336}
337
338bool shader_manager_class::render_translate_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
339 ID3D11ShaderResourceView* texture1, float valeur)
340{
341 bool result;
342
343 result = translate_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, valeur);
344 if (!result)
345 {
346 Logger::Get().Log("Error rendering translate_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
347 return false;
348 }
349
350 return true;
351}
352
353bool shader_manager_class::render_alpha_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
354 ID3D11ShaderResourceView* texture1, ID3D11ShaderResourceView* texture2, ID3D11ShaderResourceView* texture3)
355{
356 bool result;
357
358 result = alpha_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3);
359 if (!result)
360 {
361 Logger::Get().Log("Error rendering alpha_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
362 return false;
363 }
364
365 return true;
366}
367
368bool shader_manager_class::render_spec_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
369 ID3D11ShaderResourceView* texture1, ID3D11ShaderResourceView* texture2, ID3D11ShaderResourceView* texture3,
370 XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor, XMFLOAT3 cameraPosition, XMFLOAT4 specularColor, float specularPower)
371{
372 bool result;
373
374 result = spec_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3, lightDirection,
375 diffuseColor, cameraPosition, specularColor, specularPower);
376 if (!result)
377 {
378 Logger::Get().Log("Error rendering spec_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
379 return false;
380 }
381
382 return true;
383}
384
385bool shader_manager_class::render_transparent_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
386 ID3D11ShaderResourceView* texture1, float blendAmount)
387{
388 bool result;
389
390 result = transparent_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, blendAmount);
391 if (!result)
392 {
393 Logger::Get().Log("Error rendering transparent_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
394 return false;
395 }
396
397 return true;
398}
399
400bool shader_manager_class::renderlight_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
401 ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 ambientColor[])
402{
403 bool result;
404
405 result = light_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition, ambientColor);
406 if (!result)
407 {
408 return false;
409 }
410
411 return true;
412}
413
414bool shader_manager_class::renderlight_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
415 XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture1, ID3D11ShaderResourceView* texture2)
416{
417 bool result;
418
419 result = light_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
420 if (!result)
421 {
422 return false;
423 }
424
425 return true;
426}
427
428bool shader_manager_class::render_refraction_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
429 ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 ambientColor[], XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 clipPlane)
430{
431 bool result;
432
433 result = refraction_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, lightPosition, clipPlane);
434 if (!result)
435 {
436 return false;
437 }
438
439 return true;
440}
441
442bool shader_manager_class::render_water_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
443 XMMATRIX reflectionMatrix, ID3D11ShaderResourceView* reflectionTexture, ID3D11ShaderResourceView* refractionTexture,
444 ID3D11ShaderResourceView* normalTexture, float waterTranslation, float reflectRefractScale)
445{
446 bool result;
447
448 result = water_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix, reflectionTexture,
449 refractionTexture, normalTexture, waterTranslation, reflectRefractScale);
450 if (!result)
451 {
452 return false;
453 }
454
455 return true;
456}
457
458bool shader_manager_class::render_cel_shading_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
459 ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection, float sunIntensity)
460{
461 bool result;
462
463 result = cel_shading_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
464 if (!result)
465 {
466 return false;
467 }
468
469 return true;
470}
471
472bool shader_manager_class::render_sunlight_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
473 ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection, float sunIntensity)
474{
475 bool result;
476
477 result = sunlight_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
478 if (!result)
479 {
480 return false;
481 }
482
483 return true;
484}
485
486bool shader_manager_class::render_skybox_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
487 ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection, float sunIntensity)
488{
489 bool result;
490
491 result = skybox_shader_->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
492 if (!result)
493 {
494 return false;
495 }
496
497 return true;
498}
499
500bool shader_manager_class::render_depth_shader(
501 ID3D11DeviceContext* context,
502 int indexCount,
503 XMMATRIX worldMatrix,
504 XMMATRIX viewMatrix,
505 XMMATRIX projectionMatrix,
506 ID3D11ShaderResourceView* texture
507)
508{
509 bool result;
510
511 result = depth_shader_->render(context, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture);
512 if (!result)
513 {
514 return false;
515 }
516
517 return true;
518}
static Logger & Get()
Definition Logger.h:20
void Log(const std::string &message, const std::string &fileName, int lineNumber, LogLevel level=LogLevel::Info)
Definition Logger.h:158