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);