Page 1 of 1

Metalines

Posted: Wed Apr 25, 2012 8:51 am
by naughty
I've been experimenting with pixeleffect based metalines for a roguelike game I'm working on.

The attached love file is a test bed for the metalines. The controls are printed in the top left.

It was originally based on the metaballs demo (enormous thanks to the author of that) but there's quite a few things added:
  • There's a simple macro expander for creating the pixeleffect based on http://lua-users.org/wiki/SimpleLuaPreprocessor
  • In an attempt to be more efficient and support many metalines the rendering strategy is quite different. It renders the metalines to a canvas in batches then uses the canvas as a texture for a final full window pass that adds the colour.
  • To try and minimise overdraw there's three different batching strategies; simple, Bounded Interval Hierarchy (BIH) and minarea which is loosely based on r-trees.
EDIT: Now the number of metalines drawn per batch can be changed with the left and right arrow keys.

Here's some screen shots:
gOC9q.png
gOC9q.png (92.5 KiB) Viewed 504 times
lhNIu.png
lhNIu.png (104.22 KiB) Viewed 504 times
f85tv.png
f85tv.png (102.9 KiB) Viewed 504 times

Re: Metalines

Posted: Mon Apr 30, 2012 9:40 pm
by ncarlson
This is a seriously awesome demo! Thanks for sharing.

Re: Metalines

Posted: Tue May 01, 2012 8:12 am
by naughty
You're welcome.

I was surprised by some of the results while testing with this. It works by rendering batches of lines additively to a background canvas (you can change the size of the batches with the left and right arrow keys) but it always seems to be faster with smaller batches even though that require more drawing to the canvas.

Re: Metalines

Posted: Tue May 01, 2012 2:31 pm
by timmeh42
I'd love to know how you apply this to roguelikes - unless that gives away any trade-secrets?

Re: Metalines

Posted: Tue May 01, 2012 4:58 pm
by naughty
It's not a trade secret, once I've got the basics of the roguelike working I'll be posting it up here :^)

Short answer: in the screenshots above the red is the floor, the white is the walls and the blue is the solid rock the dungeon is carved out of. The thin white lines are what your @ can walk along.

Long answer: Most roguelikes take place on a grid with either 8-way or 4-way movement. There's also some 6-way hexgrid based ones and even a crazy hyperbolic plane roguelike.

I thought it would be cool to be able to do n-way movement, though I've limited it to a max of 8-way so that the usual roguelike movement controls work (hjklyubn and numpad keys). The easiest solution I could think of was a 2D graph where the points are 'tiles' and the edges between them are routes you can travel. The test data in the metalines demo, the lines in the screenshots above, are a generated level from the very early stages of coding the roguelike.

While playing around with level generation it became obvious that just looking at points and lines is a bit boring. A little green circle isn't as good as a grass tile, a bunch of blue lines doesn't look like a lake, even ASCII based roguelikes look prettier. So I needed to draw walls and floors somehow.

I had two choices either do something mesh based like Voronoi diagrams or something pixel based like metaballs/metalines. The voronoi based solution requires creating lots of extra points around the level to make the walls of the dungeon work correctly which is a pain to do well. So I started playing around with efficiently rendering metalines instead and wrote the demo in the above post.

Re: Metalines

Posted: Tue May 01, 2012 6:30 pm
by timmeh42
It is a very interesting way to do rooms, but why do you need to use metalines? Surely you can just draw thick lines normally - unless you require the rounded corners?
EDIT: Must say it does give a very organic look that would be great for caves.

Re: Metalines

Posted: Tue May 01, 2012 8:38 pm
by naughty
It just looks nicer really, also having the per-pixel distance data allows for some nice effects like a lapping shoreline on a body of water.