Skip to content

Commit

Permalink
Add light-space volume tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien authored Jun 12, 2017
1 parent 3880272 commit 6e703a7
Showing 1 changed file with 51 additions and 12 deletions.
63 changes: 51 additions & 12 deletions nier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <atlbase.h>


#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
Expand Down Expand Up @@ -317,6 +317,8 @@ SK_FAR_CheckVersion (LPVOID user)
return 0;
}

#include <../depends/include/glm/glm.hpp>

HRESULT
WINAPI
SK_FAR_CreateBuffer (
Expand All @@ -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];
Expand All @@ -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 )
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -1531,7 +1557,7 @@ SK_FAR_CorrectAspectRatio (ID3D11DeviceContext *pDevCtx)
return false;
}


__declspec (noinline)
void
WINAPI
SK_FAR_DrawIndexed (
Expand All @@ -1556,6 +1582,7 @@ SK_FAR_DrawIndexed (
SK_FAR_RestoreAspectRatio (This);
}

__declspec (noinline)
void
WINAPI
SK_FAR_Draw (
Expand All @@ -1580,6 +1607,7 @@ SK_FAR_Draw (
}


__declspec (noinline)
void
WINAPI
SK_FAR_DrawIndexedInstanced (
Expand All @@ -1598,6 +1626,7 @@ SK_FAR_DrawIndexedInstanced (
SK_FAR_RestoreAspectRatio (This);
}

__declspec (noinline)
void
WINAPI
SK_FAR_DrawIndexedInstancedIndirect (
Expand All @@ -1613,6 +1642,7 @@ SK_FAR_DrawIndexedInstancedIndirect (
SK_FAR_RestoreAspectRatio (This);
}

__declspec (noinline)
void
WINAPI
SK_FAR_DrawInstanced (
Expand All @@ -1630,6 +1660,7 @@ SK_FAR_DrawInstanced (
SK_FAR_RestoreAspectRatio (This);
}

__declspec (noinline)
void
WINAPI
SK_FAR_DrawInstancedIndirect (
Expand All @@ -1645,7 +1676,10 @@ SK_FAR_DrawInstancedIndirect (
SK_FAR_RestoreAspectRatio (This);
}

#include <cmath>
#include <memory>

__declspec (noinline)
void
WINAPI
SK_FAR_PSSetShaderResources (
Expand All @@ -1654,7 +1688,8 @@ SK_FAR_PSSetShaderResources (
_In_ UINT NumViews,
_In_opt_ ID3D11ShaderResourceView* const *ppShaderResourceViews )
{
static ID3D11ShaderResourceView* views [256];
std::vector <ID3D11ShaderResourceView *> views;
views.reserve (NumViews);

if (ppShaderResourceViews != nullptr)
{
Expand All @@ -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++)
Expand Down Expand Up @@ -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 ();
}
Expand Down

0 comments on commit 6e703a7

Please sign in to comment.