Tuesday, May 27, 2008

Procedural Textures - Tile/Wrap

I've decided to take a break from the planet geometry stuff to look into procedural textures.  I've already gotten a few free pre-generated textures which I used in earlier posts, but the idea of generating everything procedurally really appeals to me for some reason.  My level of knowledge in this area is - like most other areas - minimal, but from doing some research I'm starting to get a feel for it.  The demoscene is where most of my procedural texturing/modelling research ended up, and the demos ... are ... absolutely ... amazing...  Then you find out that they (sometimes) managed to stuff all the code into an executable less than 64KB!!!  Infinity is by far closest to my aspirations for this project, his work has incredible detailed planets in real time with all sorts of fancy effects.  One of my favourite images from his work compares a NASA space shot to his generated planet (Dec 14th 2005).

Back to the main topic though and for procedural textures I think the guys from the produkkt have got it nailed.  They have a free tool (that is, free to use the textures it generates not the actual code behind it) called werkkzeug which demonstrates their method for creating realistic textures procedurally.  If you have any interest in this stuff you should definitely try out their tutorial.  I've seen other examples for procedural texture generation which are cool in principle but kinda limited.  I was really amazed that realistic textures like this rusty barrel can be done with a bit of Perlin noise and layering other effects.  It's just the tutorial though, the gallery has more impressive textures.

werkkzeugProceduralBarrel

So... If you checked out the links above, reading the next section where I talk about work I've accomplished is gonna kinda be like when you walk onto a intercontinental plane... First you see the first class seats and think "sweet!!" then move on to the business class and think "sure, it's not as nice as first class but it's still pretty sweet, economy can't be that bad"...  Then you finally end up behind a curtain in the economy section where there are babies screaming and chickens flapping about the place and everywhere smells of sweat and cheese.

Whilst still recoiling in shock and disgust - the stewardess moves you along to where you're really seated - the cargo section.  Welcome to the update of my work!

I redid my Perlin noise app in Windows Presentation Framework (WPF) - partly to start WPF and partly because I heard it was faster than the unsafe pointer-bitmap stuff I was doing before.  There was a bit of a learning curve, but I'm pretty happy with the results - as an aside I'm ecstatic that WPF will be replacing ASP AJAX and javascript as that's my main job and it's more frustrating than Hugh Hefner without viagra ... playing pool with a rope.  Here's the app:

newWPFPerlinSandbox

My main goal was to create a tileable/wrappable Perlin noise function so that I can eventually seamlessly tile my procedural texture.  I followed the example at the bottom of this article by Zucker, and it took a long time to sink in.

public float GetTileableNoise(int x, int y)
{
return (GetNoise(x, y)*(tileWidth - x)*(tileHeight - y) +
GetNoise(x - tileWidth, y)*(x)*(tileHeight - y) +
GetNoise(x - tileWidth, y - tileHeight)*(x)*(y) +
GetNoise(x, y - tileHeight)*(tileWidth - x)*(y))
/ (tileWidth * tileHeight);
}

newWPFPerlinSandboxSeamless


I'm convinced this code could be a lot better:



  • werkkzeug seems to create a tileable Perlin noise texture instantly while this code is hella slow

  • there are some ugly tiling effects (cross-mirror I calls it) with certain combinations of noise

perlinNoTile becomes perlin 


I'll carry on with noise and textures for the time being, trying to speed it up in various ways (move to hardware texture creation perhaps?) and maybe think about implementing a poor-man's werkkzeug to play with texture creation.

No comments: