From 6ed2e7bbd18b893e0baf9fb93d09f024b6df4a72 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Sun, 28 Oct 2012 15:52:47 +0000 Subject: [PATCH] Add documentation for calculateAmbientOcclusion --- .../PolyVoxCore/AmbientOcclusionCalculator.h | 2 ++ .../PolyVoxCore/AmbientOcclusionCalculator.inl | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h index 0cbb08da..7d215c92 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h @@ -75,6 +75,8 @@ namespace PolyVox // This will be 'perfect forwarding' using 'universal references' // This will require C++11 rvalue references which is why I haven't made the // change yet. + + /// Calculate the ambient occlusion for the volume template void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, const IsVoxelTransparentCallback& isVoxelTransparentCallback); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl index bdb1237c..8659cadf 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl @@ -23,6 +23,14 @@ freely, subject to the following restrictions: namespace PolyVox { + /** + * \param volInput The volume to calculate the ambient occlusion for + * \param[out] arrayResult The output of the calculator + * \param region The region of the volume for which the occlusion should be calculated + * \param fRayLength The length for each test ray + * \param uNoOfSamplesPerOutputElement The number of samples to calculate the occlusion + * \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, const IsVoxelTransparentCallback& isVoxelTransparentCallback) { @@ -81,12 +89,12 @@ namespace PolyVox for(int ct = 0; ct < uNoOfSamplesPerOutputElement; ct++) { //We take a random vector with components going from -1 to 1 and scale it to go from -halfRatio to +halfRatio. - //This jitter value moves our sample point from the center of the array cell to somewhere else in the array cell - Vector3DFloat v3dJitter = randomVectors[(uRandomVectorIndex += (++uIndexIncreament)) % 1019]; //Prime number helps avoid repetition on sucessive loops. + //This jitter value moves our sample point from the centre of the array cell to somewhere else in the array cell + Vector3DFloat v3dJitter = randomVectors[(uRandomVectorIndex += (++uIndexIncreament)) % 1019]; //Prime number helps avoid repetition on successive loops. v3dJitter *= v3dHalfRatio; const Vector3DFloat v3dRayStart = v3dStart + v3dJitter; - Vector3DFloat v3dRayDirection = randomUnitVectors[(uRandomUnitVectorIndex += (++uIndexIncreament)) % 1021]; //Differenct prime number. + Vector3DFloat v3dRayDirection = randomUnitVectors[(uRandomUnitVectorIndex += (++uIndexIncreament)) % 1021]; //Different prime number. v3dRayDirection *= fRayLength; AmbientOcclusionCalculatorRaycastCallback ambientOcclusionCalculatorRaycastCallback(isVoxelTransparentCallback);