This works for both the full version and the free version, since the free version allows up to 4 terrains to be loaded at once.
This demo shows how you can take a large edge wrapped heightmap from L3DT Pro, break it into pieces, and make a continuous never ending terrain with it.
The heightmap is a 4096 x 4096 color heightmap saved in RAW format using L3DT Pro, then converted to a BMP using Kaedroho's conversion code.
`
` Convert a RAW heightmap to a color heightmap BMP for use in Blitzwerks Terrain
`
sync on: sync rate 0
//Variables
RAWFileName as string
RAWFileSize as integer
ImageSize as integer
i# as float
//Get info
RAWFileName="heightmap.raw"
RAWFileSize=file size(RAWFileName)
ImageSize=sqrt(RAWFileSize/2)
i# = ImageSize
//Open raw file
if file exist("heightmap.raw")
open to read 1,RAWFileName
else
cls
center text screen width()/2, screen height()/2, "Heightmap.raw file missing."
sync
wait key
end
endif
//Create memblock
make memblock 1,12+ImageSize*ImageSize*4
write memblock dword 1,0,ImageSize
write memblock dword 1,4,ImageSize
write memblock dword 1,8,32
//Copy image data
for y=0 to ImageSize-1
cls
p# = (((y + 1) / i#) * 100)
center text screen width()/2, screen height()/2, str$(p#,0)+" %"
sync
for x=0 to ImageSize-1
r as integer
g as integer
read byte 1,g
read byte 1,r
write memblock dword 1,12+(x+y*ImageSize)*4,rgb(r,g,0)
next x
next y
//Create image
make image from memblock 1,1
//Save image
if file exist("heightmap.bmp") then delete file "heightmap.bmp"
save image "heightmap.bmp",1
//Clean up
delete memblock 1
delete image 1
close file 1
center text screen width()/2, screen height()/2 + 15, "Process Complete."
sync
wait key
Then I took the heightmap and texture files and split them up into a 16x16 grid.
The terrain you start out on is Terrain 1 and is loaded at position 0,0.
When you run this you'll see Red and Yellow lines on the terrain.
The Yellow lines mark the halfway point across a terrain. When you cross these lines the terrains behind you are deleted, and the terrains in front of you are loaded. I've kept the scale small enough that you can see the terrains pop into existence in the distance. (or disappear if you're walking backwards)
The Red lines mark the edge of the terrains, and as you cross onto an adjacent terrain, you and all the currently loaded terrains are shifted so you remain in the area between 0,0 to (terrain size),(terrain size). This is to avoid the problem where objects start to jitter due to the loss of floating point accuracy at great distances from 0,0,0.
The idea behind this is there are never more than 4 terrains loaded at any time, thus saving memory and allowing some VERY large terrains to be created. Since the full heightmap is set up to wrap, this allows you to just keep going, and going, and going endlessly. I've also put numbers on the 256 terrains so you get a feel for where you are on the overall map.
The 256 individual heightmaps created are 256x256, and you really can't use anything larger than that or you run out of memory and it crashes. You also can't scale it to large for the same reasons. I've been able to get a scale of 32 to work with a terrain split value of 8. If you experience an AppCrash, try lowering the terrain scale, or the split. If the split value is to low, BT will give you an error letting you know. If it's to high you'll run out of memory and the program will crash.
Updated August 15th, 2011 for updates to Windows 7 and to include the missing C++ runtime files.
Endless Terrain Demo download.
I plan to use this for an upcoming FPS, but I wanted to share the technique with the community.