View Full Version : Pseudo 3d with bitmap as displacement for y-axis
Jerryscript
October 19th, 2007, 01:01 AM
I'm sure someone has already done something similar to this:
Using the basic focal length formula for simple 3d positioning of objects, I wanted a simple way to create a terrain. Creating a huge array of all the terrain points and elevations is tedious and time consuming. So, I thought, why not use a displacement map of sorts.
1-create a bitmap with a black background
2-draw an arial view of the terrain on the map, using an increase in the color value for each increase in elevation, so a mountain would be a collection of concentric circles with the color value increasing towards the peak of the mountain (topographical?)
3-when passing coordinates to the focal length formula, grab the pixel value of the bitmap at those coordinates and adjust the y value based upon the color returned, ie _y+=myBitmap.getPixel(x,z);
It seems to work great. Just wondering if anyone knows of any projects using such an idea, and if so, how does it perform under actual gaming conditions?
Jerryscript
October 20th, 2007, 02:30 PM
Turns out the concept is called a Voxel engine. I threw together a quick example, and it seems to work well. This is in AS1, and it looks like if the concept were done in AS 2 or 3, the speed might be fast enough to be usable in a game. Attached is an example SWF and a txt file containing the AS1 used.
Jerryscript
October 22nd, 2007, 12:02 PM
There have been some excellent examples of this technique posted if anyone is interested:
http://board.flashkit.com/board/showthread.php?p=3956815#post3956815
ArmoredSandwich
October 22nd, 2007, 12:18 PM
thats pretty awesome what you got there, and the stuff on the forum XD
Sirisian
October 22nd, 2007, 07:28 PM
http://www.sirisian.templarian.com/flash/flashIsoWave/flashIsoWave.html
you mean like real-time? It's possible to render 3D terrain in flash fairly easily if you know what you're doing.
What you want to do is just make a heightmap. From what you said you might already know what they are. Make a bitmap and perlin noise it (black and white). Use the values between 0 and 255 for your height. If you know how to render triangle strips you should be fine.
Jerryscript
October 22nd, 2007, 07:57 PM
Sirisian, you basically restated what I posted, in slightly different terms :)
I'm curious to see some actual examples of this in use, not just tests scripts, but games or other apps using a Voxel engine. Know of any?
Sirisian
October 22nd, 2007, 10:20 PM
http://en.wikipedia.org/wiki/Heightmap
Nah, I don't normally use flash much. I was just giving you the real name for the process you were using.
http://www.google.com/search?hl=en&q=Flash+heightmap&btnG=Google+Search
brings up this height-map terrain:
http://mx.coldstorageonline.com/temp/flash8/perlin-landscape.html
I will point out that voxel terrain is very CPU intensive. It's only real advantage is it's ability to be used for destructible terrain allowing burrowing and such. Something a height-map can't do.
Here's a voxel one:
http://lab.parkstudio.ru/terra/
You know what amazes me is that none of them added in cloud cover. It's a really easy thing to add in for real-time effects. But again those voxel ones are so CPU intensive that even in C++ and such they can barely run in real-time normally, however the ones that do run in real-time are very cool.
Do you want the code for rendering a heightmap via triangles? aka the real way to render terrain. The example at the bottom of the page you posted shows quads being rendered.
Jerryscript
October 22nd, 2007, 11:24 PM
Thanks again Sirisian. I will definitely look over the code, though it's a side project I'm working on for my godson, so I only work on it when I'm with him.
FYI- it's a slightly different kind of webcam based game. Most webcam games use motion detection based on a blend mode or something similar, and that returns data for all motion detected. This one uses a pen-light source in a dark room to move the cursor using thresholds, and we wanted a terrain for the enemies, which is what got me interested in the Voxel concept. Thanks again for the info!
Jerryscript
October 26th, 2007, 11:21 PM
I finally got a chance to work on what I was originally thinking of:
1- I create two bitmaps with perlinNoise, one for height mapping, one for color mapping
2- I render a perspective view by using the focal length formula and offsetting the y coordinate by the value of the height map, and setting the color with the color map
Note- steps one and two take up to 3 minutes to render depending on the size of the rendered cubes, to long for loading so....
3- I pass the pixel color values one row at a time to PHP/GD to convert the rendering to a PNG
4- I load the PNG and use the same perlinNoise height map to position objects via the focal length formula
Here are the sample files (the output to PHP/GD is disabled for viewing purposes), the Render example will take a long time and consume alot of resources!
Render (http://www.geocities.com/webwizardsways/flash/render.html)
Pre-Rendered (http://www.geocities.com/webwizardsways/flash/prerender.html)
Now I have to figure out a method for culling the objects. I'm thinking I can use the same perlinNoise function to create a set of masks, and set their layer such that objects going behind a hill will be masked appropriately. Any ideas for a better method?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.