Major - ECS - V12.0.0
This commit is contained in:
222
enginecustom/src/inc/system/ecs/systems/render_system.h
Normal file
222
enginecustom/src/inc/system/ecs/systems/render_system.h
Normal file
@@ -0,0 +1,222 @@
|
||||
#pragma once
|
||||
#include "../entity_manager.h"
|
||||
#include "../components/render_component.h"
|
||||
#include "../components/transform_component.h"
|
||||
#include "../components/shader_component.h"
|
||||
#include "shader_manager_class.h"
|
||||
#include <DirectXMath.h>
|
||||
|
||||
namespace ecs {
|
||||
|
||||
class RenderSystem {
|
||||
public:
|
||||
RenderSystem(ID3D11DeviceContext* deviceContext, shader_manager_class* shaderManager)
|
||||
: m_deviceContext(deviceContext), m_shaderManager(shaderManager) {}
|
||||
|
||||
// Rendu d'une entit<69> sp<73>cifique
|
||||
bool RenderEntity(std::shared_ptr<Entity> entity,
|
||||
const DirectX::XMMATRIX& viewMatrix,
|
||||
const DirectX::XMMATRIX& projectionMatrix,
|
||||
const DirectX::XMFLOAT4* diffuseColors,
|
||||
const DirectX::XMFLOAT4* lightPositions,
|
||||
const DirectX::XMFLOAT4* ambientColors,
|
||||
const DirectX::XMFLOAT3& cameraPosition,
|
||||
const DirectX::XMFLOAT4& sunlightDiffuse,
|
||||
const DirectX::XMFLOAT4& sunlightAmbient,
|
||||
const DirectX::XMFLOAT3& sunlightDirection,
|
||||
float sunlightIntensity) {
|
||||
|
||||
// V<>rifier si l'entit<69> a tous les composants n<>cessaires
|
||||
auto transform = entity->GetComponent<TransformComponent>();
|
||||
auto render = entity->GetComponent<RenderComponent>();
|
||||
auto shader = entity->GetComponent<ShaderComponent>();
|
||||
|
||||
if (!transform || !render || !shader || !render->GetModel())
|
||||
return false;
|
||||
|
||||
// Calculer la matrice monde
|
||||
XMMATRIX scaleMatrix = transform->GetScaleMatrix();
|
||||
XMMATRIX rotateMatrix = transform->GetRotateMatrix();
|
||||
XMMATRIX translateMatrix = transform->GetTranslateMatrix();
|
||||
|
||||
XMMATRIX worldMatrix = XMMatrixMultiply(
|
||||
XMMatrixMultiply(scaleMatrix, rotateMatrix),
|
||||
translateMatrix
|
||||
);
|
||||
|
||||
// Rendre le mod<6F>le
|
||||
render->Render(m_deviceContext);
|
||||
|
||||
// S<>lectionner le shader appropri<72>
|
||||
switch (shader->GetActiveShader()) {
|
||||
case ShaderType::ALPHA_MAPPING:
|
||||
return m_shaderManager->render_alpha_map_shader(
|
||||
m_deviceContext,
|
||||
render->GetIndexCount(),
|
||||
worldMatrix,
|
||||
viewMatrix,
|
||||
projectionMatrix,
|
||||
render->GetTexture(TextureType::Diffuse, 0),
|
||||
render->GetTexture(TextureType::Diffuse, 1),
|
||||
render->GetTexture(TextureType::Alpha, 0)
|
||||
);
|
||||
|
||||
case ShaderType::CEL_SHADING:
|
||||
return m_shaderManager->render_cel_shading_shader(
|
||||
m_deviceContext,
|
||||
render->GetIndexCount(),
|
||||
worldMatrix,
|
||||
viewMatrix,
|
||||
projectionMatrix,
|
||||
render->GetTexture(TextureType::Diffuse, 0),
|
||||
sunlightDiffuse,
|
||||
sunlightAmbient,
|
||||
sunlightDirection,
|
||||
sunlightIntensity
|
||||
);
|
||||
|
||||
case ShaderType::NORMAL_MAPPING:
|
||||
return m_shaderManager->render_normal_map_shader(
|
||||
m_deviceContext,
|
||||
render->GetIndexCount(),
|
||||
worldMatrix,
|
||||
viewMatrix,
|
||||
projectionMatrix,
|
||||
render->GetTexture(TextureType::Diffuse, 0),
|
||||
render->GetTexture(TextureType::Normal, 0),
|
||||
sunlightDirection,
|
||||
sunlightDiffuse
|
||||
);
|
||||
|
||||
case ShaderType::SPECULAR_MAPPING:
|
||||
|
||||
return m_shaderManager->render_spec_map_shader(
|
||||
m_deviceContext,
|
||||
render->GetIndexCount(),
|
||||
worldMatrix,
|
||||
viewMatrix,
|
||||
projectionMatrix,
|
||||
render->GetTexture(TextureType::Diffuse, 0),
|
||||
render->GetTexture(TextureType::Normal, 0),
|
||||
render->GetTexture(TextureType::Specular, 0),
|
||||
sunlightDirection,
|
||||
sunlightDiffuse,
|
||||
cameraPosition,
|
||||
sunlightDiffuse, // Couleur speculaire (<28> ajuster)
|
||||
16.0f // Puissance speculaire (<28> ajuster)
|
||||
);
|
||||
|
||||
case ShaderType::LIGHTING:
|
||||
{
|
||||
// Cr<43>er des copies locales non constantes des tableaux
|
||||
DirectX::XMFLOAT4 localDiffuseColors[4];
|
||||
DirectX::XMFLOAT4 localLightPositions[4];
|
||||
DirectX::XMFLOAT4 localAmbientColors[4];
|
||||
|
||||
// Copier les donn<6E>es
|
||||
for (int i = 0; i < 4; i++) {
|
||||
localDiffuseColors[i] = diffuseColors[i];
|
||||
localLightPositions[i] = lightPositions[i];
|
||||
localAmbientColors[i] = ambientColors[i];
|
||||
}
|
||||
|
||||
return m_shaderManager->renderlight_shader(
|
||||
m_deviceContext,
|
||||
render->GetIndexCount(),
|
||||
worldMatrix,
|
||||
viewMatrix,
|
||||
projectionMatrix,
|
||||
render->GetTexture(TextureType::Diffuse, 0),
|
||||
localDiffuseColors,
|
||||
localLightPositions,
|
||||
localAmbientColors
|
||||
);
|
||||
}
|
||||
|
||||
case ShaderType::SUNLIGHT:
|
||||
return m_shaderManager->render_sunlight_shader(
|
||||
m_deviceContext,
|
||||
render->GetIndexCount(),
|
||||
worldMatrix,
|
||||
viewMatrix,
|
||||
projectionMatrix,
|
||||
render->GetTexture(TextureType::Diffuse, 0),
|
||||
sunlightDiffuse,
|
||||
sunlightAmbient,
|
||||
sunlightDirection,
|
||||
sunlightIntensity
|
||||
);
|
||||
|
||||
case ShaderType::SKYBOX:
|
||||
return m_shaderManager->render_skybox_shader(
|
||||
m_deviceContext,
|
||||
render->GetIndexCount(),
|
||||
worldMatrix,
|
||||
viewMatrix,
|
||||
projectionMatrix,
|
||||
render->GetTexture(TextureType::Diffuse, 0),
|
||||
sunlightDiffuse,
|
||||
sunlightAmbient,
|
||||
sunlightDirection,
|
||||
sunlightIntensity
|
||||
);
|
||||
|
||||
case ShaderType::TEXTURE:
|
||||
default:
|
||||
return m_shaderManager->render_texture_shader(
|
||||
m_deviceContext,
|
||||
render->GetIndexCount(),
|
||||
worldMatrix,
|
||||
viewMatrix,
|
||||
projectionMatrix,
|
||||
render->GetTexture(TextureType::Diffuse, 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Rendu de toutes les entit<69>s avec les composants n<>cessaires
|
||||
int RenderAllEntities(EntityManager* entityManager,
|
||||
const DirectX::XMMATRIX& viewMatrix,
|
||||
const DirectX::XMMATRIX& projectionMatrix,
|
||||
const DirectX::XMFLOAT4* diffuseColors,
|
||||
const DirectX::XMFLOAT4* lightPositions,
|
||||
const DirectX::XMFLOAT4* ambientColors,
|
||||
const DirectX::XMFLOAT3& cameraPos,
|
||||
const DirectX::XMFLOAT4& sunlightDiffuse,
|
||||
const DirectX::XMFLOAT4& sunlightAmbient,
|
||||
const DirectX::XMFLOAT3& sunlightDirection,
|
||||
float sunlightIntensity) {
|
||||
|
||||
int renderCount = 0;
|
||||
|
||||
// R<>cup<75>rer toutes les entit<69>s qui ont les composants RenderComponent et TransformComponent
|
||||
auto entities = entityManager->GetEntitiesWithComponent<RenderComponent>();
|
||||
|
||||
for (auto& entity : entities) {
|
||||
auto render = entity->GetComponent<RenderComponent>();
|
||||
|
||||
// V<>rifier si l'entit<69> a un TransformComponent
|
||||
auto transform = entity->GetComponent<TransformComponent>();
|
||||
if (!transform) continue;
|
||||
|
||||
// V<>rifier si le mod<6F>le est visible
|
||||
if (!render->IsVisible()) continue;
|
||||
|
||||
// Effectuer le rendu
|
||||
if (RenderEntity(entity, viewMatrix, projectionMatrix,
|
||||
diffuseColors, lightPositions, ambientColors,cameraPos,
|
||||
sunlightDiffuse, sunlightAmbient, sunlightDirection,
|
||||
sunlightIntensity)) {
|
||||
renderCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return renderCount;
|
||||
}
|
||||
|
||||
private:
|
||||
ID3D11DeviceContext* m_deviceContext;
|
||||
shader_manager_class* m_shaderManager;
|
||||
};
|
||||
|
||||
} // namespace ecs
|
||||
Reference in New Issue
Block a user