Jump to content


Photo

Huge 3D Terrain Engine - 512x512 heightmap example


  • Please log in to reply
22 replies to this topic

#1 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 10 August 2010 - 09:56 PM

Huge 3D Terrain Engine
Written by: Brett Binnersley (Brett14);
Credit is NO LONGER required (despite what the GMK may say) but is greatly appreciated!


GM8.0 only at the moment, sorry.

Here's a screenshot, however you need to actually run the example to see how it works.
Posted Image


What is it?
This is a 3D terrain engine which supports HUGE terrains. The biggest size that I recommend is a 512x512 terrain, however you can go higher. It has a colormap, a detailmap (with LOD) and an overlaying texture to draw the terrain.

What Techniques did you use?
-I have used surfacefix.dll to prevent Zfighting between the detailmap, the colormap and the overlay texture, and they draw perfectly over top of each other. I have to thank Effexgames for this idea, as I was stumped on how to prevent Zfighting between different layers of the terrain without changing the Z value of the models. Since GM uses an 8bit Zbuffer it was a really noticeable gap between the layers and it just wouldn't do.

-Since heightmaps take such a long time to load I've included a converter which converts the heightmap into a grid, and saves the grid as a terrain file. This terrain file takes only a few seconds to load as opposed to a couple minutes for the heightmap.

-The example terrain included is a 512x512 heightmap. The only way that it is possible to use a terrain this vast in size in GameMaker is to split it into many smaller models and only draw the terrain around you.

Download Link?
Download

Check out my newest project: GameDev Studio
~~Brett14;

Edited by brett14, 14 March 2012 - 03:56 AM.

  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#2 NoobScratcher

NoobScratcher

    GMC Member

  • New Member
  • 132 posts

Posted 10 August 2010 - 10:04 PM

So how would i put this in my game xd ?
  • 0
The Door Closes to all noobs
but noobs arnt always dumb :)

#3 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 10 August 2010 - 10:15 PM

Export the scripts, and use them in your game the same way that they were used in the example. The example has comments for everything that you'll need to use.

Cheers
~~Brett14;
  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#4 theweirdn8

theweirdn8

    Unrivaled Legend

  • GMC Member
  • 4108 posts
  • Version:GM8.1

Posted 11 August 2010 - 12:26 AM

file not found
  • 0

[My milkshake brings all the boys to the yard]


2h2fg3c.png


#5 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 11 August 2010 - 12:55 AM

fixed
  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#6 link3000

link3000

    Link3000

  • GMC Member
  • 1130 posts
  • Version:GM8

Posted 11 August 2010 - 02:32 AM

Very nice implementation of heightmaps and regions. My only complaint is that you could be baking the shadows when the model is generated instead of having a gigantic texture spread across the entire map. The trees are also a bit ugly, but that really doesn't matter much. :P

Nice work! 9/10
  • 0

Link3000


#7 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 11 August 2010 - 04:06 AM

What do you mean baking shadows? Please explain and I could [probably] change it. There are 2 models drawn, the detailmap with the colormap/lightmap changing its vertex's colors and the overlay texture.
The detailmap draws the details of the terrain, the little rocks and things.
The overlay texture draws and colors the terrain, and this is included to make the terrain not repeat itself. It really doesn't look too great on a 512x512 terrain but it looks great on a 256x256 terrain.

The trees are also a bit ugly, but that really doesn't matter much

Yeah, I needed an object included to show that objects outside the visible region DON'T get drawn. Trees seemed like the easiest solution because I'd already made a generator a while ago. People may also find it useful and use it because its included.


Thanks for the reply.
Cheers
~~Brett14;

Edited by brett14, 11 August 2010 - 04:10 AM.

  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#8 NoobScratcher

NoobScratcher

    GMC Member

  • New Member
  • 132 posts

Posted 11 August 2010 - 08:29 AM

isnt there a export button so i can export it and just copy and paste code into game maker? :)
  • 0
The Door Closes to all noobs
but noobs arnt always dumb :)

#9 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 11 August 2010 - 09:14 AM

You dont even need to "Copy and Paste".

Open up the example loading.


File -> Export Resources
Up pops a window, name your resource. Only leave the "Scripts" box checked.

Go to your game
File -> Import Resources
Find the file you just exported. It's in your game with folders still intact.
  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#10 NoobScratcher

NoobScratcher

    GMC Member

  • New Member
  • 132 posts

Posted 11 August 2010 - 12:13 PM

You dont even need to "Copy and Paste".

Open up the example loading.


File -> Export Resources
Up pops a window, name your resource. Only leave the "Scripts" box checked.

Go to your game
File -> Import Resources
Find the file you just exported. It's in your game with folders still intact.


it keeps coming up with cant import because of names or something



  • 0
The Door Closes to all noobs
but noobs arnt always dumb :)

#11 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 11 August 2010 - 06:00 PM

Works fine here. There are 2 other ways to get the scripts into your game, but the one I origonally suggested was the easiest.

Method2) Right click on the scripts button at the top of GM. It's beside the Resources and the Run. Click it, then click "Export all scripts". Go into your game, go to the same place but inside of export all scripts click "Import Scripts". Find the scripts you exported. This works fine, but all the scripts lose their folders. You'll need to reset them yourself.

Method3) This is [the longest], [the hardest] and [I don't recommend this method] method. Go to your game, create a new script and copy-paste the code from 1 of my scripts into the script in your game. Then rename the script. Do this for every script.
  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#12 link3000

link3000

    Link3000

  • GMC Member
  • 1130 posts
  • Version:GM8

Posted 12 August 2010 - 08:43 AM

Baked shadows are faked shadows that essentially make the shadows you have in your color map when the map is loaded. I don't think I explained that very well, so here is a tutorial that I used when I started making terrains.
  • 0

Link3000


#13 theweirdn8

theweirdn8

    Unrivaled Legend

  • GMC Member
  • 4108 posts
  • Version:GM8.1

Posted 12 August 2010 - 05:21 PM

come on Im using gm7 bro
  • 0

[My milkshake brings all the boys to the yard]


2h2fg3c.png


#14 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 12 August 2010 - 06:29 PM

Just use lateral GM. It's an alternative IDE to gamemaker, but I just use it to convert GM8->GM6 (because I don't have it). It is really good at converting though, you should try it. That's what I'm just going to do to it anyways to make it GM6/7 compatible.
  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#15 3D2DGAMES

3D2DGAMES

    GMC Member

  • GMC Member
  • 864 posts
  • Version:GM:Studio

Posted 19 August 2010 - 03:19 AM

Personally I love the idea. And you are doing a great job so far. I need to say that I hate the low FPS. I get around 28. I should not get any FPS drop if I were to use a terrain engine. If you could add an easier way for the programmer to do the following:

1: enlarge the grid size. it would be nicer to use something larger than 16. In my games I don't have very large elevation changes so high detail is not required.
2: get rid of the extra terrain detail. they are cool but in some cases unnecessary

I really like your engine and I hope to use it in the near future if I can figure out how to tweak it a little for FPS purposes. keep up the good work.
  • 0

  My Twitter: @Salvakiya

 

#16 lostdarkwolf

lostdarkwolf

    GMC Member

  • GMC Member
  • 413 posts
  • Version:GM8.1

Posted 28 August 2010 - 05:31 PM

good job!

Edited by lostdarkwolf, 28 August 2010 - 05:31 PM.

  • 0

Colorado finally did it! they legalized the recreational!


#17 Brawl

Brawl

    Magnitude Games

  • GMC Member
  • 1299 posts
  • Version:GM:Studio

Posted 20 September 2010 - 09:58 PM

Hey that is great. To bad it only runs at 6 FPS on my computer. :( Oh well. That is really great still.
  • 0

#18 GPro

GPro

    Gun Powder Games

  • GMC Member
  • 293 posts
  • Version:GM8

Posted 22 January 2011 - 02:55 PM

its very nice, slow though, look here, this is a script i found in an example, its made by thesivart

//this goes to the CREATE event of the terrain object
terrain_create(heightmap,128,1000,0.5);
//this one goes into DRAW event of the same object
terrain_draw(floor);
//now the real code
//terrain_create

//THE TERRAIN SHOULD HAVE THE HIGHEST DEPTH (10000 etc. - it gets set to -1 after initing this though)
//loads the terrain from a heightmap sprite - it does not matter what the size of the sprite is ( 32x32, 64x64 or 128x128 is recommended)
//argument0 = sprite
//argument1 = the size of the terrain squares
//argument2 = terrain height
// ****---- ~ Credit goes to: brett14 ~ ----****


global.swidth=sprite_get_width(argument0);
global.sheight=sprite_get_height(argument0);
global.terrainsize = argument1;
global.terraingrid=ds_grid_create(global.swidth,global.sheight);
global.terrainmodel=d3d_model_create();
draw_sprite_stretched(argument0,0,0,0,global.swidth+2,global.sheight+2)
for(w=0;w<global.swidth+2;w+=1){
    for(h=0;h<global.sheight+2;h+=1){
        val=draw_getpixel(w,h)
        valex=color_get_value(val)
        ds_grid_set(global.terraingrid,w,h,valex/240*argument2)
        }
    } 
for(xx=0;xx<global.swidth-1;xx+=1){
d3d_model_primitive_begin(global.terrainmodel,pr_trianglestrip); 
adraw=true;
for (yy=0;yy<global.sheight;yy+=1){
  adraw = !adraw; 
  z2=ds_grid_get(global.terraingrid,yy,xx+1);
  d3d_model_vertex_normal_texture(global.terrainmodel,yy*global.terrainsize,(xx+1)*global.terrainsize,z2,0,0,1,adraw,1);
  z1=ds_grid_get(global.terraingrid,yy,xx);
  d3d_model_vertex_normal_texture(global.terrainmodel,yy*global.terrainsize,xx*global.terrainsize,z1,0,0,1,adraw,0);
  }
d3d_model_primitive_end(global.terrainmodel);
}
depth=-1;
//terrain_draw

//argument0 = terrain texture
d3d_set_culling(1);
d3d_model_draw(global.terrainmodel,0,0,0,background_get_texture(argument0))
d3d_set_culling(0);

  • 0
Gun Powder Games leader

Join our crew here!

Top Down A.I. Example | RPG Combat System | Level Up System | Shield Example


#19 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 22 January 2011 - 09:32 PM

Actually, that script was made by me. He may have used it somewhere, but if you read the script it even says inside of it that I made it. It is from my other terrain engine (unregioned, and doesn't support multitexturing). Make sure you get the authors of the scripts correct next time. All he did was change some of the comments and remove it from a script.

Link.

Edited by brett14, 22 January 2011 - 09:37 PM.

  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#20 slayer 64

slayer 64

    Slayer of gingers

  • GMC Member
  • 4301 posts
  • Version:GM:Studio

Posted 22 January 2011 - 10:10 PM

this runs at 16 frames per second for me =/
the "ter" file is 16 megs O_O lol. try saving in binary and not text.
  • 0

5y5rs3d.pngfg0UQNL.png


#21 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 22 January 2011 - 10:15 PM

I could have, but I used the built in function ds_grid_write instead. It was a tradeoff I chose that made it load much faster at the cost of a larger file. I will just write a dll next time that saves each spot as a unsignedbyte instead of a double (gamemakers grid gets saved as that.)

this runs at 16 frames per second for me =/

Yeah, I know its a little slow. I was/am working on a newer version that runs about 3X faster and is of much higher quality.

Edited by brett14, 22 January 2011 - 10:21 PM.

  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#22 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 31 January 2011 - 11:17 AM

Pretty cool thing you did here Brett.
I think detail mapping is tha best for realism.
  • 0

#23 rymate1234

rymate1234

    GMC Member

  • GMC Member
  • 30 posts

Posted 23 April 2011 - 01:31 PM

file not founnd :(

this is what i need for my game (
  • 0