diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h index c1310c4c..156601ee 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h @@ -31,6 +31,10 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Region.h" #include "PolyVoxCore/Raycast.h" +//These two should not be here! +#include "PolyVoxCore/Material.h" +#include "PolyVoxCore/SimpleVolume.h" + #include namespace PolyVox @@ -39,12 +43,16 @@ namespace PolyVox class AmbientOcclusionCalculator { public: - AmbientOcclusionCalculator(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement); + AmbientOcclusionCalculator(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement/*, polyvox_function funcIsTransparent*/); ~AmbientOcclusionCalculator(); void execute(void); private: + + //bool raycastCallback(const typename VolumeType::Sampler& sampler); + bool raycastCallback(const typename SimpleVolume::Sampler& sampler); + Region m_region; typename VolumeType::Sampler m_sampVolume; VolumeType* m_volInput; @@ -56,6 +64,8 @@ namespace PolyVox uint16_t mRandomUnitVectorIndex; uint16_t mRandomVectorIndex; uint16_t mIndexIncreament; + + polyvox_function m_funcIsTransparent; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl index 301ee0f2..e80b3911 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl @@ -24,7 +24,7 @@ freely, subject to the following restrictions: namespace PolyVox { template< template class VolumeType, typename VoxelType> - AmbientOcclusionCalculator::AmbientOcclusionCalculator(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement) + AmbientOcclusionCalculator::AmbientOcclusionCalculator(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement/*, polyvox_function funcIsTransparent*/) :m_region(region) ,m_sampVolume(volInput) ,m_volInput(volInput) @@ -33,6 +33,7 @@ namespace PolyVox ,m_uNoOfSamplesPerOutputElement(uNoOfSamplesPerOutputElement) ,mRandomUnitVectorIndex(0) //Although these could be uninitialised, we ,mRandomVectorIndex(0) //initialise for consistant results in the tests. + //,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); @@ -74,7 +75,7 @@ namespace PolyVox const Vector3DFloat v3dOffset(0.5f,0.5f,0.5f); RaycastResult raycastResult; - Raycast raycast(m_volInput, Vector3DFloat(0.0f,0.0f,0.0f), Vector3DFloat(1.0f,1.0f,1.0f), raycastResult); + Raycast raycast(m_volInput, Vector3DFloat(0.0f,0.0f,0.0f), Vector3DFloat(1.0f,1.0f,1.0f), raycastResult, polyvox_bind(&PolyVox::AmbientOcclusionCalculator::raycastCallback, this, std::placeholders::_1)); //This loop iterates over the bottom-lower-left voxel in each of the cells in the output array for(uint16_t z = m_region.getLowerCorner().getZ(); z <= m_region.getUpperCorner().getZ(); z += iRatioZ) @@ -131,4 +132,13 @@ namespace PolyVox } } } + + template< template class VolumeType, typename VoxelType> + //bool AmbientOcclusionCalculator::raycastCallback(const typename VolumeType::Sampler& sampler) + bool AmbientOcclusionCalculator::raycastCallback(const typename SimpleVolume::Sampler& sampler) + { + //VoxelType voxel = sampler.getVoxel(); + //return m_funcIsTransparent(voxel); + return sampler.getVoxel().getMaterial() == 0; + } }