How to make several heightmaps tile ?

Community Forums/General Help/How to make several heightmaps tile ?

RemiD(Posted 2011) [#1]
Hello, :)

I want to create several 512x512 heightmaps separately with a fixed Y scale and then i want to make them tile.

Can i use a sofware or a code that makes an image tile or is there a specific software or a code to make several heightmaps tile correctly ?

Thanks,
Good day,


Kryzon(Posted 2011) [#2]
If there's room to cheat, you should do so.

"Always make your life easier" - Brucey

Create a huge texture that's comprised of all those 512² heightmaps, but only load the portion you want to edit - I'd recommend a 1024² portion of that big one because this way you can edit several at the same time, including their edges.
After editing, overwrite the original big one with this edited portion, at the appropriate coordinates.
When you're done with all the edits, cut that big one into several 512² and they'll indirectly tile.


RemiD(Posted 2011) [#3]
Good idea, thanks Kryzon.

Do you know what is the maximum size of an image in pixels that Blitz3d is able to load and save ?

I would prefer to code a small program to do what you have explained.

Thanks,


Yasha(Posted 2011) [#4]
Blitz3D's maximum texture size is determined by your video card and is usually 4096x4096 or 8192x8192, I think. If you use images instead, it's possible that there is no upper limit except your machine's memory (no idea how image-images work...). For textures, you can actually just test it fairly simply by seeing how large a texture actually gets created.

I'm not sure I understand your question fully though - do you mean you want to create the heightmaps separately with unconnected runs through something like L3DT, and then glue them together by making the edges fit?

If so, I would advise against doing that.

One thing that's possible with most heightmap algorithms (certainly DSA, presumably also Perlin noise although I've never thought about that one) is to take a small grid and use it as a base for a much more detailed version, by running the algorithm over it until it has the level of detail you want. This means that rather than making the maps first and attaching them together, you can make a low-res map of the whole area and then enhance patches of it: these patches will naturally tile because 1) their terrain flows from one area into the next, and 2) you can keep track of surrounding tiles to ensure edge verts are in the right places.

If L3DT doesn't offer this functionality, it would be better to just create one enormous map and cut it up, as Kryzon suggested (while you can certainly do the above in B3D, it's a very complex topic and you'd be reinventing the L3DT wheel).

Last edited 2011


RemiD(Posted 2011) [#5]
In fact, i have already created a 10240x10240pixels heightmap using L3DT.

What i was wondering was if it is possible to load such a big image in Blitz3d in order to cut it in small 512x512tiles.

From my tests, Blitz3d doesn't like it, the program seems to freeze.

Then i was planning to reload each tile in L3DT and add specific reliefs.


Yasha(Posted 2011) [#6]
...you should probably look into using an image editor for this...

Some are scriptable (not something I've ever investigated myself, but it can be done), or you could just cut the image into quarters and try again with Blitz3D, saving you the effort of doing each of the 400 cells by hand.

Blitz3d doesn't like it, the program seems to freeze.


How long did you leave it? Blitz3D can act oddly when it faces a difficult task, even when it's still actually doing something useful. Normally, when a Blitz3D program runs out of memory, it just aborts with no error message (even in debug mode!), so a program that looks frozen is usually either trapped in an infinite loop, or is doing something but taking a really long time about it.


Kryzon(Posted 2011) [#7]
What i was wondering was if it is possible to load such a big image in Blitz3d in order to cut it in small 512x512tiles.

From my tests, Blitz3d doesn't like it, the program seems to freeze.

I'm sure that as a texture you cannot load something as big as that 10240².

So you are left with loading it as an image and "blitting" the section you want (with CopyRect() from the ImageBuffer) onto a viable-sized texture such as a 512² or bigger, and doing whatever you want from there. However, if you already have it as an image you can create smaller images, copy data and save them as your tiles.

If Blitz3D can't load this image with its native LoadImage() command, you can use the FreeImage userlib: http://www.blitzbasic.com/codearcs/codearcs.php?code=1732, which gives you another way to load image files and more advanced stuff like loading from banks.
Just changing the FiRead function code from that userlib can already do all you need with cropping a smaller section of a bigger image. You can copy a section to another image, already save it as one of the tiles etc.

Also look at the Splitz tool: http://www.feldfunker.de/?s=splitz


RemiD(Posted 2011) [#8]
I have managed to do it some hours ago.

With ReadPixel() or GetColor() forget it ! It is too slow !

But with CopyRect it is fast and perfect !

I have to improve the code in order to copy all the tiles in a loop but here is a start :
Graphics3D 1024,768,32,2
SetBuffer BackBuffer()
HidePointer

;Size of the Large Heightmap = 10240x10240pixels

;Size of the Small Heightmap = 1024x1024pixels

Color 255,000,255
Print "Defining the XOffset% and YOffset%."
XOffset% = 0
YOffset% = 10240-1024 ;first heightmap starts at 0X,0Z

Color 255,000,255
Print "Opening the Large heightmap."
LargeImage = LoadImage("L3DT Heightmap10240.png")

Color 255,000,255
Print "Creating the Small heightmap."
SmallImage = CreateImage(1024,1024)

Color 255,000,255
Print "Drawing specific color on the pixels of the corners for debug."
SetBuffer(ImageBuffer(LargeImage))
Color 255,000,000
Plot XOffset%,YOffset%
Color 000,255,000
Plot XOffset%+1023,YOffset%
Color 000,000,255
Plot XOffset%,YOffset%+1023
Color 255,255,000
Plot XOffset%+1023,YOffset%+1023
SetBuffer(BackBuffer())

Color 255,000,255
Print "Copying the color of the specified pixels of the Large heightmap to the Small heightmap."
CopyRect(XOffset%,YOffset%,1024,1024,0,0,ImageBuffer(LargeImage),ImageBuffer(SmallImage))

Color 255,000,255
Print "Closing the Large heightmap."
FreeImage(LargeImage)

Color 255,000,255
Print "Writing black lines on the borders of the Small heightmap."
SetBuffer(ImageBuffer(SmallImage))
;Color 000,000,000
;Line 0,0,1023,0
;Line 1023,0,1023,1023
;Line 1023,1023,0,1023
;Line 0,1023,0,0
SaveBuffer(ImageBuffer(SmallImage),"000000HOutput.bmp")
SetBuffer(BackBuffer())
Color 255,000,255
Print "Small heightmap saved."

Color 255,000,255
Print "Drawing the Small heightmap."
DrawImage(SmallImage,0,0)

Flip
FlushKeys
WaitKey
Color 255,000,255
Print "Closing the Small heightmap."
FreeImage(SmallImage)

End