Creating textures on the fly?

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Creating textures on the fly?

Post by ultramedia »

Hi everyone,

I'm trying to figure out how to create terrain textures on the fly for my terrain solution. What I want to be able to do is start with a simple vector shape (i.e. a rectangle) then use mid point displacement to modify it into one of those classic fractal coastline type images, then just map it onto a simple plane (which I'll then also manipulate with a height map) as a texture.

Here is an example of what I mean:
http://polymer.bu.edu/java/java/coastli ... pplet.html

I've been looking at cairographics, GDI and even had a quick look at magiclibrary. It looks like it might be a bit of a long painful journey though, so I thought I'd better check here first in case there was a quicker easier way of doing it that I'd just missed...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Just take an array of vectors (2d or even 3d) or S3DVertex points right away. Make it large enough for the maximal number of vertices and preallocate those. Then simply Make your displacement for each midpoint iteratively. This should easily get you to the coastline.
Question is how you want to map the heightmap onto the terrain. Do you want to remove those areas, which are marked as sea, or do you want to shrink those such that the coastline can be less coarse? You also have to think about how to get the terrain to the sea-level without too steep slopes. This could happen if you just use a rectangle heightmap which does not know about the coast line.
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Post by ultramedia »

Hi Hybrid,

I'm not too worried about the array or the coding to determine all the segments in the mid point displacement (that seems fairly straight forward). The thing I'm strugging with is how to take the resulting vector shape and use it to paint a texture that I can then use for heightmaps and splatting etc.

I've seen that you can get and set individual vertices in a texture, should I learn how to code rasterization of a vector shape natively in irrlicht (to a texture) or would it be smarter to learn how to integrate an external library that already has functions for doing that in it? (or more to the point, which way is most likely to be quickest?)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, copying the values of the vector into the texture won't be a problem. But filling up the rest of the heightmap will be.
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Post by ultramedia »

yeah, I'm now looking at the anti-grain geometry library. It looks pretty nice, I'm hoping I can get the hang of rendering a filled ngon to a texture tonight. Hopefully it will be able to just render directly to an irrlicht texture too, cos then I reckon I'll be off and running again...
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Post by ultramedia »

Yay :)

Got Anti-grain geometry library working alongside Irrlicht. I'll post a how to when I've got a bit more done with it...
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Post by ultramedia »

Woohoo :)

Been hammering code for a week now and *finally* managed to get some basic output going to show off my fractal islands system. Below is a an animated gif that shows several randomly generated (from a simple square) fractal shapes. Now that I've got the basic system going, the idea is that I can build large maps out of a simple grid of squares, and this will randomize the edges to make it look like (semi) natural coastlines.

Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Wow some of those look like parts of New Zealand/Australia :P
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

modified GPL license on the anti-grain lib... *sigh*

looks pretty amazing though, cool stuff!
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Post by ultramedia »

AGG 2.5 is GNU GPL, AGG 2.4 is Modified BSD

Guess which version I used ;)
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

ultramedia wrote:AGG 2.5 is GNU GPL, AGG 2.4 is Modified BSD

Guess which version I used ;)
2.4?
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Post by ultramedia »

Scraped a little bit further along tonight...
Instead of a single square now, I can do a grid. Below are a bunch of random renderings of a simple 3x3 grid with cells 1,4,5,6,9 set to "land".

Image
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Post by ultramedia »

Bigger grids, and a quick hacky little way to specify where land is...

Image

Image
Mirror
Posts: 218
Joined: Sat Dec 01, 2007 4:09 pm

Post by Mirror »

Hi. in the first and 2nd rendering it's obvious that the initial shape was a square, there are some artifacts. maybe you could start from a circle.

for the later renders, hm it reminds me of a heightmap and the same result could be produced with a diamond style subdivision for an area, coloring in blue whatever is below value X and in grey whatever is above that. maybe that could give you some ideas.
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Post by ultramedia »

Hi Mirror, yeah the single cell is just a test case. Re squares vs circles - or any other shape for that matter - it's a good point, but there are a bunch of extra things I can do with squares and the way they stack that I can't do with more freeform shapes. For example splitting the continents up into different ecotopes (i.e. mountains, hills, plains, deserts etc), see below for an (old) example diagram:

Image

It also means I only have to generate pseudo random values for the coastal and ecotope borders, instead of the entire surface of the terrain. For the heightmaps inside the various different ecotope masks, I'm just going to use generic tiling bitmaps overlaid at a couple of different scales (or even better, I can patchwork together random bits of generic satellite height maps for a super realistic look). For instance, the dark blocks above might be used as a mask to reveal a multi ridged perlin noise texture to make that part of the terrain high and mountainous, and the lighter blocks might alternate between mostly flat and mildly hilly height maps.

Another benefit of a cubic layout, is how it lets me do simple but effective looking river and road networks (also in the diagram above).
Last edited by ultramedia on Thu Jan 13, 2011 11:47 am, edited 1 time in total.
Post Reply