3D Voxel rendering
I'm working on a realtime terrain renderer by using voxels, could be nice to add to your games. I've uploaded a demo with source code and project files at
http://www.omnytex.com/pf/fileexchange/fileexchange.asp.
It is still too slow and the quality is not as good as it can be. I'll try to implement fixed point math which should speed it up, and bilinear filtering on the height map and the texture those should drastically improve the quality. Another thing is correcting the fish eye effect.
regards, Joost Bruneel
Thanks for sharing !
I saw something similar at FlipCode
I compiled for the x86em, but later I´m thinking about trying it on my cassiopeia to test the speed
Which version of PF does this need?
I tried to build the project after unzipping into my PF samples folder. I get lots of STL errors.
Also I can't see any code? Is it to do with the script?
ps: I'm very interested in a voxel terrain as my own polygon based one is too slow
Conan:look at
www.flipcode.com Jaccos tutorial about mobile 3d programming, in his first tutorial he explains basics of voxels and how to speed it up... you should be able to get good speed with it.
And of course any idea of using floatingpoint in voxel is terrible and will give awfull performace.
Conan,
You need pocketfrog 7, this is what I used to implement it. I only use default pocketfrog operations I guess, except maybe for the lockbuffer command.
Currently I'm working on the fixed point math, I hope to have it ready later on today.
Next thing is the bilinear filter. I do expect a real quality boost by this.
And to speed it up, I read somewhere about layered rendering, meaning :
- the pixels near the screen are rendered at full quality, so with the height and texture bil filtering
- a bit further you stop filtering (faster)
- and the far away pixels can be drawn with thicker spans (eg spans of 3 pixels).
It should work, and I'm pretty convinced we can achieve higher performance than polygon rendering for the same level of detail. (still need to prove it though).
If anyone has suggestions or ideas, feel free to post them
regards Joost
There it is, the fixed point version.(
http://www.omnytex.com/pf/fileexchange/ ... xel_fp.rar the new file is 'voxeldemo3.cpp'),
it should be possible to copy the whole directory structure to:
'C:\Windows CE Tools\frog\PocketFrog_0_7_0\samples\'.
I'm prety excited right now, cause the rendering speed is really good (iPaq 3850). I used 16:16 fixed point implementation.
There's even possibility for some more optimizing (can get rid of the mult for the rendering in the screen buffer).
If anyone wants some more explanation about the algorithm/math behind it, feel free to contact me.
All right, the speed is there, now let's go for quality ...
Oops, serious bug in the code,
fixed it, the patch can also be found at the download site.
The alg must remember for each column the highest span drawn (top screen row), by mistake a overwrote the maximum everytime with values that were sometimes too low, explaining the mountains that seemed to dance up and down.
It is even a bit faster now.
I have downloaded latest version plus fix plus PF7 & will get this working at lunch time.
If performance is good enough I will be interested in discussing use of the software in my next game.
30 minutes later..........
I built for arm & downloaded to my Axim. Performance of the demo is really good. There's one issue showing up with the height map ( the big white area seems to be too high).
I would be very interested in exploring this further as a module for my next game. My polygon terrain generator is not fast. I have a height map generator which creates terrain mathematically rather than from a bitmap. This is needed because I will have hundreds of planets with different terrain generated from a seed.
Conan,
You're right about the height map issue, the screen passes through the top of the white area, resulting in a strange effect on the screen, scaling down the heightmap with mountain_scale can help this.
I do have a new version meanwhile, faster (again), and with navigation through the map by means of the keys on the pocketpc (up = speed+, down speed-, left and right) and an FPS counter!
I would be very interested to see it actually running in a game. I will continue working on the improvement of the demo this week.
I'm also interested in the heightmap generator, I assume you use general pattern textures in that case to map on the height maps?
Hi,
I am also interested in your demo. I started a voxel demo myself a few weeks back after reading the first article of Jacco's series, but I never completed it.
I have a Casio E-125 (MIPS) and the demo is quite garbled on the screen. It appears that you are not using the pitch of the backbuffer when you calculate the offset in your draw routine.
Check this thread for some more info on the pitch: [url]http://www.pocketmatrix.com/forums/viewtopic.php?t=6586&highlight=pitch
[/url]
Otherwise, it seems to run smooth enough.
Pam
Pam, thanks a lot for the info,
I was even not aware of the pitch (shame on me).
I'll fix this right away.
By the way I've created a FPS counter on the screen and I noticed something very strange, when moving along the X-axis, it runs on my Ipaq at 12/13fps (on my friends Axim at 25/26fps!) when setting the angle to 90 degrees, it runs at 8/9fps on the ipaq, (on the axim also 8/9fps). The difference (factor 3 on axim) has definitely nothing to do with the math. when I copy a fixed value to the screen buffer it will work constantly at maximum fps, the problem should be somewhere in the texture lookup, in the tPix = texture[offset]; command according to some tests I've performed. Anyone an idea what could cause this drastic performance difference??
Hi Joost
My code uses a tga file in which there are numerous textured rectangles used to paint the meshes which make up the terrain. It's hopelessly slow compared to the Voxel technique.
The map generator is based on PC source code from the web. It generates islands or mainland & the seed number controls the No of hills etc.
I will download the latest version & have a look.
JoostB wrote:
the problem should be somewhere in the texture lookup, in the tPix = texture[offset]; command according to some tests I've performed. Anyone an idea what could cause this drastic performance difference??
I'll guess that it's probably a cache issue. See this thread where Refractor explains it prettly clearly,
http://www.pocketmatrix.com/forums/viewtopic.php?t=10614&highlight=cache
Chances are when you are at angle 90, you are reading the lines in the worst-case scenario. In other words, you read the pixel at texture[0] first, then instead of reading texture[1] next, you are reading texture[512], then texture[1024], etc. which aren't likely to be in the cache.
Pam
http://www.robot-frog.com/3d/hills/
This link is the article I used to get generated terrain (ie: not requiring a bitmap heightmap). This is in some ways better than my code as I ripped out the C++ stuff (classes etc).
The one thing that the Phantom does not mention is his article is reflections. His original PPC demo has nice reflections on the water.
While I don't want to give away too much about my next title in an open forum it involves terrains which change through time & via things the player does. If I can get a fast terrain engine working and a better 3D engine for the rest of the game then I will achieve my goal. (Of course I have about 6 months coding still left on STIII)
Joost, if you are interested in developing your demo into an actual terrain generator in a game I would be happy to discuss.
indeed Pam the performance difference must be due to this, did some further testing and yes at max fps I am moving in along with the pixel storage. hmmm guess can't do a lot about this
Any chance of posting the binaries? I am a long way from home (stuck in the middle of the USA of all places) and don't have my dev pc but i would like to have a look at it.
ta
Sean
Hi Sean, If no one else does so I can put up the arm binary tonight. What do you want, PPC 2002 ARM /
(stuck in Deepest USA eh!, watch out for Wendys, those pancakes will go for your waistline)
Arm 2002 0r 2003.
I think I have put on 10 pounds in 10 days :(.
Thanks
Sean
Thanks. That is pretty cool.
Guys,
If all goes well I will be improving the demo by the end of the weekend!
regards Joost
I'v implemented tiling for the heightmap and texture map, this seems to speed up things reasonably.
with tiling I mean in stead of storing the pixels sequentially row after row, I use tiles from eg 8x8 pixels, I have the impression this has a lot better (constant) effect on the texture lookup time, since there's more chance to have something in cache when you read the next texel,
optimized code for the ipaq38xx gives a constant 18fps
JoostB wrote:
I'v implemented tiling for the heightmap and texture map, this seems to speed up things reasonably.
with tiling I mean in stead of storing the pixels sequentially row after row, I use tiles from eg 8x8 pixels, I have the impression this has a lot better (constant) effect on the texture lookup time, since there's more chance to have something in cache when you read the next texel,
optimized code for the ipaq38xx gives a constant 18fps
What you should also do (in case you're not doing it already - since i haven't looked at the code) store the height and the color mixed up in the same buffer (16 bits color:16 bits height or vice versa) so you can read both information with only one instruction...
Hi Peter,
Indeed, I already do that, it is faster and causes less cache misses, since I'm reading more or less in a sequential way.
You will not find it in the posted source, this is one of the first implementations, meanwhile I've optimized the piece of code quite a bit
regards, Joost