Markov Chains for Procedurally Generated Textures

October 22, 2014 at 5:48 pm (Computer Science, Game Development, Graphics, Processing, Programming) (, , , , , )


As anybody who’s spent time on this blog knows….well, anyway, I’ve spent a while working on my game on and off. One of the time consuming processes of this was to build textures and level details. All of the art from the screenshots was created by hand using classic MS Paint (not the new-fangled one that comes with Windows 7). One particularly tedious aspect was making bookshelf textures. I had to manual rearrange books and come up with different combinations of books that I thought would be “believable” by the player and not repetitive.

Well, here’s where my new project comes in! Last weekend I spent a few hours writing an algorithm that would generate shelves of books for me. Why is this interesting though? Couldn’t I have just randomized the books and called it a day? Well, the problem with strict randomization is that it looks ugly. It would just be a mish-mash of different coloured books, which is fine for a modern bookstore but as my game takes place in the 1920’s-1940’s, it felt more appropriate to have a bit more organization. Essentially, in older libraries you would be more likely to find books that looked similar because of binding techniques of the days. You’d also find more books that were series of something that would have the same style of cover instead of just a colourful, different cover.

The goal for this project was to generate shelves that had clusters of books. To achieve this, I used a Markov Chain algorithm that would place each book on the shelf one at a time. Depending on the book it would place, it would favour specific types of books for the next book. There is still a randomized aspect to the algorithm, but it is more constrained depending on the state.

Below is a screenshot comparing some of the results of the algorithm to a strictly randomized approach. As you can see, both are somewhat random, but the shelf on the left shows more groupings of similar books.

Procedurally generated texture comparison

Procedurally generated texture comparison

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: