The Perlin Device Texture Generation Demo

April 17, 2004 - Update!

DirectX Error Number Please consult you documentation.



Update! (April 17, 2004)

I have recently taken all of the texture generation code, translated it into C++, and encapsulated it in a DLL. This has two advantages. The first is speed. Compared to the original code, which was written entirely in C#, I have achieved a 5-8 times speedup. This is partly due to my orginal code not being particularly optimized, partly due to my experience in optimizing C/C++ code, and partly due to C++ being faster than C#, especially for the kind of pixel manipulation involved in perlin texture generation. The second advantage to having a DLL is that anyone can link it in their own programs and generate their own procedural textures.


What it is

One of the projects that I'm kicking around in the back of my mind is to write a (massively) multiplayer space game. I thought it would be neat to be able to randomly generate planet textures in realtime as they are needed. This little demonstration is a proof of concept testbed for generating procedural textures using Perlin noise. It allows you to tweak a large number of parameters to create noise fields, and can then map them onto a rotating sphere so that you can get some idea of what they look like.

How it works

It is not my aim to write a tutorial on how Perlin Noise works, especially when there are people out there who are much more qualified to talk about it than I am. There are two really great online resources I have found that will answer all of your questions. Some of the algorithms in my code are lifted directly from these sites.

James Long has an interactive tutorial that lets you tweak variables and generate noise fields. He also has some C# snippets.

Huge Elias maintains the definitive Perlin Noise site on the internet. It's a great resource and a must for those interested in the topic.

I want to play with it

That's great! You can download the source and binaries right here. The code requires DirectX 9 and the .NET 1.1 Framework. Both of which can be found on Microsoft's site. I've never redistributed a C# program that uses DirectX before, but I'm pretty sure that's all you'll need. Oh, and because Microsoft has a monopoly to maintain, this program will only run on the .NET platforms, meaning Windows 2000/XP (maybe Win98). Sorry about that, I can't say I'm too happy about it either.

The old version (pure C#) is still available here.

Interacting with the DLL

If you want to use or adapt the Perlin Device (as I have been calling it) in your programs, it is very simple to do. All you need to do is call the GeneratePerlinTexture() function and pass it the width and height of the texture you want (sorry, at the moment only square textures are supported), along with a pointer to some memory you have allocated. The function will place a bitmap at that memory location in A8R8G8B8 format - which you can copy right into a .Net Bitmap object, or display in a number of other ways. I'm still working on the DLL - I want to add functions like turbulence and unique texture patterns like wood grains and craters, so it's going to remain undocumented for a while (probably forever, actually). However, the source is very straight forward.

Not sold yet?

Check out the screen shots below...




This is the basic texture generation screen. It has all sorts of variables for you to play around with... Pressing "Generate" refreshes the texture.


Oooo.... Ah.... Look! You can apply your own color palettes to the textures to acheive neat effects!


Does this texture look distorted to you? That's because it has been adjusted to map perfectly on to a sphere!


Back to Shedletsky's Code Library

Back to the Nexus