I have a bit of a hard time sorting my voxels/slabs. I want to do it without a z-buffer. I tried several approaches, but it seems there are aways little glitches/bugs. has anybody found a neat/clean/fast way of doing this ?
thanks in advance!
Awesoken at
Re: how can I sort slabs/voxels ?
Sure. Slab6 doesn't use a Z-buffer and sorts voxels in back to front order without glitches. Check out rendercube() of SLAB6.C. I'll explain how it works. First, you solve the x,y,z coordinate of your camera's position in voxel coordinates. If (x < 0), then draw plane x=xsiz-1 first and x=0 last. If (x >= xsiz) then loop from 0 to xsiz-1. If (0 <= x < xsiz), then you loop from 0 to x-1, xsiz-1 to x+1, and finally render x. If you do this same ordering for all 3 axes, and handle all 27 cases properly, you'll get a glitch-free rendering of a voxel grid. Unfortunately, this sorting trick only works if you're rendering a single voxel model.
0xC0DE at
that's the methode I used! heh.. I found out my glitches weren't from the sorting itself. But rather from my lousy sin/cos lookup table (only 256 entries). sometimes the slabs crossed each other (due to flawed precision of rotation/sin/cos) at 1 end and that created the glitches. Seems stupid I didn't realise it sooner. Now I waste a good day debuggen code that wasn't corrupt in the first place :(