Patch Update - Frustum Culling Thread Independant - V10.2.2
This commit is contained in:
parent
f8bfb62e98
commit
644fc57762
48
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
48
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
@ -6,10 +6,8 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
|
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/imgui.ini" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/modelclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/modelclass.cpp" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -23,13 +21,8 @@
|
|||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
<component name="HighlightingSettingsPerFile">
|
<component name="HighlightingSettingsPerFile">
|
||||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
<setting file="file://C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/d3d11.h" root0="SKIP_HIGHLIGHTING" />
|
||||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/enginecustom/include/Inc/VertexTypes.h" root0="SKIP_HIGHLIGHTING" />
|
||||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
|
||||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
|
||||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
|
||||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
|
||||||
<setting file="cidr-memory-view://4" root0="FORCE_HIGHLIGHTING" />
|
|
||||||
<setting file="file://$PROJECT_DIR$/enginecustom/include/Vulkan/Include/vulkan/vulkan_core.h" root0="SKIP_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/enginecustom/include/Vulkan/Include/vulkan/vulkan_core.h" root0="SKIP_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/enginecustom/src/src/shader/CelShadingShader.cpp" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/enginecustom/src/src/shader/CelShadingShader.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/../../IDE_VS/VC/Tools/MSVC/14.38.33130/include/type_traits" root0="SKIP_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/../../IDE_VS/VC/Tools/MSVC/14.38.33130/include/type_traits" root0="SKIP_HIGHLIGHTING" />
|
||||||
@ -46,25 +39,25 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"C++ Project.enginecustom.executor": "Run",
|
"C++ Project.enginecustom.executor": "Run",
|
||||||
"C/C++ Project.enginecustom.executor": "dotTrace Profiler",
|
"C/C++ Project.enginecustom.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"settings.editor.selected.configurable": "preferences.build.unityPlugin",
|
"settings.editor.selected.configurable": "preferences.build.unityPlugin",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RunManager" selected="C/C++ Project.enginecustom">
|
<component name="RunManager" selected="C/C++ Project.enginecustom">
|
||||||
<configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project">
|
<configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project">
|
||||||
<configuration_1 setup="1">
|
<configuration_1 setup="1">
|
||||||
@ -186,6 +179,7 @@
|
|||||||
<workItem from="1746538260893" duration="5781000" />
|
<workItem from="1746538260893" duration="5781000" />
|
||||||
<workItem from="1746546014271" duration="1814000" />
|
<workItem from="1746546014271" duration="1814000" />
|
||||||
<workItem from="1746619988287" duration="12282000" />
|
<workItem from="1746619988287" duration="12282000" />
|
||||||
|
<workItem from="1746711806997" duration="2620000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
|
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
@ -196,6 +196,12 @@ public :
|
|||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
|
// Thread de culling
|
||||||
|
std::thread m_CullingThread;
|
||||||
|
std::atomic<bool> m_CullingActive;
|
||||||
|
std::mutex m_ObjectsMutex;
|
||||||
|
void CullingThreadFunction();
|
||||||
|
|
||||||
|
|
||||||
std::mutex m_TerrainMutex;
|
std::mutex m_TerrainMutex;
|
||||||
std::vector<std::tuple<float, float, float, std::string, int>> m_TerrainGenerationData;
|
std::vector<std::tuple<float, float, float, std::string, int>> m_TerrainGenerationData;
|
||||||
|
@ -54,12 +54,18 @@ ApplicationClass::ApplicationClass() : m_ShouldQuit(false)
|
|||||||
ApplicationClass::~ApplicationClass()
|
ApplicationClass::~ApplicationClass()
|
||||||
{
|
{
|
||||||
m_ShouldQuit = true;
|
m_ShouldQuit = true;
|
||||||
|
m_CullingActive = false;
|
||||||
|
|
||||||
// Joindre le thread pour s'assurer qu'il se termine correctement
|
// Joindre les threads pour s'assurer qu'ils se terminent correctement
|
||||||
if (m_PhysicsThread.joinable())
|
if (m_PhysicsThread.joinable())
|
||||||
{
|
{
|
||||||
m_PhysicsThread.join();
|
m_PhysicsThread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_CullingThread.joinable())
|
||||||
|
{
|
||||||
|
m_CullingThread.join();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,6 +474,9 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd,
|
|||||||
skybox->Initialize(m_Direct3D);
|
skybox->Initialize(m_Direct3D);
|
||||||
m_Skybox.push_back(skybox->ConstructSkybox());
|
m_Skybox.push_back(skybox->ConstructSkybox());
|
||||||
|
|
||||||
|
m_CullingActive = true;
|
||||||
|
m_CullingThread = std::thread(&ApplicationClass::CullingThreadFunction, this);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
@ -1593,9 +1602,72 @@ void ApplicationClass::SetScreenWidth(int width)
|
|||||||
m_screenWidth = width;
|
m_screenWidth = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApplicationClass::CullingThreadFunction()
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Thread de culling démarré", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
|
||||||
|
while (m_CullingActive)
|
||||||
|
{
|
||||||
|
// Construction du frustum une fois par cycle de culling
|
||||||
|
ConstructFrustum();
|
||||||
|
|
||||||
|
// S'assurer que la skybox est toujours visible
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_ObjectsMutex);
|
||||||
|
for (auto* skyboxObject : m_Skybox)
|
||||||
|
{
|
||||||
|
if (skyboxObject)
|
||||||
|
{
|
||||||
|
skyboxObject->SetVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Traitement des files d'objets normaux (sans la skybox)
|
||||||
|
std::vector<std::reference_wrapper<std::vector<Object*>>> queues = {
|
||||||
|
std::ref(m_object), std::ref(m_cubes), std::ref(m_terrainChunk)
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto& queueRef : queues)
|
||||||
|
{
|
||||||
|
std::vector<Object*>& queue = queueRef.get();
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(m_ObjectsMutex);
|
||||||
|
|
||||||
|
for (auto* object : queue)
|
||||||
|
{
|
||||||
|
if (!object) continue;
|
||||||
|
|
||||||
|
// Extraction des données de position
|
||||||
|
XMVECTOR position = object->GetPosition();
|
||||||
|
float x = XMVectorGetX(position);
|
||||||
|
float y = XMVectorGetY(position);
|
||||||
|
float z = XMVectorGetZ(position);
|
||||||
|
|
||||||
|
// Calcul du rayon approximatif
|
||||||
|
XMVECTOR scale = object->GetScale();
|
||||||
|
float radius = max(max(XMVectorGetX(scale), XMVectorGetY(scale)), XMVectorGetZ(scale));
|
||||||
|
|
||||||
|
// Vérification du frustum
|
||||||
|
bool visible = m_FrustumCulling.CheckCube(x, y, z, radius, GetFrustumTolerance());
|
||||||
|
object->SetVisible(visible);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause pour éviter de surcharger le CPU
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60 Hz
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::Get().Log("Thread de culling terminé", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::vector<Object*>>>& RenderQueues, 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;
|
std::lock_guard<std::mutex> lock(m_ObjectsMutex);
|
||||||
|
XMMATRIX scaleMatrix, rotateMatrix, translateMatrix ;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
int renderCount = 0;
|
int renderCount = 0;
|
||||||
@ -1631,21 +1703,29 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std::
|
|||||||
object->UpdatePosition(m_Timer->GetTime());
|
object->UpdatePosition(m_Timer->GetTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vérifie si l'objet est dans le frustum
|
|
||||||
if (!m_FrustumCulling.CheckCube(x, y, z, radius, GetFrustumTolerance()))
|
if (!object->IsVisible())
|
||||||
{
|
{
|
||||||
object->SetVisible(false);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
object->SetVisible(true); // L'objet est visible
|
|
||||||
|
// // Vérifie si l'objet est dans le frustum
|
||||||
|
// if (!m_FrustumCulling.CheckCube(x, y, z, radius, GetFrustumTolerance()))
|
||||||
|
// {
|
||||||
|
// object->SetVisible(false);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// object->SetVisible(true); // L'objet est visible
|
||||||
renderCount++;
|
renderCount++;
|
||||||
|
|
||||||
scaleMatrix = object->GetScaleMatrix();
|
scaleMatrix = object->GetScaleMatrix();
|
||||||
rotateMatrix = object->GetRotateMatrix();
|
rotateMatrix = object->GetRotateMatrix();
|
||||||
translateMatrix = object->GetTranslateMatrix();
|
translateMatrix = object->GetTranslateMatrix();
|
||||||
|
|
||||||
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
XMMATRIX worldMatrix = XMMatrixMultiply(
|
||||||
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
XMMatrixMultiply(scaleMatrix, rotateMatrix),
|
||||||
|
translateMatrix
|
||||||
|
);
|
||||||
|
|
||||||
object->Render(m_Direct3D->GetDeviceContext());
|
object->Render(m_Direct3D->GetDeviceContext());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user