It is currently Sat Aug 22, 2020 1:44 pm


All times are UTC




Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to increase the extraction speed
PostPosted: Fri Jun 08, 2012 3:53 pm 

Joined: Fri Jun 01, 2012 5:31 pm
Posts: 11
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)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to increase the extraction speed
PostPosted: Fri Jun 08, 2012 8:30 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to increase the extraction speed
PostPosted: Sat Jun 09, 2012 9:48 am 

Joined: Fri Jun 01, 2012 5:31 pm
Posts: 11
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);
         }
      }
   }
}


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to increase the extraction speed
PostPosted: Sat Jun 09, 2012 6:10 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to increase the extraction speed
PostPosted: Sat Jun 09, 2012 6:48 pm 

Joined: Fri Jun 01, 2012 5:31 pm
Posts: 11
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to increase the extraction speed
PostPosted: Sun Jun 10, 2012 6:53 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to increase the extraction speed
PostPosted: Sun Jun 10, 2012 6:42 pm 

Joined: Fri Jun 01, 2012 5:31 pm
Posts: 11
ok, got it to work:

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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to increase the extraction speed
PostPosted: Mon Jun 11, 2012 7:51 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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;


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to increase the extraction speed
PostPosted: Tue Jun 12, 2012 2:23 pm 

Joined: Fri Jun 01, 2012 5:31 pm
Posts: 11
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 ...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How to increase the extraction speed
PostPosted: Tue Jun 12, 2012 5:51 pm 

Joined: Sun Jan 08, 2012 10:00 am
Posts: 31
Location: Germany
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


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net