Page 1 of 2

Terrain Caves in Irrlicht

Posted: Sun May 27, 2007 1:10 am
by BlindSide
Hey guys, I started experimenting with ways to make caves using just Irrlicht terrain because everyone is always moaning about "Morrowind" or whatever it was that did this. And I think the results are not too bad...

(Removed Screeny cuz it was misleading, better to download example and try number 4 method!)

You can download the program here (Thx Spintz):
http://irrnet.spintz.com/CavesTest.zip

It includes 3 different methods I experimented with to get (Nearly) the same result. They are all a bit juvenile and hacky, but I think the last method is definately the best (Only requires one heightmap file and supports correct dynamic lighting).

The three methods are:
Inverted Heightmap - An identical but inverted (in paint :P ) heightmap file is loaded on top of the original, with backface culling disabled so that the underside is visible. This is the first one I tried but it gives poor performance because the other side of the "ceiling" terrain has to be drawn and also the normals are the wrong way round for dynamic lighting.

Rotated Mirrored Heightmap - An identical but horizontally mirrored (in paint :P) heightmap is drawn on top of the original. Backface culling is NOT disabled so this method provides the best perforamance out of all three (I got a 5-10fps gain.) BUT it looks like crap because the rotated terrain does not line up perfectly, and much to my dismay when I tried this method the normals are still screwy for the top part.

Inverted Y-Axis Terrain - Now to me, this was the first method I thought of, but the last one I tried. Mainly because I feared something will go wrong, or look buggy, or whatever can happen when the scale is inverted. Luckily, I chose to do this just for the sake of doing a third method, and it turned out to be the best! It only requires one heightmap, the textures line up perfectly, and dynamic lighting looks just like it should. :D The screenshot above is using this method.



Now, while making this I realized, the most obvious advantage to this is the ease of customization by an end user, and also the ease to create maps. For example, here is the terrain file I am using in this program:

Image

Thats right! I just opened up paint and scribbled something in 5 seconds, and no matter what you say the result does not look bad for the amount of work I put in modelling this map! :lol:

So...TRY THIS: Open up the file in the media folder "cave1.bmp" in paint, and do a little scribble in paint, and walla! You have your own customized cave map :P This could lead to literally hundreds of maps for an fps shooter for example, or a gigantic dungeon crawl thing.
(Please try to make the shapes as squigly as possible, no uniform shapes like squares or straight lines because there is a bug with the terrain smoothing at the mo...)

Im thinking of making a shooter called "irrCaves" based on this method sometime.

Cheers.

Posted: Sun May 27, 2007 11:55 am
by Strong99
but that means the cave top is always mirrored? but how to create then different heights to walk and different ceiling heights?

Posted: Sun May 27, 2007 6:12 pm
by Dances
Use greys instead of just black and white. You could also scale the entire top terrain.

Posted: Sun May 27, 2007 8:28 pm
by BlindSide
strong99 wrote:but that means the cave top is always mirrored? but how to create then different heights to walk and different ceiling heights?
Your not restricted to using the same terrain image in the first and second methods for both the ceiling and the floor, I only like it so you only need to draw something in paint quickly and start shooting ppl.

Posted: Wed May 30, 2007 12:26 pm
by TheRLG
That's pretty neat. With some nicely-setup lightning, grass, and water, it would look pretty killer

Posted: Sun Jul 01, 2007 5:45 pm
by IainC
I really like that; might play some with it.

Posted: Wed Jul 04, 2007 10:04 am
by JRowe47
Awesome program and concept :)

It would rock if you could do a cave map, and integrate it with a heightmap for normal terrain. You'd be able to designate depth, and by using depth, someone could add cavemap paging, similar to terrain paging, for unlimited depth. Doing a 3D paging system shouldn't be too great of a leap, I would think. I'd love to see procedurally generated cavemaps in a 3D roguelike. Definitely huge possibilities for fun!

The simplest way to do it, I think, would be to create your tunnels raw, like the black squiggly lines, then do a difference on the heightmap used for your terrain, so that you end up with a cavemap that is perfectly level with your terrain (on top.) Then you can modify the height of the map as a whole, by lightening or darkening the pixels.

Once that's finished, you can finally go in and modify the cavemap height in specific areas, to add slope. All this could be done automagically with a simple photoshop/GIMP script.

How hard would it be to add another terrain layer with caves specifically in mind, so you could integrate heightmaps and cavemaps in the same scene?

Posted: Sat Jul 07, 2007 7:13 am
by BlindSide
Good idea jrowe, ill definately give that a shot...

Posted: Sat Jul 07, 2007 2:10 pm
by SwitchCase
That's pretty neat. With some nicely-setup lightning, grass, and water, it would look pretty killer
Yeh but i reckon it would be a tedious task positioning these correctly.

Anyway, nice job blindside, its pretty cool. :D

Posted: Mon Jul 09, 2007 7:17 am
by BlindSide
If anyone is interested here is a link to the source of the demo, it is very simple. (I found testtype 4 to be the best personally, also, collision was done using a normal terrain selecter with bottom terrain and limiting the camera to certain height so it doesnt go through the roof. You will need a better method than this if you decide to make roof heightmap different from floor heightmap, so you can use testtype 2, and use collision selectors for top and bottom, although testtype 2 can have some inaccuracy in the positioning, it will require a little tinkering to work correctly.)

Oh yeah, here it is: http://rafb.net/p/xNFkje73.html

Cheers :D

Posted: Mon Jul 09, 2007 7:56 am
by etcaptor
Nice!

Posted: Mon Jul 09, 2007 10:02 am
by JRowe47
If I can figure out how, I'll post the code to do dynamic lighting for the #2 method, which is more flexible, I would think. By making spires and whatnot on the terrain, you can create stalactites, stalagmites, and columns (where they join.)

Very cool technique, can't wait to start trying it out tomorrow on arras' tiled terrain.

Posted: Mon Sep 14, 2009 5:30 am
by gd_anon
Excuse me for resurrecting this, but the link to the source is dead (only link to demo works). Can someone reupload it?

Posted: Mon Sep 14, 2009 8:43 am
by BlindSide
gd_anon wrote:Excuse me for resurrecting this, but the link to the source is dead (only link to demo works). Can someone reupload it?
It's not easily accessible for me at the moment (Old harddrive) but it's not rocket science.

You just create an ordinary terrain scene node, and then create another one using the same heightmap but with an inverted Y-Scale (e.g. "terrain->setScale(core::vector3df(1.0f, -1.0f, 1.0f))"). That's pretty much the best and easiest way to do it (Method 3).

BTW: Wow 2+ years resurrection, nice going (Man did I love smiley faces back then!).

Posted: Thu Sep 17, 2009 7:00 am
by deanhanson
It is a good idea and a different project. It seems little bit difficult and doubtful. But when there is will, there is a way. So my best wishes for you. and update the thread as work progress