I am experimenting with the material ids now.
with cubic extractor I don't have problems, but with the MArching Cubes I get somehow non-perfectly-smooth result. How can I fix that?
Attachment:
mids.jpg [ 53.19 KiB | Viewed 10268 times ]
Attachment:
mids2.jpg [ 57.12 KiB | Viewed 10268 times ]
Useful snippets:
Code:
SVT& SVT::operator +(const SVT &other)
{
if(this->material==0) this->material = other.material;
this->density += other.density;
return *this;
}
SVT& SVT::operator -(const SVT &other)
{
if(this->material==0) this->material = other.material;
this->density -= other.density;
return *this;
}
SVT& SVT::operator /(const int &other)
{
this->density /= other;
return *this;
}
/**/
SVT& SVT::operator +=(const SVT &other)
{
if(this->material==0) this->material = other.material;
this->density += other.density;
return *this;
}
SVT& SVT::operator -=(const SVT &other)
{
if(this->material==0) this->material = other.material;
this->density -= other.density;
return *this;
}
SVT& SVT::operator /=(const int &other)
{
this->density /= other;
return *this;
}
...
//Smooth chunk
RawVolume<SVT> tempVolume(Region(-1,-1,-1,c->sx+1,c->sy+1,c->sz+1));
LowPassFilter< RawVolume<SVT>, RawVolume<SVT>, SVT >
lpf(c->voxdata, Region(-1,-1,-1,c->sx+1,c->sy+1,c->sz+1),
&tempVolume, Region(-1,-1,-1,c->sx+1,c->sy+1,c->sz+1),
3);
lpf.execute();
MarchingCubesSurfaceExtractor< RawVolume<SVT>, PGFMarchingCubesController >
ext2(&tempVolume, Region(0,0,0,c->sx,c->sy,c->sz), c->newmesh);
ext2.execute();
...
for(uint32_t i = 0; i < vertices.size(); i++)
{
const PolyVox::PositionMaterialNormal& vertex = vertices.at(i);
const MaterialAlpha& ma = vertex_extra_data.at(i);
PolyVox::Vector3DFloat vertex_pos = vertex.getPosition();
no->position(vertex_pos.getX(), vertex_pos.getY(), vertex_pos.getZ());
no->normal(vertex.getNormal().getX(), vertex.getNormal().getY(), vertex.getNormal().getZ());
Ogre::Vector4 color;
int mid = vertex.getMaterial();
switch(mid)
{
case 0: color = Ogre::Vector4( 0 , 0 , 0 , 0 ); break;
case 1: color = Ogre::Vector4( 0 , 0 , 0 , 1 ); break;
case 2: color = Ogre::Vector4( 0 , 0 , 1 , 0 ); break;
case 3: color = Ogre::Vector4( 0 , 0 , 1 , 1 ); break;
case 4: color = Ogre::Vector4( 0 , 1 , 0 , 0 ); break;
case 5: color = Ogre::Vector4( 0 , 1 , 0 , 1 ); break;
case 6: color = Ogre::Vector4( 0 , 1 , 1 , 0 ); break;
case 7: color = Ogre::Vector4( 0 , 1 , 1 , 1 ); break;
case 8: color = Ogre::Vector4( 1 , 0 , 0 , 0 ); break;
case 9: color = Ogre::Vector4( 1 , 0 , 0 , 1 ); break;
case 10: color = Ogre::Vector4( 1 , 0 , 1 , 0 ); break;
case 11: color = Ogre::Vector4( 1 , 0 , 1 , 1 ); break;
case 12: color = Ogre::Vector4( 1 , 1 , 0 , 0 ); break;
case 13: color = Ogre::Vector4( 1 , 1 , 0 , 1 ); break;
case 14: color = Ogre::Vector4( 1 , 1 , 1 , 0 ); break;
case 15: color = Ogre::Vector4( 1 , 1 , 1 , 1 ); break;
}
no->colour(color.x,color.y,color.z,color.w);
...
Shaders:
struct vsout
{
float4 op: POSITION; // Transformed vertex position
float3 uv: TEXCOORD0; // UV0
float3 nm: TEXCOORD1;
float4 cl: COLOR;
};
vsout vert(
// Vertex Inputs
float4 position : POSITION, // Vertex position in model space
float3 texCoord0 : TEXCOORD0, // Texture UV set 0
float3 normal : NORMAL,
float4 color : COLOR,
// Model Level Inputs
uniform float4x4 WVPMAT
)
{
vsout o;
float4 p = mul(WVPMAT, position);
o.op = p;
o.nm = normal;
o.uv = position.xyz /1 * float3(-1,1,1) + 0.5;
o.cl = color;
return o;
}
void frag(
// Pixel Inputs
float3 pos : TEXCOORD0, // UV interpolated for current pixel
float3 vnormal : TEXCOORD1,
float4 col : COLOR, // the encoded material id
// Outputs
out float4 color : COLOR, // Output color we want to write
// Model Level Inputs
uniform sampler2D texture) // Texture we're going to use
{
color = col - (1-pos.z/70)+0.4;
}