diff --git a/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h b/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h index 7be8dc9e..892b8004 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h +++ b/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h @@ -103,6 +103,18 @@ namespace PolyVox return 1; } + MaterialType blendMaterials(MaterialType a, MaterialType b, float weight) + { + if(weight < 0.5f) + { + return a; + } + else + { + return b; + } + } + /** * Returns the density value which was passed to the constructor. * diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 8869b094..72248fda 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -168,6 +168,11 @@ namespace PolyVox return 1; } + MaterialType blendMaterials(MaterialType /*a*/, MaterialType /*b*/, float /*weight*/) + { + return 1; + } + DensityType getThreshold(void) { return m_tThreshold; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl index 69e0b9cd..4a4db219 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl @@ -461,7 +461,7 @@ namespace PolyVox //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000); const typename Controller::MaterialType uMaterial100 = m_controller.convertToMaterial(v100); - const typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial100); + const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial100, fInterp); const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); @@ -494,7 +494,7 @@ namespace PolyVox //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000); const typename Controller::MaterialType uMaterial010 = m_controller.convertToMaterial(v010); - const typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial010); + const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial010, fInterp); const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); @@ -526,7 +526,7 @@ namespace PolyVox //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000); const typename Controller::MaterialType uMaterial001 = m_controller.convertToMaterial(v001); - const typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial001); + const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial001, fInterp); const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index cdde07f7..6f9e2d11 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -132,6 +132,18 @@ namespace PolyVox return voxel.getMaterial(); } + MaterialType blendMaterials(MaterialType a, MaterialType b, float weight) + { + if(weight < 0.5f) + { + return a; + } + else + { + return b; + } + } + DensityType getThreshold(void) { return m_tThreshold; diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 45c0958a..796f3b2c 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -55,6 +55,11 @@ public: return 1; } + float blendMaterials(float /*a*/, float /*b*/, float /*weight*/) + { + return 1; + } + float getThreshold(void) { return 50.0f;