1#include "shader_manager_class.h"
3shader_manager_class::shader_manager_class()
6 normal_map_shader_ = 0;
7 multitexture_shader_ = 0;
11 transparent_shader_ = 0;
13 light_map_shader_ = 0;
14 refraction_shader_ = 0;
16 cel_shading_shader_ = 0;
19 refraction_shader_ = 0;
27shader_manager_class::~shader_manager_class()
31bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
33 Logger::Get().
Log(
"Initializing shader_manager_class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
39 result = texture_shader_->initialize(device, hwnd);
42 Logger::Get().
Log(
"Error initializing texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
48 result = normal_map_shader_->initialize(device, hwnd);
51 Logger::Get().
Log(
"Error initializing normal_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
57 result = multitexture_shader_->initialize(device, hwnd);
60 Logger::Get().
Log(
"Error initializing multi_texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
66 result = translate_shader_->initialize(device, hwnd);
69 Logger::Get().
Log(
"Error initializing translate_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
75 result = alpha_map_shader_->initialize(device, hwnd);
78 Logger::Get().
Log(
"Error initializing alpha_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
84 result = spec_map_shader_->initialize(device, hwnd);
87 Logger::Get().
Log(
"Error initializing spec_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
93 result = transparent_shader_->initialize(device, hwnd);
96 Logger::Get().
Log(
"Error initializing transparent_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
102 result = light_shader_->initialize(device, hwnd);
105 Logger::Get().
Log(
"Error initializing light_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
111 result = light_map_shader_->initialize(device, hwnd);
114 Logger::Get().
Log(
"Error initializing light_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
120 result = refraction_shader_->initialize(device, hwnd);
128 result = water_shader_->initialize(device, hwnd);
135 result = cel_shading_shader_->initialize(device, hwnd);
142 result = sunlight_shader_->initialize(device, hwnd);
149 result = skybox_shader_->Initialize(device, hwnd);
152 Logger::Get().
Log(
"Error initializing skybox_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
157 result = depth_shader_->initialize(device, hwnd);
160 Logger::Get().
Log(
"Error initializing depth_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
164 Logger::Get().
Log(
"shader_manager_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
169void shader_manager_class::shutdown()
171 Logger::Get().
Log(
"Shutting down shader_manager_class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
174 if (normal_map_shader_)
176 normal_map_shader_->shutdown();
177 delete normal_map_shader_;
178 normal_map_shader_ = 0;
184 texture_shader_->shutdown();
185 delete texture_shader_;
190 if (multitexture_shader_)
192 multitexture_shader_->shutdown();
193 delete multitexture_shader_;
194 multitexture_shader_ = 0;
198 if (translate_shader_)
200 translate_shader_->shutdown();
201 delete translate_shader_;
202 translate_shader_ = 0;
206 if (alpha_map_shader_)
208 alpha_map_shader_->shutdown();
209 delete alpha_map_shader_;
210 alpha_map_shader_ = 0;
214 if (spec_map_shader_)
216 spec_map_shader_->shutdown();
217 delete spec_map_shader_;
218 spec_map_shader_ = 0;
222 if (transparent_shader_)
224 transparent_shader_->shutdown();
225 delete transparent_shader_;
226 transparent_shader_ = 0;
232 light_shader_->shutdown();
233 delete light_shader_;
238 if (light_map_shader_)
240 light_map_shader_->shutdown();
241 delete light_map_shader_;
242 light_map_shader_ = 0;
246 if (refraction_shader_)
248 refraction_shader_->shutdown();
249 delete refraction_shader_;
250 refraction_shader_ = 0;
256 water_shader_->shutdown();
257 delete water_shader_;
262 if (cel_shading_shader_)
264 cel_shading_shader_->shutdown();
265 delete cel_shading_shader_;
266 cel_shading_shader_ = 0;
269 if (sunlight_shader_)
271 sunlight_shader_->shutdown();
272 delete sunlight_shader_;
273 sunlight_shader_ = 0;
278 skybox_shader_->Shutdown();
279 delete skybox_shader_;
285 depth_shader_->shutdown();
286 delete depth_shader_;
290 Logger::Get().
Log(
"shader_manager_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
293bool shader_manager_class::render_texture_shader(ID3D11DeviceContext* deviceContext,
int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
294 ID3D11ShaderResourceView* texture)
298 result = texture_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture);
301 Logger::Get().
Log(
"Error rendering texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
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)
313 result = normal_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, colorTexture, normalTexture, lightDirection, diffuseColor);
316 Logger::Get().
Log(
"Error rendering normal_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
323bool shader_manager_class::render_multitexture_shader(ID3D11DeviceContext* deviceContext,
int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
324 ID3D11ShaderResourceView* texture1, ID3D11ShaderResourceView* texture2)
328 result = multitexture_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
331 Logger::Get().
Log(
"Error rendering multi_texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
338bool shader_manager_class::render_translate_shader(ID3D11DeviceContext* deviceContext,
int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
339 ID3D11ShaderResourceView* texture1,
float valeur)
343 result = translate_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, valeur);
346 Logger::Get().
Log(
"Error rendering translate_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
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)
358 result = alpha_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3);
361 Logger::Get().
Log(
"Error rendering alpha_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
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)
374 result = spec_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3, lightDirection,
375 diffuseColor, cameraPosition, specularColor, specularPower);
378 Logger::Get().
Log(
"Error rendering spec_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
385bool shader_manager_class::render_transparent_shader(ID3D11DeviceContext* deviceContext,
int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
386 ID3D11ShaderResourceView* texture1,
float blendAmount)
390 result = transparent_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, blendAmount);
393 Logger::Get().
Log(
"Error rendering transparent_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
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[])
405 result = light_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition, ambientColor);
414bool shader_manager_class::renderlight_map_shader(ID3D11DeviceContext* deviceContext,
int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
415 XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture1, ID3D11ShaderResourceView* texture2)
419 result = light_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
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)
433 result = refraction_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, lightPosition, clipPlane);
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)
448 result = water_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix, reflectionTexture,
449 refractionTexture, normalTexture, waterTranslation, reflectRefractScale);
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)
463 result = cel_shading_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
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)
477 result = sunlight_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
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)
491 result = skybox_shader_->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
500bool shader_manager_class::render_depth_shader(
501 ID3D11DeviceContext* context,
503 XMMATRIX worldMatrix,
505 XMMATRIX projectionMatrix,
506 ID3D11ShaderResourceView* texture
511 result = depth_shader_->render(context, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture);
void Log(const std::string &message, const std::string &fileName, int lineNumber, LogLevel level=LogLevel::Info)