This commit is contained in:
2025-02-02 22:35:41 +01:00
parent af01f223c1
commit 5e68105fe1
10 changed files with 72 additions and 185 deletions

View File

@@ -31,8 +31,7 @@ float4 FontPixelShader(PixelInputType input) : SV_TARGET
// If the color is black on the texture then treat this pixel as transparent.
if (color.r == 0.0f && color.g == 0.0f && color.b == 0.0f)
{
color.a = 0.0f;
return color;
return color / color;
}
// If the color is other than black on the texture then this is a pixel in the font so draw it using the font pixel color.

View File

@@ -64,7 +64,11 @@ public:
ApplicationClass();
~ApplicationClass();
D3DClass* GetDirect3D();
RenderTextureClass* GetRenderTexture() const { return m_SceneTexture; };
RenderTextureClass* GetSceneTexture() const { return m_SceneTexture; };
RenderTextureClass* GetRenderTexture() const { return m_RenderTexture; };
RenderTextureClass* GetRefractionTexture() const { return m_RefractionTexture; };
RenderTextureClass* GetReflectionTexture() const { return m_ReflectionTexture; };
bool Initialize(int, int, HWND);
void Shutdown();
@@ -140,6 +144,8 @@ public:
bool GetCanFixedUpdate() const { return CanFixedUpdate; };
void SetCanFixedUpdate(bool canFixedUpdate) { CanFixedUpdate = canFixedUpdate; };
ID3D11ShaderResourceView* GetBackBufferSRV() const {return m_BackBufferSRV;};
private:
bool Render(float, float, float, float, float);
bool RenderPhysics(bool keyLeft, bool keyRight, bool keyUp, bool keyDown, float deltaTime);
@@ -256,6 +262,9 @@ private :
bool CanFixedUpdate = false;
std::thread m_PhysicsThread;
ID3D11Texture2D* m_BackBufferTexture;
ID3D11ShaderResourceView* m_BackBufferSRV;
// ------------------------------------------------- //
// ------------------- Culling --------------------- //
// ------------------------------------------------- //

View File

@@ -21,7 +21,7 @@ public:
bool Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext);
void Shutdown();
void Render();
void Render(ApplicationClass* app);
void NewFrame();
void SetupDockspace();

View File

@@ -178,6 +178,7 @@ bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* v
polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[1].InstanceDataStepRate = 0;
// Get a count of the elements in the layout.
numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);

View File

@@ -213,7 +213,7 @@ bool SystemClass::Frame()
Logger::Get().Log("Failed to render ImGui widgets", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
m_Application->GetDirect3D()->EndScene();
return true;

View File

@@ -994,7 +994,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_SceneTexture->Shutdown();
m_SceneTexture->Initialize(m_Direct3D->GetDevice(), (int)windowSize.x, (int)windowSize.y, SCREEN_DEPTH, SCREEN_NEAR, 1);
}
m_SceneTexture->SetRenderTarget(m_Direct3D->GetDeviceContext());
m_SceneTexture->ClearRenderTarget(m_Direct3D->GetDeviceContext(), 0.0f, 0.0f, 0.0f, 1.0f);
@@ -1085,48 +1085,6 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
return false;
}
// Setup matrices - Top display plane.
worldMatrix = XMMatrixTranslation(0.0f, 1.5f, 0.0f);
// Render the display plane using the texture shader and the render texture resource.
m_DisplayPlane->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderTextureShader(m_Direct3D->GetDeviceContext(), m_DisplayPlane->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_RenderTexture->GetShaderResourceView());
if (!result)
{
Logger::Get().Log("Could not render the display plane using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup matrices - Bottom left display plane.
worldMatrix = XMMatrixTranslation(-1.5f, -1.5f, 0.0f);
// Render the display plane using the texture shader and the render texture resource.
m_DisplayPlane->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderTextureShader(m_Direct3D->GetDeviceContext(), m_DisplayPlane->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_RenderTexture->GetShaderResourceView());
if (!result)
{
Logger::Get().Log("Could not render the display plane using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup matrices - Bottom right display plane.
worldMatrix = XMMatrixTranslation(1.5f, -1.5f, 0.0f);
// Render the display plane using the texture shader and the render texture resource.
m_DisplayPlane->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderTextureShader(m_Direct3D->GetDeviceContext(), m_DisplayPlane->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_RenderTexture->GetShaderResourceView());
if (!result)
{
Logger::Get().Log("Could not render the display plane using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Disable the Z buffer and enable alpha blending for 2D rendering.
m_Direct3D->TurnZBufferOff();
m_Direct3D->EnableAlphaBlending();
@@ -1361,6 +1319,8 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Direct3D->TurnZBufferOn();
m_Direct3D->DisableAlphaBlending();
return true;
}

View File

@@ -29,8 +29,6 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
// Setup style
ImGui::StyleColorsDark();
ImGuiStyle& style = ImGui::GetStyle();
style.Colors[ImGuiCol_WindowBg] = ImVec4(1.0f, 0.1f, 0.1f, 1.0f);
Logger::Get().Log("imgui initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
@@ -46,10 +44,17 @@ void imguiManager::Shutdown()
Logger::Get().Log("imgui shutdown", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
void imguiManager::Render()
void imguiManager::Render(ApplicationClass* app)
{
ImGui::Render();
app->GetDirect3D()->TurnZBufferOff();
app->GetDirect3D()->EnableAlphaBlending();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
app->GetDirect3D()->DisableAlphaBlending();
app->GetDirect3D()->TurnZBufferOn();
}
void imguiManager::NewFrame()
@@ -403,7 +408,7 @@ bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app)
WidgetRenderWindow(app, ImVec2(800, 600));
//render imgui
Render();
Render(app);
return true;
}
@@ -604,9 +609,9 @@ void imguiManager::WidgetLogWindow(ApplicationClass* app)
ImGui::End();
}
void imguiManager::WidgetRenderWindow(ApplicationClass* app, ImVec2 availableSize)
{
ImGui::Begin("Render Window");
ImVec2 oldWindowSize = windowSize;
@@ -617,7 +622,6 @@ void imguiManager::WidgetRenderWindow(ApplicationClass* app, ImVec2 availableSiz
{
app->SetWindowSize(windowSize);
}
// Get the aspect ratio of the scene in app
@@ -631,17 +635,13 @@ void imguiManager::WidgetRenderWindow(ApplicationClass* app, ImVec2 availableSiz
{
windowSize.y = windowSize.x / aspectRatio;
}
// Assurez-vous que la texture est valide
m_renderTexture = app->GetRenderTexture();
if (m_renderTexture)
ID3D11ShaderResourceView* texture = app->GetSceneTexture()->GetShaderResourceView();
if (texture)
{
// Obtenez la vue de la ressource shader de la texture rendue
ID3D11ShaderResourceView* texture = m_renderTexture->GetShaderResourceView();
// Affichez la texture dans une fen<65>tre ImGui
ImGui::Image((ImTextureID)texture, windowSize);
ImGui::Image((ImTextureID)texture, windowSize, ImVec2(0, 0), ImVec2(1, 1), ImVec4(1, 1, 1, 1));
}
else
{