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.

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.



























