• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
jellyfishchris

Voxel engine, storage of blocks

13 posts in this topic

I have just started working on a voxel engine for the fun of it. Ive managed to create the voxels and apply those with a texture atlas into a VBO. I have performed a few optimizations such as dont draw blocks you cant see etc etc.

 

I'm storing the blocks such as

 

Block m_blocks[16][128][16]; 
 

 

for each chunk.

 

However the problem arises when I want to have an infinite terrain. I found a few resources online saying I need to use hashmap and or loading/saving to external file for this. I would just like to clarify is this the correct approach additionally any advice/tips on how to go about it would be very appreciated.

 

Thanks

Edited by jellyfishchris
0

Share this post


Link to post
Share on other sites

if you are wanting to do something like Minecraft, then yes, saving the chunks to disk is probably a good idea.

 

also, given the potentially steep memory and storage costs that may pop up with voxel terrain, investigating the use of data-compression may also be a good idea.

 

FWIW: my engine uses compressed voxels both in their on-disk and in-memory format, typically decompressing and recompressing chunks as-needed (typically inactive chunks revert to a compressed form in-memory, and may be dynamically decompressed when the chunk is accessed).

 

at least for storage, Minecraft stores its chunks in a deflate-compressed form, typically also packaged up inside of "region" files (each of which hold a 32x32 grid of chunks).

1

Share this post


Link to post
Share on other sites

I think you should go with a octree format for voxel data storage. The concept with an octree is that say you have a 5x5x5 cube of dirt blocks (125 blocks). Rather than save each and every single one, wouldn't you rather just save one large block the same size? It sounds sorta complicated, but once you understand how it works in a whole, its actually pretty straight forward. 

 

I found this blog entry on the implementation of a Minecraft like game using octrees. It just so happens to also have some source code attached (at the bottom of the entry)... :) You might also want to see the rest of his entries as here as later he revises his octree format a bit.

0

Share this post


Link to post
Share on other sites

I have never implemented a voxel based engine, but instead of dense storage like this, why not try sparse storage like kdtrees or BVH and store blocks as cubes of 8x8x8 in the leaves ? (or some other constant adjusted emprically by try/measure).

The hash map idea is the same, but rather than a spatial tree structure (like kdtree/bvh) it would use location hashing.

There should not be much difference, both have imperfect densities, maybe the hash will be faster to access one leaf (because of amortized O(1) access) than the tree (O(log N)) but the neighborhood walking might be a tiny bit faster with the tree thanks to locality of storage (a brother is accessed through 2 indirections) but the need of rehash in the hash map solution makes neighborhood walking the same speed than random access in the first place. Sometimes walking is important (ray cast, collisions, volume fog...), it depends on what operation is more frequent. There are lots of ray tracing acceleration methods based on hybrids and mixes of many styles of acceleration structures, one of the most basic examples is Bresenham algorithm, it has optimization to walk super fast from cell to cell in a grid using ALU operations. The same idea exists in 3D with SSE and 3D grids, (called grid marching) some ray tracers are based on that. I recommend a bit of papers reading about that, even if they have nothing to do with voxels (purely structures for ray tracing purposes) it will still help to take decisions.

Such sparse structures will fill in memory for kilometers of terrain because basically, the storage requirement becomes a surface (and not a volume) * log(surface) for the tree solution. and * 1/charge factor for hash maps. For infinite worlds, it becomes possible to cluster in much larger sectors that gets streamd in/out on demand.

Also, there are ways to design super intelligent tree structures that you can access (read stream) partially and get a coarser LOD while not entirely read. (like progressive JPEG); like mip maps basically, same thing than the voxels of Cyril Crassin in the cone tracing paper, but thought for progressive serialization. this can be used for long range display, and fast stream in of distant clusters.

0

Share this post


Link to post
Share on other sites

I would explore the octree approach, though that also comes with its own challenges of figuring out how to represent the octree in a structure so as to make it efficient to store and read as well, because the number of octree leaves for each chunk can differ greatly from one another. 

 

Edit: Never mind, I realized you can store the octree data by assinging each leaf for each level a different number ID. This makes it much easier to understand and apply. All the solid areas can then be represented by the biggest leaf possible that encloses it by only storing these numbers. Numbering them, for example, starting with the top-most level (single leaf) is 0, next level down are 1-8, next level down 9 through 72, etc. Going down one level to subdivide a leaf by multiplying the current leaf's ID by 8, and then adding 1 through 8 to get the inner leaves.

Edited by CC Ricers
1

Share this post


Link to post
Share on other sites

Thanks guys I had a look at both the suggested ideas such as Octree and RLE. Which do you think is a better choice?

0

Share this post


Link to post
Share on other sites

RLE is better if there are a lot of the same types of blocks in a certain area. It keeps track of them in the following manner:

 

say you have 5 A blocks, 3 B blocks, and 1 C blocks) as follows:

AAAAABBBC

 

RLE would save that as:

5A3B1C

 

Notice that the Z takes up a single byte ('Z') in the first line, while it takes up two bytes ('1Z') in the second. This really becomes a problem when you encounter a lot of different object types.

 

In my opinion, Octrees are much more space and memory efficient, but they will be harder to parse (from the programmer's standpoint). The reason is that RLE must be decompressed in memory where as Octrees don't.

0

Share this post


Link to post
Share on other sites

RLE is better if there are a lot of the same types of blocks in a certain area. It keeps track of them in the following manner:

 

say you have 5 A blocks, 3 B blocks, and 1 C blocks) as follows:

AAAAABBBC

 

RLE would save that as:

5A3B1C

 

Notice that the Z takes up a single byte ('Z') in the first line, while it takes up two bytes ('1Z') in the second. This really becomes a problem when you encounter a lot of different object types.

 

In my opinion, Octrees are much more space and memory efficient, but they will be harder to parse (from the programmer's standpoint). The reason is that RLE must be decompressed in memory where as Octrees don't.

 

whether or not a single item takes 1 or 2 bytes depends on the type of RLE.

in many forms of RLE, a single item will usually only take a single byte.

 

for example, a PCX-like RLE:

0x00-0xBF: encoded directly

0xC0-0xFF: RLE run (1-64 bytes), followed by byte.

 

another strategy:

most bytes, passed through (except the escape byte).

0xFE=Escape byte

0xFE <count> <value> = RLE run

 

or, possibly, a compromise:

0x00-0xBF: passed through

0xC0-0xCF <value>: RLE run 1-16 (0xC0 <value> = Escaped Byte)

0xD0 <count> <value>: RLE Run (16-271)

0xD1 <count16> <value>: RLE Run (272-65536 / 65551)

0xD2-0xDF: reserved

0xE0-0xFF: passed through

 

 

in my engine, most of the voxel terrain is kept compressed in memory as well, but chunks may be decompressed on access, and revert to a compressed form later.

RLE is used here, mostly because it compresses/decompresses quickly.

 

block-level RLE can be faster than byte-level RLE, and avoids needing to flatten out or reconstitute the blocks (into a collection of "byte planes" or similar), but has the disadvantage that it doesn't compress as well (only blocks which are exactly the same may be compressed).

 

a more "fancy" idea I had also considered was basically doing something more PNG-like, basically using a Paeth predictor and Deflate, but this wouldn't be as usable for in-memory compression, due the higher encoding/decoding costs.

 

another trick is essentially skipping chunks which only contain a single type of voxel (such as air or stone), treating them like a single large block, but this works more in my engine because chunks are 16x16x16 (and stack vertically as well).

 

 

haven't personally messed with using octrees this way.

Edited by cr88192
1

Share this post


Link to post
Share on other sites

You're right, I forgot to mention that.

 

I personally use octrees all the time. I've only used RLE once in a really early project I did a few years back. I chose it over octrees back then since it was much easier to implement and I wasn't too comfortable with C++ at the time to work with octrees.

0

Share this post


Link to post
Share on other sites

You're right, I forgot to mention that.

 

I personally use octrees all the time. I've only used RLE once in a really early project I did a few years back. I chose it over octrees back then since it was much easier to implement and I wasn't too comfortable with C++ at the time to work with octrees.

 

Why do you use Octrees now?

0

Share this post


Link to post
Share on other sites

They both seem to have their advantages. RLE for describing the distribution of block types, and octrees for describing the actual volume all blocks take up for that chunk.

 

You can probably combine both ideas by using a single flat array delimited by the block type IDs, so the renderer knows what blocks to draw separately by texture.

 

I'm currently trying to make a voxel engine just for fun (maybe for a simple top-down shooting game), and taking advantage of the octree structure by drawing single, large cubes for the larger nodes instead of filling it all up with equal-sized cubes. The hardest thing for me right now is actually taking the node index to correctly position the cubes in 3D space.

0

Share this post


Link to post
Share on other sites

You're right, I forgot to mention that.

 

I personally use octrees all the time. I've only used RLE once in a really early project I did a few years back. I chose it over octrees back then since it was much easier to implement and I wasn't too comfortable with C++ at the time to work with octrees.

 

Why do you use Octrees now?

 

They are (in my opinion) more efficient for larger datasets. I use them mostly for terrain rendering as you are able to collapse the tree for father areas (less detail) and expand the tree for closer areas (more detail). I'm also experimenting with GigaVoxels and Voxel Cone-Tracing which both use octrees for efficient data storage and access.

0

Share this post


Link to post
Share on other sites

I understand the advantages of both just seem a little confused on what to do after reading...

 

http://www.sea-of-memes.com/LetsCode32/LetsCode32.html

and

http://0fps.wordpress.com/2012/01/14/an-analysis-of-minecraft-like-engines/

 

The first article is actually where it clicked how I would store the block-filling space as an octree. I did not actually look at the code samples from either. What are you having trouble with, storing the data or how to properly render the blocks on the screen?

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0