I haven't actually worked with pure colors in conjunction with the marching cubes surface extractor, but in principle it should work. Firstly though, are you using the last release of PolyVox (0.2.1) or the latest develop version from Git? What I say below applies to the develop version. You may be able to adjust it for the last stable release but I'm a bit hazy as to exactly what has changed.
Anyway, a key issue will be the way that the vertex's color/material is chosen based on it's neighbours. A vertex is always positioned between two voxels and gets it color/material by sampling them. You can see this in the code:
Code:
// Allow the controller to decide how the material should be derived from the voxels.
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v100, fInterp);
Now, most people use PolyVox with 'material IDs', and in general there is no sensible way to blend between them. The default implementation just picks one based on the density:
Code:
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> blendMaterials(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> a, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> b, float /*weight*/)
{
if(convertToDensity(a) > convertToDensity(b))
{
return a;
}
else
{
return b;
}
}
But if you have colors then you *can* blend between then. To test, you can probably do this by editing the function above (found in MateriaDensityPair.h). Something like:
Code:
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> blendMaterials(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> a, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> b, float /*weight*/)
{
// Untested pseudocode!
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> result;
result.Red = (a.Red + b.Red) / 2.0 // Note: Probably convert to floats first?
result.Green = ...
result.Blue = ...
return result;
}
If you can get this to work then later you can make a proper 'Color' voxel type by duplicating MaterialDensityPair and modifying it to your needs.
@petersvp - I think this is different to your problem because colors can be interpolated whereas material IDs cannot. But I'm not certain... let's see what happens.