Forum archive
voxel algorithm
- Hey Ken (or anybody else that knows something about voxels),
I was wondering what you thought of the way I render voxel slices. I came up with it
myself, although it probably exists already (I just haven’t read anything about it).
Just to get clear on this; with ‘slice’ I mean a 2D grid. For example a 32x32x32 voxel
model, has 32 slices of 32x32.
I take the 4 corners/vectors of each slice and transform them to screenspace. I then
interpolate between them so I don’t have to transform every voxel.
I know which voxels to draw because I shoot rays at 3 bitmaps (each representing an
angle of the model. In this order; top, side, front) you might want to include other angles
for coloring (such as back and bottom).
The code for rendering slices is here :
http://rafb.net/p/0hpuHu63.html
The var names aren’t really nice to look at, and I understand that you have better things to
do then study my code. But I would really appreciate it if you could take a quick look at
it, and tell me if such way is a good way to render voxels.
Even though it runs pretty smooth on a Gameboy Advance. I have no idea if this is a
good way of doing this, because I don’t really know any other way. Except for the brute
force way (transforming every voxel). Re: voxel algorithm
It's interesting that you are rendering directly from the 3 bitmaps. Having to check every voxel in a 3D grid will always be slow. You could speed it up by pre-generating some tables that let you skip over the transparent and interior voxels. These tables would basically be an array that holds a list of all the inputs (x,y,z,color) that you pass to your fillrect function.
My KV6 format does exactly this, with compression that works like this: Under each column (x,y), I have a list of surface voxels: (z,color), (z,color), .. Each column has a length byte telling how many surface voxels are in it. If your models are limited to 256^3 and you are using 8-bit color, then it would require: x*y + num_surfaces*2 bytes.- Thanks for the reply Ken. Your tip about the tables seems interesting, I’m currently
considering if I would implant it. The problem is most of my stuff is done on handhelds
(gameboy,mobilephone,etc) So I’m not sure if the speed advantage weights up against the
extra memory it takes with the tables (the bigger the models, the more memory I need).
I’m also writing some documentation/tutorial about my algorithm. Since I really haven’t
seen any good tutorial for doing ‘real’ 3D voxels. I will post a link to the tutorial when
it’s done :).
Thanks again Ken, for taking the time. voxel tutorial; need proof reading.
I've finally finished my first real article/tutorial. It's about realtime 3D voxel models
and how to render them.If you got some time to spare, I would really appreciate it if
you could read it and give your opinion.
If the article is good enough, I will probably post it on gamedev and some other sites.
Thanks in advance!
http://www.tremorsoftware.eu/articles/voxels.htmRe: voxel algorithm
In your tutorial, you should make it crystal clear that your algorithm is rendering directly from the front, top, and side views. This is what separates your method from every other voxel rendering method out there. I would include a screenshot of that car model you posted on these forums, along with its 3 source bitmaps.
I still think you should try a KVX style memory format. You would be shooting yourself in the foot by not following through. It would not require extra memory. In fact it could be less, depending on your choice of compression. Remember, you wouldn't need the original 3 bitmaps anymore.- I studied your KVX memory format. But I can’t seem understand why that would be
better (maybe I’m missing something?) I mean, it would make some if-checks (transparent voxel,color,etc)
obsolete in my render code. But would that really improve things drastically ? - For about the same amount of memory, you would get:
* a much faster loop that skips air and interior voxels
* support for any model shape - no symmetry requirements - Okay, I'm currently busy trying to implant it. My way is a little bit different, but I was
hoping if you could tell if I'm going the right way. This is some quick pseudo code that
hopefully explains how I want to implant it. As you can see I use start y and end y,
instead of z. this is mainly because it's easier with my rotation/transform functions.
/*
slab[][0] = x
slab[][1] = z
slab[][2] = start y
slab[][3] = end y
maxSlabZ[] = number of slabs for specific z axe.
*/
for(slicez = 0; slicez < VOXEL_MODEL_DEPTH; slicez++)
{
for(s = 0; s < maxSlabZ[slicez]; s++)
{
screen_x = slab[s][0] * (position formula);
for(y = slab[s][2]; y < slab[s][3]; y++)
{
screen_y = y * (position formula);
fillRect(screen_x,screen_y);
}
}
}
I’m sorry to bother you with only some ideas instead of code. But it’s very late where I
live and I’m on my way to bed. However, I’m planning to implant it tomorrow. So I was
hoping you could tell if I’m going the right way before I waste one day going in the
wrong direction :) thanks in advance, and thanks for all your help in general.Edited by Hugo Smits at - Yes, you are on the right track. You do not show where you would retrieve voxel colors from, but I assume you will figure that out.
- Hey Ken, the slab stuff is great. I haven't fully implanted it yet (wanted to do some
testing on smaller things first) After all tests are done I probably feel comfortable enough
to write a piece about it for the tutorial. Thanks again for your advice :) - okay I'm done! I've updated the tutorial (point 9 and 10) :
http://www.tremorsoftware.eu/articles/voxels.htm
Those slabs are great! My render loop runs more then double as fast :) - Somebody send me a pm. asking what happend to the article. I couldn't reply (because the system couldn't find the user :'()
So I will post my answer in this topic, even though this topic is older then 30 days. It may also be nice for other people in search
for the article :
I've changed my website. And as a result of that the url to the article changed. The new url is :
http://www.tremorsoftware.eu/articles/voxels/voxels.html
please note; that I'm currently making some changes (ie. gramma misstakes) in the article and will put the new version online soon.
To all, thanks for your intrest! - I think the PM is mine. Thanks for the reply. (I was out for a long time).