Fast Cube Rendering

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Elfinitiy
Posts: 21
Joined: Thu May 26, 2011 10:23 am

Fast Cube Rendering

Post by Elfinitiy »

How to render cubes like in this game http://irrlicht.sourceforge.net/forum/v ... t=minetest.

What's the fastest way ?
I tried something like this

Code: Select all

vdr->drawVertexPrimitiveList(verts,3,indices,3,video::E_VERTEX_TYPE::EVT_STANDARD,
                        scene::EPT_TRIANGLES);
but i don't know if its well enough when i have a lot of cubes
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Fast Cube Rendering

Post by hybrid »

Just use the search button and see what many others already proposed for this.
Elfinitiy
Posts: 21
Joined: Thu May 26, 2011 10:23 am

Re: Fast Cube Rendering

Post by Elfinitiy »

The only answer i found is

Code: Select all

mesh batching
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Fast Cube Rendering

Post by hybrid »

Yes, this will be one of the best options. HW instancing is also good, but usually inferior to batching.
Elfinitiy
Posts: 21
Joined: Thu May 26, 2011 10:23 am

Re: Fast Cube Rendering

Post by Elfinitiy »

But will this option

Code: Select all

vdr->drawVertexPrimitiveList(verts,3,indices,3,video::E_VERTEX_TYPE::EVT_STANDARD,
                        scene::EPT_TRIANGLES);
Be as good for the purpose of making a Minecraft-like game ?
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Fast Cube Rendering

Post by hybrid »

No, because you need one render call per box. You won't get over a few hundred boxes with this method. As said in those posts about batching...
Elfinitiy
Posts: 21
Joined: Thu May 26, 2011 10:23 am

Re: Fast Cube Rendering

Post by Elfinitiy »

Thank you for the reply (:
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Fast Cube Rendering

Post by devsh »

howabout make a vertex buffer full of points where you want your boxes spawned(all have to be same material). One point per box, vertex position as cube position.
Create a geometry shader with input Primitive type = EPT_POINTS and output EPT_QUADS and make 6 quads around your point (same size since you have a minecraft-like game). The best thing is that you don't need to set transform matrices and you need 6x less data than mesh batching (and no index lists).
Storing all vertices and indices for a cube takes 24 vertices (for correct lighting), and 12 indices. Using simplest irrlicht vertex type this means (4*4+4+3*4+2*4)*24+48==1008 bytes. However if you want to use pseudo instancing, you have to use up one more texcoord for instance index, so we hit 1008+24*8= 1200bytes. You can use 64kb vertex cache for post transform, this means that the max amount of vertices you can send to vertex shader is 1600, meaning 66 cubes==396 polygons per draw call. that would be a plane of 8x8 cubes, or about one tree made of cubes. with the geometry shaders you use one vertex per cube which means outputting 1600 cubes is possible== 9600 polygons per draw call.

An even more hardcore solution would be to use a kind of "compression". Since the geom shader can output 1024 floats == 256 vertex positions == 64 quads == 10 cubes. you could define a square/rectange of cubes to be created per vertex. That is 60x less data, and 14400 cubes at once.

The most hardcore solution would enable you to draw arbitrary amounts of cubes. Take a height map, 128x128 pixels. Take 4 vertices making two triangles, tesselate with OpenGL tessellation (search my post), you will have 1056*3*4 vertices for FREE. Then you just happen to have a vertex ALMOST (122x122) per every pixel(remember to tessellate triangles, but output points into geom shader from tessellation evaluation). Then read off the height map in geom shader, round the height to nearest CUBE height and spawn a cube at that point using the geom shader. THAT'S 112000 cubes, 1.2 million polygons without filling up any shader uniforms, and submitting only 184 bytes of data to the gpu!

Don't even get me started on whatIF you used 24x24x2 triangles and a 4096x4096 heightmap!!!
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: Fast Cube Rendering

Post by shadowslair »

There`re so many minecraft clones the last 6 months, that I personally am tired hearing of them, not to mention playing them. But at the moment I see a minecraft clone game using up to 128x128 pixel textures and simplistic lighting, and using geom shaders+tesselation+instancing+MTHNHA* for such simplfied style design and all, well then, I`ll be sure game art had entered a new age and this will definitely be sth new...

* MTHNHA = Many Things Humanity Had Never Heard About
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Post Reply