public void Execute(int index) { var voxelIndex = new VoxelIndex { Value = index }; var rootCoordiante = voxelLayout.GetCoordinatesFromVoxelIndex(voxelIndex); var originalSelfValue = sourceDiffusionValues[voxelIndex.Value]; float newValue = originalSelfValue; for (int adjacencyIndex = 0; adjacencyIndex < adjacencyVectors.Length; adjacencyIndex++) { var offset = adjacencyVectors[adjacencyIndex]; var sampleCoordinate = offset + rootCoordiante; var sampleIndex = voxelLayout.GetVoxelIndexFromCoordinates(sampleCoordinate); if (!sampleIndex.IsValid) { // if the index is outside of bounds, do no diffusion // this should have an effect of conserving all resources inside the bounds, none // should be lost or gained from the boundary conditions continue; } var sampleValue = sourceDiffusionValues[sampleIndex.Value]; var diffusionAdjustment = diffusionConstant; var diffuseAmount = (sampleValue - originalSelfValue) * diffusionAdjustment; newValue += diffuseAmount; } targetDiffusionValues[voxelIndex.Value] = newValue; }
public void Execute(int index) { if ((oneDimensionalKernel.Length - 1) % 2 != 0) { throw new System.Exception("kernel must be odd number length"); } Vector3Int axisVector; switch (diffuseAxis) { case DiffusionAxis.X: axisVector = new Vector3Int(1, 0, 0); break; case DiffusionAxis.Y: axisVector = new Vector3Int(0, 1, 0); break; case DiffusionAxis.Z: axisVector = new Vector3Int(0, 0, 1); break; default: throw new System.Exception("must specify diffuse axis"); } var voxelIndex = new VoxelIndex { Value = index }; var rootCoordiante = voxelLayout.GetCoordinatesFromVoxelIndex(voxelIndex); var kernelOrigin = oneDimensionalKernel.Length / 2; float newValue = 0; for (int kernelIndex = 0; kernelIndex < oneDimensionalKernel.Length; kernelIndex++) { var offset = axisVector * (kernelIndex - kernelOrigin); var kernelWeight = oneDimensionalKernel[kernelIndex]; var sampleCoordinate = offset + rootCoordiante; var sampleIndex = voxelLayout.GetVoxelIndexFromCoordinates(sampleCoordinate); float sampleValue; if (!sampleIndex.IsValid) { sampleValue = boundaryValue; } else { sampleValue = sourceDiffusionValues[sampleIndex.Value]; } newValue += sampleValue * kernelWeight; } targetDiffusionValues[voxelIndex.Value] = newValue; }