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_RefractionTexture = 0;
|
||||||
m_ReflectionTexture = 0;
|
m_ReflectionTexture = 0;
|
||||||
m_Physics = 0;
|
m_Physics = 0;
|
||||||
|
m_cubes.clear();
|
||||||
|
m_terrainChunk.clear();
|
||||||
|
m_object.clear();
|
||||||
|
m_RenderQueues.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationClass::~ApplicationClass()
|
ApplicationClass::~ApplicationClass()
|
||||||
@ -47,6 +51,10 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
bool result;
|
bool result;
|
||||||
HRESULT Hresult;
|
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_screenWidth = screenWidth;
|
||||||
m_screenHeight = screenHeight;
|
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 ------------ //
|
// ------------ 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)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
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;
|
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;
|
XMMATRIX worldMatrix, scaleMatrix, rotateMatrix, translateMatrix, srMatrix;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
for (auto& object : RenderQueue)
|
for (const auto& RenderQueue : RenderQueues)
|
||||||
{
|
{
|
||||||
|
for (auto& object : RenderQueue.get())
|
||||||
if (object == nullptr)
|
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
|
if (object == nullptr)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Could not render the model using the cel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
Logger::Get().Log("Object is null", __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);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
scaleMatrix = object->GetScaleMatrix();
|
||||||
}
|
rotateMatrix = object->GetRotateMatrix();
|
||||||
|
translateMatrix = object->GetTranslateMatrix();
|
||||||
|
|
||||||
// Render Specular mapping.
|
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
||||||
if (object->GetSpecularMappingEnabled()) {
|
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
||||||
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)
|
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);
|
case Object::CEL_SHADING:
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ private:
|
|||||||
bool RenderSceneToTexture(float);
|
bool RenderSceneToTexture(float);
|
||||||
bool RenderRefractionToTexture();
|
bool RenderRefractionToTexture();
|
||||||
bool RenderReflectionToTexture();
|
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 :
|
private :
|
||||||
|
|
||||||
@ -152,6 +152,7 @@ private :
|
|||||||
float m_speed = 0.1f; // speed for the demo spinning object
|
float m_speed = 0.1f; // speed for the demo spinning object
|
||||||
std::vector<Object*> m_object;
|
std::vector<Object*> m_object;
|
||||||
int m_ObjectId = 0;
|
int m_ObjectId = 0;
|
||||||
|
std::vector<std::reference_wrapper<std::vector<Object*>>> m_RenderQueues;
|
||||||
|
|
||||||
// ----------------------------------- //
|
// ----------------------------------- //
|
||||||
// ------------- LIGHTS -------------- //
|
// ------------- 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">
|
<CopyFileToFolders Include="assets\Texture\water01.png">
|
||||||
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\assets\Texture\</DestinationFolders>
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\assets\Texture\</DestinationFolders>
|
||||||
</CopyFileToFolders>
|
</CopyFileToFolders>
|
||||||
|
<Image Include="assets\Texture\EmptyTexture.png" />
|
||||||
<Image Include="KhaoticIcon.ico" />
|
<Image Include="KhaoticIcon.ico" />
|
||||||
<CopyFileToFolders Include="sprite01.tga" />
|
<CopyFileToFolders Include="sprite01.tga" />
|
||||||
<CopyFileToFolders Include="sprite02.tga" />
|
<CopyFileToFolders Include="sprite02.tga" />
|
||||||
|
@ -388,6 +388,9 @@
|
|||||||
<Image Include="KhaoticIcon.ico">
|
<Image Include="KhaoticIcon.ico">
|
||||||
<Filter>Assets</Filter>
|
<Filter>Assets</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
|
<Image Include="assets\Texture\EmptyTexture.png">
|
||||||
|
<Filter>Assets\Texture</Filter>
|
||||||
|
</Image>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
@ -162,7 +162,11 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
|
|||||||
// Texture
|
// Texture
|
||||||
// add all texture category names to a vector
|
// add all texture category names to a vector
|
||||||
std::vector<std::string> textureCategories = {
|
std::vector<std::string> textureCategories = {
|
||||||
"Diffuse"
|
"Diffuse",
|
||||||
|
"Normal",
|
||||||
|
"Specular",
|
||||||
|
"Reflection",
|
||||||
|
"Refraction"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -246,6 +250,34 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
|
|||||||
app->DeleteKobject(index);
|
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();
|
ImGui::Separator();
|
||||||
|
|
||||||
// Demo spinning
|
// Demo spinning
|
||||||
|
@ -233,64 +233,4 @@ bool Object::IsPhysicsEnabled() const
|
|||||||
void Object::SetPhysicsEnabled(bool state)
|
void Object::SetPhysicsEnabled(bool state)
|
||||||
{
|
{
|
||||||
m_isPhysicsEnabled = 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);
|
bool LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, const std::wstring& filename);
|
||||||
|
|
||||||
// Setters and getters for the shader to use
|
enum ShaderType
|
||||||
void SetCelShading(bool state);
|
{
|
||||||
bool GetCelShading() const;
|
CEL_SHADING,
|
||||||
void SetLightingEnabled(bool state);
|
LIGHTING,
|
||||||
bool GetLightingEnabled() const;
|
NORMAL_MAPPING,
|
||||||
void SetNormalMappingEnabled(bool state);
|
SPECULAR_MAPPING,
|
||||||
bool GetNormalMappingEnabled() const;
|
REFLECTION,
|
||||||
void SetSpecularMappingEnabled(bool state);
|
REFRACTION
|
||||||
bool GetSpecularMappingEnabled() const;
|
};
|
||||||
void SetReflectionEnabled(bool state);
|
|
||||||
bool GetReflectionEnabled() const;
|
ShaderType GetActiveShader() const { return m_activeShader; };
|
||||||
void SetRefractionEnabled(bool state);
|
void SetActiveShader(ShaderType activeShader) { m_activeShader = activeShader; };
|
||||||
bool GetRefractionEnabled() const;
|
|
||||||
|
|
||||||
public :
|
public :
|
||||||
bool m_demoSpinning = false;
|
bool m_demoSpinning = false;
|
||||||
@ -91,11 +90,5 @@ private:
|
|||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
// Shader to use for rendering
|
ShaderType m_activeShader = LIGHTING;
|
||||||
bool isCelShading = false;
|
|
||||||
bool isLightingEnabled = true;
|
|
||||||
bool isNormalMappingEnabled = false;
|
|
||||||
bool isSpecularMappingEnabled = false;
|
|
||||||
bool isReflectionEnabled = false;
|
|
||||||
bool isRefractionEnabled = false;
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user