Voxels rendering : improve performances

Problems building or running the engine, queries about how to use features etc.
Post Reply
timjrd
Gnoblar
Posts: 4
Joined: Mon Feb 08, 2016 9:59 pm

Voxels rendering : improve performances

Post by timjrd »

Hi everyone :)

We are coding a voxel-based shooter game, this is our first experience with Ogre and in real-time 3D (I have done some OpenGL/GLSL but in 2D). I am trying to render a destroyable voxel-based cave with ManualObject. Voxels are stored as a simple 3D array divided into "batch" sections, each section corresponding to a ManualObject. When a voxel is modified I extract quads from the modified section and I update the corresponding ManualObject with the quads. It works, but we would like to improve the performances. I tried different section size, even a single big section, but for a large number of quads performances are not very good : with 10*10*10=1000 sections of 30*30*30=27000 voxels each (which seems a good ratio) and a total of 664082 quads I run with about 40FPS on my chipset and 80FPS on my GPU. How can we improve that ? Is there simply too many triangles ? We are using the default SceneManager.

Thanks :)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: Voxels rendering : improve performances

Post by dark_sylinc »

Please expand on how you're rendering because there's little information to guess where the problem is.

How many vertices you have per ManualObject? How many ManualObjects do you have? what do you mean by...?:
10*10*10=1000 sections of 30*30*30=27000 voxels each
Does that mean 1000 ManualObjects, with 27000 voxels in ManualObject? How many vertices does each voxel have? 8? 24? 36?

How complex is the pixel shader? (are you using pixel shaders?). How many textures do you use? What's the texture resolution? how many lights? (any lights?).

Without more info I have no idea how to help you.
timjrd
Gnoblar
Posts: 4
Joined: Mon Feb 08, 2016 9:59 pm

Re: Voxels rendering : improve performances

Post by timjrd »

dark_sylinc wrote:Does that mean 1000 ManualObjects, with 27000 voxels in ManualObject?
Yes, but only visible faces are rendered so in my test case there are on average 660 quads per ManualObject (so ~2640 vertices). Performances are similar with a single big ManualObject containing 2656328 vertices.
dark_sylinc wrote:How many vertices does each voxel have? 8? 24? 36?
If a voxel is entirely visible there are 24 vertices.
dark_sylinc wrote:How complex is the pixel shader? (are you using pixel shaders?). How many textures do you use? What's the texture resolution?
There is no custom pixel shader, no textures, only this simple voxel material :

Code: Select all

material voxel
{
    technique
    {
        pass
        {
            lighting on
            
            ambient  vertexcolour
            diffuse  vertexcolour
            specular vertexcolour
        }
    }
}

dark_sylinc wrote:how many lights? (any lights?).
In my test case there is only one light, but we will add many more.
qwertzui11
Halfling
Posts: 80
Joined: Wed May 14, 2008 10:44 am
Location: EU
x 22
Contact:

Re: Voxels rendering : improve performances

Post by qwertzui11 »

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: Voxels rendering : improve performances

Post by dark_sylinc »

I see.

There are a couple of things that could be going wrong. CPU side 1000 ManualObjects can be a lot for 1.x Ogre to handle, Ogre 2.1 is much, much better in that regard.

GPU & CPU side, the AABB of the ManualObject must be correctly set so that Ogre can cull entire chunks of ManualObjects that are not visible by the camera (frustum cull)

GPU side, your vertex count may be high. But more importantly, if you're updating the buffers frequently you may run into two problems:
  • ManualObject is a user-friendly system to build your own meshes; but it's not optimized for max performance. If you want the best performance, you will have to deal with modifying vertex buffers directly.
  • Frequent changes to the ManualObject if the buffers are static means a lot of API overhead discarding old buffers and allocating new memory. But if the buffers are dynamic, reconstructing so many vertices per object may be saturating the PCI-e bandwidth. In other words you need to profile, experiment by removing potential bottlenecks and see if performance improves, find all the problems & hotspots, and with all the data you gathered change to a smart approach for modifying the vertex buffers that is optimized for you kind of usage patterns.
timjrd
Gnoblar
Posts: 4
Joined: Mon Feb 08, 2016 9:59 pm

Re: Voxels rendering : improve performances

Post by timjrd »

qwertzui11 wrote:ever though about using existing frameworks like
OgreVolume http://www.ogre3d.org/forums/viewtopic.php?f=11&t=72895
http://voxelterrain.com/
http://www.volumesoffun.com/
?
We did consider to use PolyVox, but for now our game is mostly a toy project, and as it's our first 3D app with Ogre we don't really want to accumulate libs.
I didn't know about voxelterrain nor the GSoC project, they are both integrated with Ogre so this is good to know, thanks !
dark_sylinc wrote:GPU & CPU side, the AABB of the ManualObject must be correctly set so that Ogre can cull entire chunks of ManualObjects that are not visible by the camera (frustum cull)
Thank you for your advice. I first checked the AABB as it's the simplest thing to fix. getBoundingBox() seems to be OK, but getWorldBoundingBox() always returns min(-0.5, -0.5, -0.5) max(0.5, 0.5, 0.5) even if I setBoundingBox() manually, is it normal ? Do I have to attach the ManualObjects to individual SeneNodes or activate something in the SceneManager ? Currently they are all attached to the root SceneNode.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Voxels rendering : improve performances

Post by Kojack »

timjrd wrote:Currently they are all attached to the root SceneNode.
Culling is done on scene nodes. If you attach all the manual objects to the root node, then ogre can't cull the ones that are off screen.
timjrd
Gnoblar
Posts: 4
Joined: Mon Feb 08, 2016 9:59 pm

Re: Voxels rendering : improve performances

Post by timjrd »

I attached each ManualObject to a SceneNode and there is a huge performance boost : I'm now running at ~100FPS on my chipset instead of 40 ! Curiously I'm still at 80FPS on the GPU... For now it's sufficient.

Thank you all !
User avatar
Zonder
Ogre Magi
Posts: 1168
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 73

Re: Voxels rendering : improve performances

Post by Zonder »

timjrd wrote: Curiously I'm still at 80FPS on the GPU...
The driver might be limiting it.
There are 10 types of people in the world: Those who understand binary, and those who don't...
Post Reply