diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h index 8bf66df8..d77458a7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h @@ -68,40 +68,31 @@ namespace PolyVox polyvox_function m_funcIsTransparent; }; - class IsVoxelTransparent - { - public: - bool operator()(uint8_t voxel) - { - return voxel == 0; - } - }; - - template + template class AmbientOcclusionCalculatorRaycastCallback { public: - AmbientOcclusionCalculatorRaycastCallback() + AmbientOcclusionCalculatorRaycastCallback(IsVoxelTransparentCallback isVoxelTransparentCallback) { + mIsVoxelTransparentCallback = isVoxelTransparentCallback; } bool operator()(const SimpleVolume::Sampler& sampler) { - //return sampler.getVoxel() == 0; - //return IsTransparentCallback(sampler.getVoxel()); - uint8_t sample = sampler.getVoxel(); - + bool direct = sample == 0; - IsTransparentCallback funcToCall; - bool func = funcToCall(sample); + bool func = mIsVoxelTransparentCallback(sample); assert(direct == func); + return direct; } + + IsVoxelTransparentCallback mIsVoxelTransparentCallback; }; - template - void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement/*, IsTransparentCallback funcIsTransparent*/) + template + void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback) { Region m_region = region; typename VolumeType::Sampler m_sampVolume(volInput); @@ -186,7 +177,11 @@ namespace PolyVox ++uVisibleDirections; }*/ - MyRaycastResult result = raycastWithDirection(m_volInput, v3dRayStart, v3dRayDirection, AmbientOcclusionCalculatorRaycastCallback()); + //IsVoxelTransparent isVoxelTransparent; + + AmbientOcclusionCalculatorRaycastCallback ambientOcclusionCalculatorRaycastCallback(isVoxelTransparentCallback); + + MyRaycastResult result = raycastWithDirection(m_volInput, v3dRayStart, v3dRayDirection, ambientOcclusionCalculatorRaycastCallback); if(result == MyRaycastResults::Completed) { ++uVisibleDirections; diff --git a/tests/TestAmbientOcclusionGenerator.cpp b/tests/TestAmbientOcclusionGenerator.cpp index 30dcdb16..65367da7 100644 --- a/tests/TestAmbientOcclusionGenerator.cpp +++ b/tests/TestAmbientOcclusionGenerator.cpp @@ -30,7 +30,14 @@ freely, subject to the following restrictions: using namespace PolyVox; - +class IsVoxelTransparent +{ +public: + bool operator()(uint8_t voxel) + { + return voxel == 0; + } +}; void TestAmbientOcclusionGenerator::testExecute() { @@ -59,7 +66,8 @@ 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*/); + IsVoxelTransparent 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.