From 6e703a783a63a2c69a3a9c574583288309574748 Mon Sep 17 00:00:00 2001 From: "Andon M. Coleman" Date: Mon, 12 Jun 2017 14:05:43 -0400 Subject: [PATCH] Add light-space volume tests --- nier.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/nier.cpp b/nier.cpp index 7296283..048cfca 100644 --- a/nier.cpp +++ b/nier.cpp @@ -49,7 +49,7 @@ #include -#define FAR_VERSION_NUM L"0.6.0" +#define FAR_VERSION_NUM L"0.6.1" #define FAR_VERSION_STR L"FAR v " FAR_VERSION_NUM // Block until update finishes, otherwise the update dialog @@ -317,6 +317,8 @@ SK_FAR_CheckVersion (LPVOID user) return 0; } +#include <../depends/include/glm/glm.hpp> + HRESULT WINAPI SK_FAR_CreateBuffer ( @@ -343,7 +345,7 @@ SK_FAR_CreateBuffer ( // TODO: Scale light volume by distance from camera (in world-space) to properly // handle small nearby lights. // - if (pInitialData != 0) + if (pInitialData != nullptr && pInitialData->pSysMem != nullptr) { struct far_light_volume_s { float world_pos [4]; @@ -356,10 +358,33 @@ SK_FAR_CreateBuffer ( static far_light_volume_s backup_lights [128]; - for (int i = 0; i < 128; i++) { - if (lights [i].half_extents [0] < __FAR_MINIMUM_EXT || - lights [i].half_extents [1] < __FAR_MINIMUM_EXT || - lights [i].half_extents [2] < __FAR_MINIMUM_EXT) + // This code is bloody ugly, but it works ;) + for (int i = 0; i < 128; i++) + { + float light_pos [4] = { lights [i].world_pos [0], lights [i].world_pos [1], + lights [i].world_pos [2], lights [i].world_pos [3] }; + + if ( lights [i].world_pos [0] == 0.0f && lights [i].world_pos [1] == 0.0f && + lights [i].world_pos [2] == 0.0f && lights [i].world_pos [3] == 0.0f ) + { + lights [i] = backup_lights [i]; + + light_pos [0] = backup_lights [i].world_pos [0]; light_pos [1] = backup_lights [i].world_pos [1]; + light_pos [2] = backup_lights [i].world_pos [2]; light_pos [3] = backup_lights [i].world_pos [3]; + } + + glm::vec4 cam_pos_world (light_pos [0] - ((float *)far_cam.pCamera) [0], light_pos [1] - ((float *)far_cam.pCamera) [1], light_pos [2] - ((float *)far_cam.pCamera) [2], 1.0f); + + glm::mat4x4 world_mat (lights [i].world_to_vol [ 0], lights [i].world_to_vol [ 1], lights [i].world_to_vol [ 2], lights [i].world_to_vol [ 3], + lights [i].world_to_vol [ 4], lights [i].world_to_vol [ 5], lights [i].world_to_vol [ 6], lights [i].world_to_vol [ 7], + lights [i].world_to_vol [ 8], lights [i].world_to_vol [ 9], lights [i].world_to_vol [10], lights [i].world_to_vol [11], + lights [i].world_to_vol [12], lights [i].world_to_vol [13], lights [i].world_to_vol [14], lights [i].world_to_vol [15]); + + glm::vec4 test = world_mat * cam_pos_world; + + if ( fabs (lights [i].half_extents [0]) < fabs (test.x) * __FAR_MINIMUM_EXT || + fabs (lights [i].half_extents [1]) < fabs (test.z) * __FAR_MINIMUM_EXT || + fabs (lights [i].half_extents [2]) < fabs (test.y) * __FAR_MINIMUM_EXT ) { if ( lights [i].half_extents [0] != 0.0f && lights [i].half_extents [1] != 0.0f && lights [i].half_extents [2] != 0.0f ) @@ -1125,6 +1150,7 @@ D3D11_PSSetShaderResources_Override ( // Note that there are more low-res 800x450 buffers not yet handled by this, // but which could probably be handled similarly. Primarily, SSAO. +__declspec (noinline) HRESULT WINAPI SK_FAR_CreateTexture2D ( @@ -1531,7 +1557,7 @@ SK_FAR_CorrectAspectRatio (ID3D11DeviceContext *pDevCtx) return false; } - +__declspec (noinline) void WINAPI SK_FAR_DrawIndexed ( @@ -1556,6 +1582,7 @@ SK_FAR_DrawIndexed ( SK_FAR_RestoreAspectRatio (This); } +__declspec (noinline) void WINAPI SK_FAR_Draw ( @@ -1580,6 +1607,7 @@ SK_FAR_Draw ( } +__declspec (noinline) void WINAPI SK_FAR_DrawIndexedInstanced ( @@ -1598,6 +1626,7 @@ SK_FAR_DrawIndexedInstanced ( SK_FAR_RestoreAspectRatio (This); } +__declspec (noinline) void WINAPI SK_FAR_DrawIndexedInstancedIndirect ( @@ -1613,6 +1642,7 @@ SK_FAR_DrawIndexedInstancedIndirect ( SK_FAR_RestoreAspectRatio (This); } +__declspec (noinline) void WINAPI SK_FAR_DrawInstanced ( @@ -1630,6 +1660,7 @@ SK_FAR_DrawInstanced ( SK_FAR_RestoreAspectRatio (This); } +__declspec (noinline) void WINAPI SK_FAR_DrawInstancedIndirect ( @@ -1645,7 +1676,10 @@ SK_FAR_DrawInstancedIndirect ( SK_FAR_RestoreAspectRatio (This); } +#include +#include +__declspec (noinline) void WINAPI SK_FAR_PSSetShaderResources ( @@ -1654,7 +1688,8 @@ SK_FAR_PSSetShaderResources ( _In_ UINT NumViews, _In_opt_ ID3D11ShaderResourceView* const *ppShaderResourceViews ) { - static ID3D11ShaderResourceView* views [256]; + std::vector views; + views.reserve (NumViews); if (ppShaderResourceViews != nullptr) { @@ -1663,18 +1698,18 @@ SK_FAR_PSSetShaderResources ( views [i] = ppShaderResourceViews [i]; if (far_ao.views.count (ppShaderResourceViews [i]) && far_ao.disable) { - views [i] = nullptr; + views [i] = nullptr; far_ao.active = true; } else if (far_bloom.views.count (ppShaderResourceViews [i]) && far_bloom.disable) { - views [i] = nullptr; + views [i] = nullptr; far_bloom.active = true; } } } - ppShaderResourceViews = views; + ppShaderResourceViews = views.data (); #if 0 for (int i = 0; i < NumViews; i++) @@ -2441,8 +2476,12 @@ SK_FAR_ControlPanel (void) //ImGui::Checkbox ("Compatibility Mode", &__FAR_GlobalIllumCompatMode); } - if (ImGui::SliderFloat ("Minimum Light Extent", &__FAR_MINIMUM_EXT, 0.0f, 64.0f)) + float extent = __FAR_MINIMUM_EXT * 100.0f; + + if (ImGui::SliderFloat ("Minimum Light Extent", &extent, 0.0f, 100.0f, "%0.2f%%")) { + __FAR_MINIMUM_EXT = std::min (1.0f, std::max (0.0f, extent / 100.0f)); + far_gi_min_light_extent->set_value (__FAR_MINIMUM_EXT); far_gi_min_light_extent->store (); }