Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

How to increase the extraction speed
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=401
Page 1 of 2

Author:  gamer8o4 [ Fri Jun 08, 2012 3:53 pm ]
Post subject:  How to increase the extraction speed

I want to create a voxel-based game with a very high amount of voxels.
Hopefully it will look like this:
http://www.youtube.com/watch?v=03zx1FZ5gsY

So my question, what is the fastest way to generate the terrain and extract it to the ogre-scenenode?

I use the cubicsurfaceextractor (without normals) and material8 (because i don't need density for now)

Author:  David Williams [ Fri Jun 08, 2012 8:30 pm ]
Post subject:  Re: How to increase the extraction speed

Well it's definitely possible because that demo uses PolyVox and Ogre. But are you saying you are actually finding the extraction speed to be too slow, or are you just curious?

How big are the regions you are extracting, and how long does it take? For each region you should work out how long the actual generation is taking (from Perlin noise?), how long the extraction is taking, and how long the upload to the GPU is taking. Then you can work out which part to optimise.

For interfacing PolyVox with Ogre the fastest approach is probably to use the HardwareBuffers directly, but I think most people just go through ManualObject.

Author:  gamer8o4 [ Sat Jun 09, 2012 9:48 am ]
Post subject:  Re: How to increase the extraction speed

For now there isn't a 'terrain' with multiple regions.
I only created a solid block in a 128x128x3 volume and this takes about 6 seconds to load.
By the way, your voxelins needs only 1-2 seconds for a bigger volume.

My code:
Code:
voldata = new SimpleVolume<PolyVox::Material8>(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(128, 2, 128)));

Code:
   
terrain->createChunkInVolume(voldata); // <<<< this creates the a solid block in the volume
   SurfaceMesh<PositionMaterial/*Normal*/> mesh;
   //CubicSurfaceExtractorWithNormals<SimpleVolume, PolyVox::Material8 > surfaceExtractor(voldata, voldata->getEnclosingRegion(), &mesh);
   PolyVox::CubicSurfaceExtractor<SimpleVolume, PolyVox::Material8> surfaceExtractor(voldata, voldata->getEnclosingRegion(), &mesh);
   surfaceExtractor.execute();
   /////
   Ogre::ManualObject* obj = App::getSceneManager()->createManualObject();

    uint32_t noVertices = mesh.getNoOfVertices();
    uint32_t noIndices = mesh.getNoOfIndices();

    obj->estimateVertexCount(noVertices);
    obj->estimateIndexCount(noIndices);

    obj->begin(/*"WireFrame"*/"ColouredCubicVoxel", Ogre::RenderOperation::OT_TRIANGLE_LIST);

   // vertexes
   const std::vector<PolyVox::PositionMaterial/*Normal*/>& vVertices = mesh.getVertices();
    for (unsigned int i=0; i<noVertices; i++) {
        const PolyVox::Vector3DFloat& pos = vVertices[i].getPosition();
        obj->position(pos.getX(), pos.getY(), pos.getZ());
        //const PolyVox::Vector3DFloat& normal = vVertices[i].getNormal();
        //obj->normal(normal.getX(), normal.getY(), normal.getZ());
    }

    // indices
   const std::vector<uint32_t>& vIndices = mesh.getIndices();
    for (unsigned int i=0; i<noIndices; i++) {
        obj->index( vIndices[i] );
    }

    obj->end();

    if ( node == NULL ) {
        node = App::getSceneManager()->getRootSceneNode()->createChildSceneNode();
    }
   node = App::getSceneManager()->getRootSceneNode()->createChildSceneNode();
    node->attachObject(obj);
    node->setScale(10.0, 10.0, 10.0);
    node->setPosition(pos);

Code:
void voxel::terrain::createChunkInVolume(SimpleVolume<PolyVox::Material8>* voldata){
   Vector3DFloat v3dVolCenter(voldata->getWidth() / 2, voldata->getHeight() / 2, voldata->getDepth() / 2);
   for (int z = 0; z < voldata->getWidth(); z++){
      for (int y = 0; y < voldata->getHeight(); y++){
         for (int x = 0; x < voldata->getDepth(); x++){
            Vector3DFloat v3dCurrentPos(x,y,z);
            voldata->setVoxelAt(x, y, z, 1);
         }
      }
   }
}

Author:  David Williams [ Sat Jun 09, 2012 6:10 pm ]
Post subject:  Re: How to increase the extraction speed

gamer8o4 wrote:
I only created a solid block in a 128x128x3 volume and this takes about 6 seconds to load.
This does sound a little slow, I guess I would expect it to take 1/10th of a second or so. But how much of the time is actually spend in the execute() functions, rather than loading data to the GPU for example. I think Ogre has a Timer class (?) so maybe you can use that around your call to execute() and print out the result?

Also, you are running a relese (not dubug) build, right?

Author:  gamer8o4 [ Sat Jun 09, 2012 6:48 pm ]
Post subject:  Re: How to increase the extraction speed

Quote:
Also, you are running a relese (not dubug) build, right?

oh, no :oops: after switching to it, it only takes 3 sec. (so doubled the speed)

[EDIT]
And about taking time the time, i am very new to ogre and don't know how :S
I programmed with Irrlicht until a week ago

Author:  David Williams [ Sun Jun 10, 2012 6:53 am ]
Post subject:  Re: How to increase the extraction speed

gamer8o4 wrote:
oh, no :oops: after switching to it, it only takes 3 sec. (so doubled the speed)

For what it's worth, this is probably the most commom performance problem for people using PolyVox. So it's always worth checking :-)

gamer8o4 wrote:
And about taking time the time, i am very new to ogre and don't know how :S

Ogre has a Timer class here: http://www.ogre3d.org/docs/api/html/cla ... Timer.html

I'm not sure exactly how you use it... I guess you create the object before your call to execute() and then call getMilliseconds() aterwards? If that doesn't work then maybe you can find an example on the Ogre forums.

Author:  gamer8o4 [ Sun Jun 10, 2012 6:42 pm ]
Post subject:  Re: How to increase the extraction speed

ok, got it to work:

filling the volume-data takes 2719 microseconds
and the extraction takes 3838843 microseconds

Author:  David Williams [ Mon Jun 11, 2012 7:51 pm ]
Post subject:  Re: How to increase the extraction speed

gamer8o4 wrote:
...and the extraction takes 3838843 microseconds


This is much too slow. I just timed the BasicExample which comes with PolyVox and the extraction of a 64x64x64 volume took 52 milliseconds. Are you able to run this example yourself? I added timing code as follows:

Code:
//Extract the surface
SurfaceMesh<PositionMaterialNormal> mesh;
CubicSurfaceExtractorWithNormals<SimpleVolume, MaterialDensityPair44 > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
QTime time;
time.start();
surfaceExtractor.execute();
std::cout << "Took " << time.elapsed() << "ms" << std::endl;

Author:  gamer8o4 [ Tue Jun 12, 2012 2:23 pm ]
Post subject:  Re: How to increase the extraction speed

Actually a haven't the time to compile it in in the next 2 days :S
But i looked through the basic example and a can't find any significantly differences in my code.
... or I am just blind ...

Author:  zprg [ Tue Jun 12, 2012 5:51 pm ]
Post subject:  Re: How to increase the extraction speed

How to increase the extraction speed - some ideas beside c++/polyvox:

1. if you use for example a 386'er PC with MS-DOS -> use a new PC with better cpu ;)
2. your harddrive is full -> check explorer in windows or command df -k in linux
3. your cpu is overheating -> check cputemperature in bios or with checkprograms
4. if you use a PC with windows xp -> check system->devicemanager->IDEcontroller->is it running in DMA mode or in PIO, if its PIO thats bad you should change to DMA5
5. your harddrive it totally fragmented -> use defragment programs to check and defragment
6. if you use a new PC with windows or linux -> check the systemprogram/resourcemonitor (windows) or command top(linux) for the processes that use the most cputime cause this are multitaskingoperatingsystems and its possible that there are processes that steal the cputime for example trojans. and you can check the open networkconnections with command netstat -an
7. if theres trojans/rootkits -> use checkprograms (from kaspersky, symantec etc), its good to run from bootcd or better format harddrive and after that install viruschecker and firewalls

Page 1 of 2 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/