Changed he way that materials are blended by default, such that the material of the voxel with the highest density is used.

This commit is contained in:
David Williams 2014-03-06 16:38:57 +01:00
parent 1cf5f4c899
commit 163e520e9f
4 changed files with 17 additions and 29 deletions

View File

@ -108,18 +108,18 @@ namespace PolyVox
*
* The Marching Cubes algotithm generates vertices which lie between voxels, and ideally the material of the vertex should be interpolated from the materials
* of the voxels. In practice, that material type is often an integer identifier (e.g. 1 = rock, 2 = soil, 3 = grass) and an interpolation doean't make sense
* (e.g. soil is not a combination or rock and grass). Therefore this default interpolation just return one material or the other, but if more advanced voxel
* types do support interpolation then it can be implemented in this function.
* (e.g. soil is not a combination or rock and grass). Therefore this default interpolation just returns whichever material is associated with a voxel of the
* higher density, but if more advanced voxel types do support interpolation then it can be implemented in this function.
*/
MaterialType blendMaterials(MaterialType a, MaterialType b, float weight)
MaterialType blendMaterials(VoxelType a, VoxelType b, float /*weight*/)
{
if(weight < 0.5f)
if(convertToDensity(a) > convertToDensity(b))
{
return a;
return convertToMaterial(a);
}
else
{
return b;
return convertToMaterial(b);
}
}

View File

@ -168,7 +168,7 @@ namespace PolyVox
return 1;
}
MaterialType blendMaterials(MaterialType /*a*/, MaterialType /*b*/, float /*weight*/)
MaterialType blendMaterials(Density<Type> /*a*/, Density<Type> /*b*/, float /*weight*/)
{
return 1;
}

View File

@ -456,12 +456,8 @@ namespace PolyVox
v3dNormal.normalise();
}
//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 typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
const typename Controller::MaterialType uMaterial100 = m_controller.convertToMaterial(v100);
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial100, fInterp);
// Allow the controller to decide how the material should be derived from the voxels.
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v100, fInterp);
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
@ -489,12 +485,8 @@ namespace PolyVox
v3dNormal.normalise();
}
//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 typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
const typename Controller::MaterialType uMaterial010 = m_controller.convertToMaterial(v010);
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial010, fInterp);
// Allow the controller to decide how the material should be derived from the voxels.
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v010, fInterp);
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
@ -521,12 +513,8 @@ namespace PolyVox
v3dNormal.normalise();
}
//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 typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000);
const typename Controller::MaterialType uMaterial001 = m_controller.convertToMaterial(v001);
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial001, fInterp);
// Allow the controller to decide how the material should be derived from the voxels.
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v001, fInterp);
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);

View File

@ -132,15 +132,15 @@ namespace PolyVox
return voxel.getMaterial();
}
MaterialType blendMaterials(MaterialType a, MaterialType b, float weight)
MaterialType blendMaterials(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> a, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> b, float /*weight*/)
{
if(weight < 0.5f)
if(convertToDensity(a) > convertToDensity(b))
{
return a;
return convertToMaterial(a);
}
else
{
return b;
return convertToMaterial(b);
}
}