Procedural Textures and Dilation

It's amazing how I tend to get sucked into projects or think up new projects when I already have too many (including such projects as a web portal, multiplayer game, a proof for an algorithm to find a p-like cycle in polynomial time, etc.). However I find the procedural texture project to be the one that interests me the most.  Anyway, I've been looking back through FxGen again and found an interesting function, Dilate. A rework of the code, in C#, can be found below:

namespace Graphics
{
    class Dilate
    {
        public static float[,] Process(float[,] Data, int Width, int Height,int Iterations)
        {
            float[,] FinalValues = new float[Width, Height];
            for(int i=0;i<Iterations;++i)
            {
                for(int y=0;y<Height;++y)
                {
                    for (int x = 0; x < Width; ++x)
                    {
                        float Threshold = Data[x, y];
                        FinalValues[x, y] = Threshold;
                        for (int u = -1; u < 2; ++u)
                        {
                            for (int v = -1; v < 2; ++v)
                            {
                                int XIndex = (x + Width + u) % Width;
                                XIndex = GlobalFunctions.ClampValue(XIndex, Width, 0);
                                int YIndex = (y + Height + v) % Height;
                                YIndex = GlobalFunctions.ClampValue(YIndex, Height, 0);
                                if (Data[XIndex, YIndex] > Threshold)
                                {
                                    Threshold = Data[XIndex, YIndex];
                                    FinalValues[x, y] = Data[XIndex, YIndex];
                                }
                            }
                        }
                    }
                }
                Data=FinalValues;
                FinalValues = new float[Width, Height];
            }
            return Data;
        }
    }
}

The basic concept is we got through and check each pixel against its neighbors and whichever neighbor is the highest, we set the pixel to that value. In turn it gives a result similar to  the one below:

 



It's probably not the most useful function, but it has its uses. Anyway, check out the code, leave feedback, and happy coding.
kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 5/15/2008 at 8:29 AM
Tags: ,
Categories: Game Programming | Procedural Content
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Swirling Vortexes and Procedural Textures

Before I start, this is pretty much taken from FXGen. I really like that library for procedural texture generation. The code can be a bit difficult to parse through some times, but I still like it.  Anyway, I was bored and looking through their code when I came across their Vortex function.  I couldn't quite figure out what I would do with it until I started looking at items in their gallery. And since I was bored, I figured I would implement it in my own library:

 



All that the function is, really, is a rotation within a certain distance from a specified point. The closer you are to the center, the more you rotate. So basically you just find the distance from the current point to the center, determine the inverse percentage between that distance and the maximum distance, multiply that by the desired rotation, and then rotate the point. You could use cosine or something to give a smoother transition but a linear transition works just as well in my book. Anyway, I'm sure you're interested in the code:

 

Vortex.zip (1.11 kb)

 

So download the code, leave feedback, and as always happy coding. 

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 4/28/2008 at 12:42 PM
Tags: ,
Categories: Game Programming | Procedural Content
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Creating Marble Like Textures Procedurally

I've been working a lot on my texture generation library. And it's starting to shape up nicely. It will take me a while for it to be on par with the likes of .werkkzeug or FXGen (let alone some of the stuff out there like ProFX).

One of the items I recently added to the library was a turbulence function. It basically takes an image as input, creates two perlin noise images, and uses them to determine the pixel offset between the output image and the input image... For example:

 

turns into this using the function:

 

The reason we use perlin noise instead of straight random numbers is we want the noise to be coherent. The smoother the noise, the more the final image is going to look like something coherent instead of random. And since marble, wood textures, etc. all need some semblance of coherency, we need it to act in this manner. Anyway, I'm sure that you're interested in the code:

 

Turbulence.zip (2.59 kb)

 The code has both the perlin noise class (and the interface that it derives from) and the turbulence function. So download the code, leave feedback, and as always happy coding.

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 4/26/2008 at 10:20 AM
Tags: ,
Categories: Game Programming | Procedural Content
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed