From 413bb95b1ade1de6169d925ad0e1ade7898e8f96 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 30 Mar 2015 11:01:08 +0200 Subject: [PATCH 1/4] Passing parameter as const ref. --- include/PolyVox/AmbientOcclusionCalculator.h | 2 +- include/PolyVox/AmbientOcclusionCalculator.inl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/PolyVox/AmbientOcclusionCalculator.h b/include/PolyVox/AmbientOcclusionCalculator.h index bdd10de7..72f80bf1 100644 --- a/include/PolyVox/AmbientOcclusionCalculator.h +++ b/include/PolyVox/AmbientOcclusionCalculator.h @@ -74,7 +74,7 @@ namespace PolyVox /// Calculate the ambient occlusion for the volume template - void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback); + void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, const Region& region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback); } #include "PolyVox/AmbientOcclusionCalculator.inl" diff --git a/include/PolyVox/AmbientOcclusionCalculator.inl b/include/PolyVox/AmbientOcclusionCalculator.inl index be9db40e..cea5897a 100644 --- a/include/PolyVox/AmbientOcclusionCalculator.inl +++ b/include/PolyVox/AmbientOcclusionCalculator.inl @@ -32,7 +32,7 @@ namespace PolyVox * \param isVoxelTransparentCallback A callback which takes a \a VoxelType and returns a \a bool whether the voxel is transparent */ template - void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback) + void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, const Region& region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback) { //Make sure that the size of the volume is an exact multiple of the size of the array. if(volInput->getWidth() % arrayResult->getDimension(0) != 0) From d000616d3e933e5eb8159e7405c273cffb68a7f7 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 30 Mar 2015 11:24:48 +0200 Subject: [PATCH 2/4] Revert "Ambient occlusion test now uses RawVolume, as it need a fixed size volume to create a temporary array." This reverts commit 396d1cfc599e6837cf38bc1a95e680e9721ea844. --- include/PolyVox/AmbientOcclusionCalculator.h | 4 ++-- tests/TestAmbientOcclusionGenerator.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/PolyVox/AmbientOcclusionCalculator.h b/include/PolyVox/AmbientOcclusionCalculator.h index 72f80bf1..7f0fc5a4 100644 --- a/include/PolyVox/AmbientOcclusionCalculator.h +++ b/include/PolyVox/AmbientOcclusionCalculator.h @@ -33,7 +33,7 @@ freely, subject to the following restrictions: //These two should not be here! #include "PolyVox/Material.h" -#include "PolyVox/RawVolume.h" +#include "PolyVox/PagedVolume.h" #include @@ -53,7 +53,7 @@ namespace PolyVox { } - bool operator()(const RawVolume::Sampler& sampler) + bool operator()(const PagedVolume::Sampler& sampler) { uint8_t sample = sampler.getVoxel(); bool func = mIsVoxelTransparentCallback(sample); diff --git a/tests/TestAmbientOcclusionGenerator.cpp b/tests/TestAmbientOcclusionGenerator.cpp index 683d5c98..dcdab847 100644 --- a/tests/TestAmbientOcclusionGenerator.cpp +++ b/tests/TestAmbientOcclusionGenerator.cpp @@ -24,7 +24,7 @@ freely, subject to the following restrictions: #include "TestAmbientOcclusionGenerator.h" #include "PolyVox/AmbientOcclusionCalculator.h" -#include "PolyVox/RawVolume.h" +#include "PolyVox/PagedVolume.h" #include @@ -49,7 +49,7 @@ void TestAmbientOcclusionGenerator::testExecute() const int32_t g_uVolumeSideLength = 64; //Create empty volume - RawVolume volData(Region(0, 0, 0, g_uVolumeSideLength - 1, g_uVolumeSideLength - 1, g_uVolumeSideLength - 1)); + PagedVolume volData; //Create two solid walls at opposite sides of the volume for (int32_t z = 0; z < g_uVolumeSideLength; z++) From b415e5c5f383c3440533d83f10727073a59312ee Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 30 Mar 2015 11:44:25 +0200 Subject: [PATCH 3/4] calculateAmbientOcclusion() now works with both RawVolume and PagedVolume. --- include/PolyVox/AmbientOcclusionCalculator.h | 6 +++--- include/PolyVox/AmbientOcclusionCalculator.inl | 14 +++++++------- tests/TestAmbientOcclusionGenerator.cpp | 13 ++++++++++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/PolyVox/AmbientOcclusionCalculator.h b/include/PolyVox/AmbientOcclusionCalculator.h index 7f0fc5a4..2fded9f9 100644 --- a/include/PolyVox/AmbientOcclusionCalculator.h +++ b/include/PolyVox/AmbientOcclusionCalculator.h @@ -45,7 +45,7 @@ namespace PolyVox * Ambient occlusion */ - template + template class AmbientOcclusionCalculatorRaycastCallback { public: @@ -53,9 +53,9 @@ namespace PolyVox { } - bool operator()(const PagedVolume::Sampler& sampler) + bool operator()(const typename VolumeType::Sampler& sampler) { - uint8_t sample = sampler.getVoxel(); + auto sample = sampler.getVoxel(); bool func = mIsVoxelTransparentCallback(sample); return func; } diff --git a/include/PolyVox/AmbientOcclusionCalculator.inl b/include/PolyVox/AmbientOcclusionCalculator.inl index cea5897a..04ef6815 100644 --- a/include/PolyVox/AmbientOcclusionCalculator.inl +++ b/include/PolyVox/AmbientOcclusionCalculator.inl @@ -35,15 +35,15 @@ namespace PolyVox void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, const Region& region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback) { //Make sure that the size of the volume is an exact multiple of the size of the array. - if(volInput->getWidth() % arrayResult->getDimension(0) != 0) + if (region.getWidthInVoxels() % arrayResult->getDimension(0) != 0) { POLYVOX_THROW(std::invalid_argument, "Volume width must be an exact multiple of array width."); } - if(volInput->getHeight() % arrayResult->getDimension(1) != 0) + if (region.getHeightInVoxels() % arrayResult->getDimension(1) != 0) { POLYVOX_THROW(std::invalid_argument, "Volume width must be an exact multiple of array height."); } - if(volInput->getDepth() % arrayResult->getDimension(2) != 0) + if (region.getDepthInVoxels() % arrayResult->getDimension(2) != 0) { POLYVOX_THROW(std::invalid_argument, "Volume width must be an exact multiple of array depth."); } @@ -61,9 +61,9 @@ namespace PolyVox //nth 'random' value isn't always followed by the n+1th 'random' value. uIndexIncreament = 1; - const int iRatioX = volInput->getWidth() / arrayResult->getDimension(0); - const int iRatioY = volInput->getHeight() / arrayResult->getDimension(1); - const int iRatioZ = volInput->getDepth() / arrayResult->getDimension(2); + const int iRatioX = region.getWidthInVoxels() / arrayResult->getDimension(0); + const int iRatioY = region.getHeightInVoxels() / arrayResult->getDimension(1); + const int iRatioZ = region.getDepthInVoxels() / arrayResult->getDimension(2); const float fRatioX = iRatioX; const float fRatioY = iRatioY; @@ -104,7 +104,7 @@ namespace PolyVox Vector3DFloat v3dRayDirection = randomUnitVectors[(uRandomUnitVectorIndex += (++uIndexIncreament)) % 1021]; //Different prime number. v3dRayDirection *= fRayLength; - AmbientOcclusionCalculatorRaycastCallback ambientOcclusionCalculatorRaycastCallback(isVoxelTransparentCallback); + AmbientOcclusionCalculatorRaycastCallback ambientOcclusionCalculatorRaycastCallback(isVoxelTransparentCallback); RaycastResult result = raycastWithDirection(volInput, v3dRayStart, v3dRayDirection, ambientOcclusionCalculatorRaycastCallback); // Note - The performance of this could actually be improved it we exited as soon diff --git a/tests/TestAmbientOcclusionGenerator.cpp b/tests/TestAmbientOcclusionGenerator.cpp index dcdab847..9a2fb411 100644 --- a/tests/TestAmbientOcclusionGenerator.cpp +++ b/tests/TestAmbientOcclusionGenerator.cpp @@ -24,7 +24,9 @@ freely, subject to the following restrictions: #include "TestAmbientOcclusionGenerator.h" #include "PolyVox/AmbientOcclusionCalculator.h" +#include "PolyVox/FilePager.h" #include "PolyVox/PagedVolume.h" +#include "PolyVox/RawVolume.h" #include @@ -47,9 +49,14 @@ bool isVoxelTransparentFunction(uint8_t voxel) void TestAmbientOcclusionGenerator::testExecute() { const int32_t g_uVolumeSideLength = 64; + Region region(0, 0, 0, g_uVolumeSideLength - 1, g_uVolumeSideLength - 1, g_uVolumeSideLength - 1); //Create empty volume - PagedVolume volData; + RawVolume volData(region); + + // To test with a PagedVolume instead you can comment ou the above line and use these instead. + // FilePager* pFilePager = new FilePager("."); + // PagedVolume volData(pFilePager, 256 * 1024 * 1024, 32); //Create two solid walls at opposite sides of the volume for (int32_t z = 0; z < g_uVolumeSideLength; z++) @@ -73,7 +80,7 @@ void TestAmbientOcclusionGenerator::testExecute() // Calculate the ambient occlusion values IsVoxelTransparent isVoxelTransparent; QBENCHMARK { - calculateAmbientOcclusion(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255, isVoxelTransparent); + calculateAmbientOcclusion(&volData, &ambientOcclusionResult, region, 32.0f, 255, isVoxelTransparent); } //Check the results by sampling along a line though the centre of the volume. Because @@ -85,7 +92,7 @@ void TestAmbientOcclusionGenerator::testExecute() QCOMPARE(static_cast(ambientOcclusionResult(16, 31, 16)), 173); //Just run a quick test to make sure that it compiles when taking a function pointer - calculateAmbientOcclusion(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 8, &isVoxelTransparentFunction); + calculateAmbientOcclusion(&volData, &ambientOcclusionResult, region, 32.0f, 8, &isVoxelTransparentFunction); //Also test it using a lambda //calculateAmbientOcclusion(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 8, [](uint8_t voxel){return voxel == 0;}); From 5847219331026d43d759ca0f50e41fcc6d703a2f Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 30 Mar 2015 15:36:28 +0200 Subject: [PATCH 4/4] Fixed bug with chunk timestamp not being updated. --- include/PolyVox/PagedVolume.inl | 1 + 1 file changed, 1 insertion(+) diff --git a/include/PolyVox/PagedVolume.inl b/include/PolyVox/PagedVolume.inl index 57bf70c8..3afc3d1e 100644 --- a/include/PolyVox/PagedVolume.inl +++ b/include/PolyVox/PagedVolume.inl @@ -282,6 +282,7 @@ namespace PolyVox // The chunk was found so we can use it. pChunk = itChunk->second.get(); POLYVOX_ASSERT(pChunk, "Recent chunk list shold never contain a null pointer."); + pChunk->m_uChunkLastAccessed = ++m_uTimestamper; } // If we still haven't found the chunk then it's time to create a new one and page it in from disk.