Jump to content


Fun with texture generation


18 replies to this topic

#1 TheNut

    Senior Member

  • Moderators
  • 1470 posts
  • LocationThornhill, ON

Posted 16 February 2009 - 06:58 PM

It's been awhile, so I figure I'd start up another "Fun with" thread ;) So today's discussion is about procedurally generated textures. Programs like Genetica and MapZone do a decent job at this and come with an extensive library of formulas. So on my quest for knowledge, I decided to build one myself (screenshot below).

The core algorithm is based on what's called a "Shader Tree". I don't know if that's the official name for it, but it sticks well. The idea is quite simple. Have a look at the following screenshot.

Posted Image
TexGen Screenshot: Generating a "Sandy Carpet" texture


A shader tree is an organized set of shaders, which as many fragment GPU programers know is a program to be executed for each pixel. Thus, each node in the tree contains logic for processing a single pixel, passing its output as the input to its parent node. What's neat about this is that it's very memory efficient. Each pixel in the final image is calculated by going through each node in the shader tree, following a depth-first traversal. So the memory requirement is equal to the size of the output image. In programs like Gimp, each of these nodes would represent a new layer in the image, which consumes (Width * Height * Bits Per Pixel) memory. Of course, having precomputed images in memory vastly improves computational time. The more shaders added, the longer the output image takes to calculate. Significant speed improvements could also be gained by coding the shaders on your GPU instead of the CPU, but it all comes down to compatibility and quality concerns.

The shaders are all mathematical to support infinite detail; however one could also assign raster images to help define the base texture of the image. In the example above, I didn't have a "wavy sand" algorithm and so I used a sand texture to help bring out some details. The perlin noise was applied to give the texture a fabric look. The coloured cell noise was added to give it a "dirty" look most cheap carpets have. There are many more algorithms too. I'd like to integrate IFS into the program, possibly using LUA to define functions not built-in to the program. It could be useful to simulate scratched metallic surfaces or interleaved fabric patterns, and many others too. It's not a very fast algorithm, especially with making LUA calls, but it's quite flexible.

One important area I need to look into is tile mapping. From what I gather, I will need to provide specialized shaders that take into account tile mapping and adjust the output so the edges link up. This would require every shader to have a tilable version, which can add up when you consider there are thousands of equations one could use. An alternative would be a raster based tile generator, one capable of taking the output image and generating a repeating tile from it based on image analysis. I've seen some very impressive results from this tile mapping style, although the complexity of the algorithms they use could easily frighten me away ;)


So this concludes today's fun post. I'm looking forward to adding more algorithms and generating some cool content with it. Pretty handy for testing out procedural functions too.
http://www.nutty.ca - Being a nut has its advantages.

#2 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 911 posts

Posted 17 February 2009 - 02:30 PM

That ideed looks like fun :)
"Stupid bug! You go squish now!!" - Homer Simpson

#3 TheNut

    Senior Member

  • Moderators
  • 1470 posts
  • LocationThornhill, ON

Posted 18 February 2009 - 01:39 AM

I still need to add some interface features, but so far it has been fun manipulating the values and seeing what pops out. I just added in a Lua shader this morning, which opens up a ton of possibilities. In just a couple minutes, I wrote a quick 'n dirty solar shader.

Posted Image

I'm working on generating basic shapes as well, such as rectangles and circles. Then mixing them up with colours / noise to produce bricks, marbles, ceramic tiles, etc...
http://www.nutty.ca - Being a nut has its advantages.

#4 Xilam

    New Member

  • Members
  • Pip
  • 7 posts

Posted 21 February 2009 - 06:35 PM

Why are you not in mensa?

#5 Reedbeta

    DevMaster Staff

  • Administrators
  • 4969 posts
  • LocationBellevue, WA

Posted 22 February 2009 - 01:09 AM

Maybe he IS in Mensa. Who says he's not? ;)
reedbeta.com - developer blog, OpenGL demos, and other projects

#6 TheNut

    Senior Member

  • Moderators
  • 1470 posts
  • LocationThornhill, ON

Posted 06 March 2009 - 12:02 AM

I say ;) To maintain a healthy balance, I play lots of 3d shooters to dumb down my IQ. I then return to development to boost it back up again. Although some work is quite menial, so I get a double dose of dumbness and then the nutty side of me starts to shine. But enough about that.. ;)

I never posted my release of this program, so I guess I'll make a quick announcement of version 0.2 I'm releasing. Aside from dealing with basic procedural algorithms and a simple shader tree processor, I've extended the logic to handle precomputing images (aka Output nodes in TexGen). This allows you to create multiple shader trees in a single project and link them together to produce some interesting results. For example, here's a render of some rocks using a sprinkle of voronoi, a dash of perlin, a touch of normal maps, and a couple Lua spices to liven it up.

Posted Image

The normal map is generated from a series of mixed algorithms. I then apply a Lua shader to shade the normal map into a black and white image. Following that, I apply a sandy colour to give it some life. In most cases though, you would probably only use the normal map in your game and then have the shader finish off the result. That would be a lot more flexible.

Posted Image

I plan to continue poking away at this on my daily commutes to work. I'm still keen on getting my IFS / Flame system in there, although it follows a much more different process than the shader tree. Nevertheless it further opens up the possibilities.


TexGen Version 0.2
Download Here
http://www.nutty.ca - Being a nut has its advantages.

#7 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2325 posts

Posted 06 March 2009 - 12:31 AM

your getting nice quality there.

#8 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 06 March 2009 - 06:52 PM

I'm getting the following error on your website:

This page contains the following errors:


error on line 1 at column 29: Extra content at the end of the document

Below is a rendering of the page up to the first error.


This looks cool and I can't wait to try it out!
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#9 TheNut

    Senior Member

  • Moderators
  • 1470 posts
  • LocationThornhill, ON

Posted 06 March 2009 - 10:30 PM

Are you using Google Chrome? For some reason that browser doesn't like my XSLT. I never bothered to fix it, as you've seen ;) It should work fine on other browsers AFAIK.
http://www.nutty.ca - Being a nut has its advantages.

#10 TheNut

    Senior Member

  • Moderators
  • 1470 posts
  • LocationThornhill, ON

Posted 16 March 2009 - 02:29 AM

More labour of love. A new version is available that includes support for using Lua scripts to create images as well as filter (post-process) existing images. I also added Perlin turbulence and updated some Lua scripts to include turbulence as well. Here are some examples.

Posted Image Posted Image Posted Image

Marble:
I spent quite a bit of time generating this and started to lose my own marbles. I hope to perfect it someday, but man is it ever a time suck. The streaks need to be sharpened and the gradient used needs to be imrpoved. A couple more days and I should officially earn my straight jacket.

Wood:
Although this may appear that I am colour blind, I was just to lazy to get it right ;) Here's a fine example of turbulent rings.

Abstract:
Fossilized Spaghetti! This random line art is a combination of grainy noise mixed with frequency-filtered turbulent waves. I have a blown up shot I'm using for my desktop now. It stimulates my curiosity :lol:
http://www.nutty.ca - Being a nut has its advantages.

#11 flux00

    Valued Member

  • Members
  • PipPipPip
  • 108 posts

Posted 20 March 2009 - 05:40 AM

Incredibly cool, keep at it, I'd love to see the results you get :happy:

Do you have any references for the implementation of these algorithms? I've just finished adding a perlin noise generator to my ray tracer, and I'd like to add more.

#12 Hyper

    Valued Member

  • Members
  • PipPipPip
  • 193 posts

Posted 20 March 2009 - 03:24 PM

TheNut, The one on the far right looks like a squishy brain. :p

#13 TheNut

    Senior Member

  • Moderators
  • 1470 posts
  • LocationThornhill, ON

Posted 21 March 2009 - 02:02 PM

flux00

I mostly use Blender as a reference, although its noise algorithms are really just based off Perlin and Voronoi (aka Cell Noise). It would seem that those two can produce an infinite number of solutions simply by manipulating their outputs.

See
- http://www.blender.o...dural-textures/
- http://wiki.blender....ypes/Procedural

Turbulence http://student.kuleu...andomnoise.html
- This augments the noise by shifting the result around. I find it adds the most interesting effects. It could turn a straight line into an abstract piece of art. Very easy to implement.

Voronoi
I haven't been able to find a site that outlines a list of interesting Voronoi functions. The sky is the limit here, but finding something that looks nice is difficult. I find when you plug in equations you know, such as the equation of a sphere or convert the solution over to Bezier paths, you get interesting results.

See: http://carljohanrosen.com/processing/


For other interesting algorithms:

IFS
This is not so much for noise as it is for patterns. Dead simple to implement with absolutely beautiful output. Difficult to implement in a program though because there are an infinite number of functions you can provide, in any order, with an infinite number of final functions, etc... I'm thinking about coupling it with LUA so the base is provided and the rest is up to the author.
See: http://flam3.com/flame.pdf

L Systems
I'm looking into this one next. Good for abstract patterns and symbols. General Google search turns up more sites than you could read in a lifetime.
http://www.nutty.ca - Being a nut has its advantages.

#14 TheNut

    Senior Member

  • Moderators
  • 1470 posts
  • LocationThornhill, ON

Posted 01 July 2009 - 03:30 PM

A couple versions later, I got around to implementing more fun into TexGen by introducing an automated IFS / Fractal Flame system. The core of the algorithm is mostly done, at least to the point that I'm satisfied with it. What remains now is to eventually complete the interface so that all the low-level functions of the system are modifiable. Here are some samples.

Posted Image Posted Image Posted Image

Seeing these beauties at full resolution is a real treat.

My next feature is to implement a GPU shader, effectively converting all my software shaders to GLSL. It should be interesting to see how much faster it can generate the results. I'm especially curious how much faster it can render fractal flames.
http://www.nutty.ca - Being a nut has its advantages.

#15 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 01 July 2009 - 09:22 PM

Sweeeeeet!

#16 tobeythorn

    Valued Member

  • Members
  • PipPipPip
  • 189 posts

Posted 02 July 2009 - 02:51 AM

TheNut,
Cool stuff. I was wondering if you are you making your texture generator as a standalone generator or or for integration into realtime 3D applications?

#17 TheNut

    Senior Member

  • Moderators
  • 1470 posts
  • LocationThornhill, ON

Posted 02 July 2009 - 10:54 AM

The underlying architect is built into my engine, both as part of a maths library and a software shader. TexGen is just a front-end to that. It serves mostly as testing grounds while I continue to expand on the algorithms. I will likely use it to also produce complex textures that would otherwise take to long to generate at runtime (not everyone owns an Intel i7 yet :)

Eventually I plan to build a couple procedural games off them. 2D games where levels and most textures are generated on the fly. Though for now this stuff is reserved for generating desktop wallpaper ;)
http://www.nutty.ca - Being a nut has its advantages.

#18 TheNut

    Senior Member

  • Moderators
  • 1470 posts
  • LocationThornhill, ON

Posted 06 July 2009 - 02:37 AM

Time flies when you're having fun!

I'm getting closer to generating a style of hardwood flooring.
Posted Image

The tile repeats well horizontally, but unfortunately the vertical axis is tough due to the way I'm generating the wood patterns. It works like this:

Posted Image + Posted Image

The first image is generated using a simple sine wave. The second image is a random perlin map with a vertical blur equal to about 1/3 the resolution of the final image. All that remains here is to blend the two together using multiplication. You could lighten the effect by brightening the perlin map before blending.

And here's a ghetto render of some textures in action.
Posted Image Posted Image A generated tile is an easy little addition. Create 4 boxes, perlin map them to get a little texture, then bumpmap it.


And finally to finish off the night, I played around some more with IFS. Who says a computer can't draw? :)

Posted Image
http://www.nutty.ca - Being a nut has its advantages.

#19 katzky

    New Member

  • Members
  • Pip
  • 1 posts

Posted 06 July 2009 - 07:55 PM

Yeah, it's cool.!

surendettement







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users