From 3b61adefaae3c746c437947af8b583c4c6f676a6 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 5 Oct 2012 15:42:16 +0200 Subject: [PATCH] Work unclassing ambientOcclusionCalculator --- .../PolyVoxCore/AmbientOcclusionCalculator.h | 29 +++++++++++++++---- tests/TestAmbientOcclusionGenerator.cpp | 7 ++--- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h index f5b75bf4..8bf66df8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h @@ -68,6 +68,16 @@ namespace PolyVox polyvox_function m_funcIsTransparent; }; + class IsVoxelTransparent + { + public: + bool operator()(uint8_t voxel) + { + return voxel == 0; + } + }; + + template class AmbientOcclusionCalculatorRaycastCallback { public: @@ -77,12 +87,21 @@ namespace PolyVox bool operator()(const SimpleVolume::Sampler& sampler) { - return sampler.getVoxel() == 0; + //return sampler.getVoxel() == 0; + //return IsTransparentCallback(sampler.getVoxel()); + + uint8_t sample = sampler.getVoxel(); + + bool direct = sample == 0; + IsTransparentCallback funcToCall; + bool func = funcToCall(sample); + assert(direct == func); + return direct; } }; - template - void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, polyvox_function funcIsTransparent) + template + void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement/*, IsTransparentCallback funcIsTransparent*/) { Region m_region = region; typename VolumeType::Sampler m_sampVolume(volInput); @@ -96,7 +115,7 @@ namespace PolyVox uint16_t mRandomVectorIndex = 0; uint16_t mIndexIncreament; - polyvox_function m_funcIsTransparent = funcIsTransparent; + //polyvox_function m_funcIsTransparent = funcIsTransparent; //Make sure that the size of the volume is an exact multiple of the size of the array. assert(m_volInput->getWidth() % arrayResult->getDimension(0) == 0); @@ -167,7 +186,7 @@ namespace PolyVox ++uVisibleDirections; }*/ - MyRaycastResult result = raycastWithDirection(m_volInput, v3dRayStart, v3dRayDirection, AmbientOcclusionCalculatorRaycastCallback()); + MyRaycastResult result = raycastWithDirection(m_volInput, v3dRayStart, v3dRayDirection, AmbientOcclusionCalculatorRaycastCallback()); if(result == MyRaycastResults::Completed) { ++uVisibleDirections; diff --git a/tests/TestAmbientOcclusionGenerator.cpp b/tests/TestAmbientOcclusionGenerator.cpp index 18402c96..30dcdb16 100644 --- a/tests/TestAmbientOcclusionGenerator.cpp +++ b/tests/TestAmbientOcclusionGenerator.cpp @@ -30,10 +30,7 @@ freely, subject to the following restrictions: using namespace PolyVox; -bool isVoxelTransparent(uint8_t voxel) -{ - return voxel == 0; -} + void TestAmbientOcclusionGenerator::testExecute() { @@ -62,7 +59,7 @@ void TestAmbientOcclusionGenerator::testExecute() Array<3, uint8_t> ambientOcclusionResult(ArraySizes(g_uArraySideLength)(g_uArraySideLength)(g_uArraySideLength)); // Calculate the ambient occlusion values - calculateAmbientOcclusion(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255, isVoxelTransparent); + calculateAmbientOcclusion(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255/*, isVoxelTransparent*/); //Check the results by sampling along a line though the centre of the volume. Because //of the two walls we added, samples in the middle are darker than those at the edge.