Page 1 of 1
Lots of Boxes!
Posted: Fri Jul 16, 2010 7:54 am
by QJaxun
So i've just started playing around with irrlicht and its been a joy to work with so far. Ive got a lot of experience with making 2d games but this is the first time i've really been serious about starting up a 3d project, so forgive me if my question is a stupid one.
Id like to make a game where the levels are entirely made up of cubes, something like the game
http://minecraft.net/. The levels will be randomly generated and i need to be able to add and remove cubes during runtime (destructible/constructable terrain).
Ive tried simply adding a separate scene node for each of edit: 200 x 200 = 40,000 not 2000, cubes as a test but obviously take a huge performance hit. I guess im just looking for some advice on how to get started and as im new to 3d programming i don't even know what to search for.
This is how i've tried adding nodes:
Code: Select all
for(int z=0;z<200;z++)
{
for(int x=0;x<200;x++)
{
scene::ISceneNode * node = smgr->addCubeSceneNode();
if (node)
{
node->setPosition(core::vector3df(x*10,0,z*10));
node->setMaterialTexture(0, driver->getTexture("../media/t351sml.jpg"));
node->setMaterialFlag(video::EMF_LIGHTING, false);
}
}
}
Posted: Fri Jul 16, 2010 8:04 am
by serengeor
Since you will be using many cubes I would suggest not to use high resolution textures like 512x512. I think 128x128 should be fine.
You should also try to reduce draw calls (idea from other post
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=39154 )
Posted: Fri Jul 16, 2010 8:23 am
by ent1ty
Well but he wants to have it destructible so batching is probably not an option.
200x200= 40000 and not 2000, that's why it's so slow

Posted: Fri Jul 16, 2010 3:39 pm
by PI
Posted: Fri Jul 16, 2010 6:45 pm
by QJaxun
Awesome thanks for the replies. Id love to take a look at your example PI (sent you an email).
Looking forward for this and/or similar solutions
Posted: Sun Jul 18, 2010 1:46 pm
by blizuke
I've been wishing to find a solution for this for months now.
Please do share this, and/or any similar ways to do it.
It would be greatly appreciated! Thank-you.
Posted: Sun Jul 18, 2010 2:19 pm
by slavik262
PI wrote:Plus, it deletes all the invisible sides of the cubes and shows only the visible ones.
You didn't write code that does this yourself, did you? That's what backface culling does automatically.
Posted: Sun Jul 18, 2010 2:37 pm
by PI
I've sent you the code via emails guys!
You didn't write code that does this yourself, did you? That's what backface culling does automatically.
Sorry but first I laughed on this!
Fancy a big cube that is made out of a lot of small ones. Say 10x10x10, that is 1000 little cubes, each with 6 quads, that is 6000 quad = 12000 triangles. What you're saying is I should keep all these little pieces inside, what no one will ever see. Instead, I delete all the invisible sides, thus I get - to stick with the example - 10x10x6 = 600 visible quads thus 1200 triangles. Sounds a bit better than 12k ain't?

After that I send the whole thing up to the video card, to get hardware acceleration, plus the backface culling does it job as well. I also select those "block of cubes" can be seen to hide those are unnecessary to render.

Posted: Wed Jul 28, 2010 6:36 am
by QJaxun
Hey PI I have a couple questions for you.
1) Any tips on how to increase the speed of adding cubes. Ive made it add perfect cubes but when building really large maps (like over 64x64x64), even just a flat plane it takes quite awhile to build.
2) Any tips to increase render performance? When rendering a flat plane of boxes of size over 64x64 i get 15-40 fps and was wondering if there is anything i can do to speed things up.
Ive removed all the LDText code and cube selection stuff. Id like to have a view range of like 256 (so a map of like 512x512x128) cubes but with the slow build time and low fps that doesn't seem possible using the current code.
Posted: Wed Jul 28, 2010 11:57 am
by slavik262
PI wrote:I've sent you the code via emails guys!
You didn't write code that does this yourself, did you? That's what backface culling does automatically.
Sorry but first I laughed on this!
Fancy a big cube that is made out of a lot of small ones. Say 10x10x10, that is 1000 little cubes, each with 6 quads, that is 6000 quad = 12000 triangles. What you're saying is I should keep all these little pieces inside, what no one will ever see. Instead, I delete all the invisible sides, thus I get - to stick with the example - 10x10x6 = 600 visible quads thus 1200 triangles. Sounds a bit better than 12k ain't?

After that I send the whole thing up to the video card, to get hardware acceleration, plus the backface culling does it job as well. I also select those "block of cubes" can be seen to hide those are unnecessary to render.

Alright - I didn't understand what culling you were doing. Obviously doing your own algorithm here would be important for performance.
Posted: Thu Jul 29, 2010 6:47 am
by PI
QJaxun wrote:Hey PI I have a couple questions for you.
1) Any tips on how to increase the speed of adding cubes. Ive made it add perfect cubes but when building really large maps (like over 64x64x64), even just a flat plane it takes quite awhile to build.
2) Any tips to increase render performance? When rendering a flat plane of boxes of size over 64x64 i get 15-40 fps and was wondering if there is anything i can do to speed things up.
Ive removed all the LDText code and cube selection stuff. Id like to have a view range of like 256 (so a map of like 512x512x128) cubes but with the slow build time and low fps that doesn't seem possible using the current code.
1) You could cut the whole process into phases. Currently it creates new vertex positions; smooths them; calculates raw normals; calculates smooth normals; calculates texture coordinates; then adds cubes to the meshbuffer. As you can see, it can be split into smaller tasks. To make it visible, you could re-build the meshbuffer after a couple of changes. Then, do some other tasks, and re-build it again, ..., etc. You'll have a nice time synchronizing all these tasks, though!

I just have re-read you question again, and building such a large amount of cubes... you could then just add those sides that are needed, predefined normals and texture coords, etc. Predefined. Will be faster.
Or, you can optimize the whole stuff even more.
2) 64x64 is not much, you should have much more FPS than that. Does your video card support VBOs? I remember I had 1400+ FPS on my desktop and 150+ on my old laptop (which is really old)! Something is definately going wrong there!
Optimization could help here too. Especially regarding what you can see and what not.
That's all for now.
Cheers,
PI