From 87dd98d4fa611bffffb6d9df7811f9ee049284f3 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 10 Dec 2011 06:59:32 +0000 Subject: [PATCH] Fix for material bug where ORing of material IDs was creating a new material ID, as one of the material IDs could be non-zero. --- .../include/PolyVoxCore/SurfaceExtractor.inl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl index 1f449cd6..456be614 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl @@ -442,7 +442,10 @@ namespace PolyVox Vector3DFloat v3dNormal = (n100*fInterp) + (n000*(1-fInterp)); v3dNormal.normalise(); - const uint32_t uMaterial = v000.getMaterial() | v100.getMaterial(); //Because one of these is 0, the or operation takes the max. + //Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of + //material IDs does not make sense). We take the largest, so that if we are working on a material-only + //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. + const uint32_t uMaterial = (std::max)(v000.getMaterial(), v100.getMaterial()); PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); @@ -465,7 +468,10 @@ namespace PolyVox Vector3DFloat v3dNormal = (n010*fInterp) + (n000*(1-fInterp)); v3dNormal.normalise(); - const uint32_t uMaterial = v000.getMaterial() | v010.getMaterial(); //Because one of these is 0, the or operation takes the max. + //Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of + //material IDs does not make sense). We take the largest, so that if we are working on a material-only + //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. + const uint32_t uMaterial = (std::max)(v000.getMaterial(), v010.getMaterial()); PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); @@ -488,7 +494,10 @@ namespace PolyVox Vector3DFloat v3dNormal = (n001*fInterp) + (n000*(1-fInterp)); v3dNormal.normalise(); - const uint32_t uMaterial = v000.getMaterial() | v001.getMaterial(); //Because one of these is 0, the or operation takes the max. + //Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of + //material IDs does not make sense). We take the largest, so that if we are working on a material-only + //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. + const uint32_t uMaterial = (std::max)(v000.getMaterial(), v001.getMaterial()); PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);