Minor update - Add Render Queues
This commit is contained in:
parent
915c0cdd7f
commit
ab0355ed97
@ -25,6 +25,10 @@ ApplicationClass::ApplicationClass() : m_ShouldQuit(false)
|
||||
m_RefractionTexture = 0;
|
||||
m_ReflectionTexture = 0;
|
||||
m_Physics = 0;
|
||||
m_cubes.clear();
|
||||
m_terrainChunk.clear();
|
||||
m_object.clear();
|
||||
m_RenderQueues.clear();
|
||||
}
|
||||
|
||||
ApplicationClass::~ApplicationClass()
|
||||
@ -47,6 +51,10 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
||||
bool result;
|
||||
HRESULT Hresult;
|
||||
|
||||
m_RenderQueues.push_back(std::ref(m_object));
|
||||
m_RenderQueues.push_back(std::ref(m_cubes));
|
||||
m_RenderQueues.push_back(std::ref(m_terrainChunk));
|
||||
|
||||
m_screenWidth = screenWidth;
|
||||
m_screenHeight = screenHeight;
|
||||
|
||||
@ -1072,7 +1080,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
|
||||
// -------------------------------------------------------- //
|
||||
// ------------ Render the object in the queue ------------ //
|
||||
// -------------------------------------------------------- //
|
||||
result = RenderPass(m_terrainChunk, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
|
||||
result = RenderPass(m_RenderQueues, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
|
||||
if (!result)
|
||||
{
|
||||
Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
@ -1904,81 +1912,74 @@ void ApplicationClass::SetScreenWidth(int width)
|
||||
m_screenWidth = width;
|
||||
}
|
||||
|
||||
bool ApplicationClass::RenderPass(std::vector<Object*> RenderQueue, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection)
|
||||
bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::vector<Object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection)
|
||||
{
|
||||
XMMATRIX worldMatrix, scaleMatrix, rotateMatrix, translateMatrix, srMatrix;
|
||||
bool result;
|
||||
|
||||
for (auto& object : RenderQueue)
|
||||
for (const auto& RenderQueue : RenderQueues)
|
||||
{
|
||||
|
||||
if (object == nullptr)
|
||||
for (auto& object : RenderQueue.get())
|
||||
{
|
||||
Logger::Get().Log("Object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
scaleMatrix = object->GetScaleMatrix();
|
||||
rotateMatrix = object->GetRotateMatrix();
|
||||
translateMatrix = object->GetTranslateMatrix();
|
||||
|
||||
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
||||
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
||||
|
||||
object->Render(m_Direct3D->GetDeviceContext());
|
||||
|
||||
// Render cel shading.
|
||||
if (object->GetCelShading()) {
|
||||
result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0),
|
||||
m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), TrueLightPosition);
|
||||
if (!result)
|
||||
if (object == nullptr)
|
||||
{
|
||||
Logger::Get().Log("Could not render the model using the cel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Render normal mapping.
|
||||
if (object->GetNormalMappingEnabled()) {
|
||||
|
||||
result = m_ShaderManager->RenderNormalMapShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), object->GetTexture(1), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor());
|
||||
|
||||
if (!result)
|
||||
{
|
||||
Logger::Get().Log("Could not render the model using the normal map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
Logger::Get().Log("Object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
scaleMatrix = object->GetScaleMatrix();
|
||||
rotateMatrix = object->GetRotateMatrix();
|
||||
translateMatrix = object->GetTranslateMatrix();
|
||||
|
||||
// Render Specular mapping.
|
||||
if (object->GetSpecularMappingEnabled()) {
|
||||
result = m_ShaderManager->RenderSpecMapShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), object->GetTexture(1), object->GetTexture(2), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), m_Camera->GetPosition(), m_Lights[0]->GetSpecularColor(), m_Lights[0]->GetSpecularPower());
|
||||
if (!result)
|
||||
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
||||
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
||||
|
||||
object->Render(m_Direct3D->GetDeviceContext());
|
||||
|
||||
// Utiliser l'enum ShaderType pour déterminer quel shader utiliser
|
||||
switch (object->GetActiveShader())
|
||||
{
|
||||
Logger::Get().Log("Could not render the model using the specular map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
case Object::CEL_SHADING:
|
||||
result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0),
|
||||
m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), TrueLightPosition);
|
||||
if (!result)
|
||||
{
|
||||
Logger::Get().Log("Could not render the model using the cel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case Object::NORMAL_MAPPING:
|
||||
result = m_ShaderManager->RenderNormalMapShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), object->GetTexture(1), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor());
|
||||
if (!result)
|
||||
{
|
||||
Logger::Get().Log("Could not render the model using the normal map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case Object::SPECULAR_MAPPING:
|
||||
result = m_ShaderManager->RenderSpecMapShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), object->GetTexture(1), object->GetTexture(2), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), m_Camera->GetPosition(), m_Lights[0]->GetSpecularColor(), m_Lights[0]->GetSpecularPower());
|
||||
if (!result)
|
||||
{
|
||||
Logger::Get().Log("Could not render the model using the specular map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case Object::LIGHTING:
|
||||
default:
|
||||
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection,
|
||||
object->GetTexture(0), diffuse, position, ambient);
|
||||
if (!result)
|
||||
{
|
||||
Logger::Get().Log("Could not render the object model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// By default, render the object using the light shader.
|
||||
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection,
|
||||
object->GetTexture(0) ,diffuse, position, ambient);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
Logger::Get().Log("Could not render the object model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ private:
|
||||
bool RenderSceneToTexture(float);
|
||||
bool RenderRefractionToTexture();
|
||||
bool RenderReflectionToTexture();
|
||||
bool RenderPass(std::vector<Object*> RenderQueue, XMFLOAT4* diffuse,XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX proijection);
|
||||
bool RenderPass(const std::vector<std::reference_wrapper<std::vector<Object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection);
|
||||
|
||||
private :
|
||||
|
||||
@ -152,6 +152,7 @@ private :
|
||||
float m_speed = 0.1f; // speed for the demo spinning object
|
||||
std::vector<Object*> m_object;
|
||||
int m_ObjectId = 0;
|
||||
std::vector<std::reference_wrapper<std::vector<Object*>>> m_RenderQueues;
|
||||
|
||||
// ----------------------------------- //
|
||||
// ------------- LIGHTS -------------- //
|
||||
|
BIN
enginecustom/assets/Texture/EmptyTexture.png
Normal file
BIN
enginecustom/assets/Texture/EmptyTexture.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
@ -304,6 +304,7 @@
|
||||
<CopyFileToFolders Include="assets\Texture\water01.png">
|
||||
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\assets\Texture\</DestinationFolders>
|
||||
</CopyFileToFolders>
|
||||
<Image Include="assets\Texture\EmptyTexture.png" />
|
||||
<Image Include="KhaoticIcon.ico" />
|
||||
<CopyFileToFolders Include="sprite01.tga" />
|
||||
<CopyFileToFolders Include="sprite02.tga" />
|
||||
|
@ -388,6 +388,9 @@
|
||||
<Image Include="KhaoticIcon.ico">
|
||||
<Filter>Assets</Filter>
|
||||
</Image>
|
||||
<Image Include="assets\Texture\EmptyTexture.png">
|
||||
<Filter>Assets\Texture</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
@ -162,7 +162,11 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
|
||||
// Texture
|
||||
// add all texture category names to a vector
|
||||
std::vector<std::string> textureCategories = {
|
||||
"Diffuse"
|
||||
"Diffuse",
|
||||
"Normal",
|
||||
"Specular",
|
||||
"Reflection",
|
||||
"Refraction"
|
||||
};
|
||||
|
||||
|
||||
@ -246,6 +250,34 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
|
||||
app->DeleteKobject(index);
|
||||
}
|
||||
|
||||
// Shader selection
|
||||
std::string shaderLabel = "Shader##" + std::to_string(index);
|
||||
|
||||
// Radio buttons for shader options
|
||||
Object::ShaderType activeShader = object->GetActiveShader();
|
||||
|
||||
if (ImGui::RadioButton("Enable Lighting", activeShader == Object::LIGHTING))
|
||||
{
|
||||
object->SetActiveShader(Object::LIGHTING);
|
||||
}
|
||||
|
||||
if (ImGui::RadioButton("Enable Cel Shading", activeShader == Object::CEL_SHADING))
|
||||
{
|
||||
object->SetActiveShader(Object::CEL_SHADING);
|
||||
}
|
||||
|
||||
if (ImGui::RadioButton("Enable Normal Mapping", activeShader == Object::NORMAL_MAPPING))
|
||||
{
|
||||
object->SetActiveShader(Object::NORMAL_MAPPING);
|
||||
}
|
||||
|
||||
if (ImGui::RadioButton("Enable Specular Mapping", activeShader == Object::SPECULAR_MAPPING))
|
||||
{
|
||||
object->SetActiveShader(Object::SPECULAR_MAPPING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
// Demo spinning
|
||||
|
@ -233,64 +233,4 @@ bool Object::IsPhysicsEnabled() const
|
||||
void Object::SetPhysicsEnabled(bool state)
|
||||
{
|
||||
m_isPhysicsEnabled = state;
|
||||
}
|
||||
|
||||
void Object::SetCelShading(bool state)
|
||||
{
|
||||
isCelShading = state;
|
||||
}
|
||||
|
||||
bool Object::GetCelShading() const
|
||||
{
|
||||
return isCelShading;
|
||||
}
|
||||
|
||||
void Object::SetLightingEnabled(bool state)
|
||||
{
|
||||
isLightingEnabled = state;
|
||||
}
|
||||
|
||||
bool Object::GetLightingEnabled() const
|
||||
{
|
||||
return isLightingEnabled;
|
||||
}
|
||||
|
||||
void Object::SetNormalMappingEnabled(bool state)
|
||||
{
|
||||
isNormalMappingEnabled = state;
|
||||
}
|
||||
|
||||
bool Object::GetNormalMappingEnabled() const
|
||||
{
|
||||
return isNormalMappingEnabled;
|
||||
}
|
||||
|
||||
void Object::SetSpecularMappingEnabled(bool state)
|
||||
{
|
||||
isSpecularMappingEnabled = state;
|
||||
}
|
||||
|
||||
bool Object::GetSpecularMappingEnabled() const
|
||||
{
|
||||
return isSpecularMappingEnabled;
|
||||
}
|
||||
|
||||
void Object::SetReflectionEnabled(bool state)
|
||||
{
|
||||
isReflectionEnabled = state;
|
||||
}
|
||||
|
||||
bool Object::GetReflectionEnabled() const
|
||||
{
|
||||
return isReflectionEnabled;
|
||||
}
|
||||
|
||||
void Object::SetRefractionEnabled(bool state)
|
||||
{
|
||||
isRefractionEnabled = state;
|
||||
}
|
||||
|
||||
bool Object::GetRefractionEnabled() const
|
||||
{
|
||||
return isRefractionEnabled;
|
||||
}
|
@ -57,19 +57,18 @@ public:
|
||||
|
||||
bool LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, const std::wstring& filename);
|
||||
|
||||
// Setters and getters for the shader to use
|
||||
void SetCelShading(bool state);
|
||||
bool GetCelShading() const;
|
||||
void SetLightingEnabled(bool state);
|
||||
bool GetLightingEnabled() const;
|
||||
void SetNormalMappingEnabled(bool state);
|
||||
bool GetNormalMappingEnabled() const;
|
||||
void SetSpecularMappingEnabled(bool state);
|
||||
bool GetSpecularMappingEnabled() const;
|
||||
void SetReflectionEnabled(bool state);
|
||||
bool GetReflectionEnabled() const;
|
||||
void SetRefractionEnabled(bool state);
|
||||
bool GetRefractionEnabled() const;
|
||||
enum ShaderType
|
||||
{
|
||||
CEL_SHADING,
|
||||
LIGHTING,
|
||||
NORMAL_MAPPING,
|
||||
SPECULAR_MAPPING,
|
||||
REFLECTION,
|
||||
REFRACTION
|
||||
};
|
||||
|
||||
ShaderType GetActiveShader() const { return m_activeShader; };
|
||||
void SetActiveShader(ShaderType activeShader) { m_activeShader = activeShader; };
|
||||
|
||||
public :
|
||||
bool m_demoSpinning = false;
|
||||
@ -91,11 +90,5 @@ private:
|
||||
|
||||
std::string m_name;
|
||||
|
||||
// Shader to use for rendering
|
||||
bool isCelShading = false;
|
||||
bool isLightingEnabled = true;
|
||||
bool isNormalMappingEnabled = false;
|
||||
bool isSpecularMappingEnabled = false;
|
||||
bool isReflectionEnabled = false;
|
||||
bool isRefractionEnabled = false;
|
||||
ShaderType m_activeShader = LIGHTING;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user