Learning to Write Procedural Textures

Hi, everybody! My name is Sarah. This is my first post of my own work… hope you like it…

I’ve been working on learning (among other things) how to use the plugin API to write procedural textures in C. Below are some samples from my first texture plugin!

These samples are all from the same texture plugin, but with different option values. Each cube on the left has a corresponding sphere on the right with the same texture, since sometimes the results look substantially different on a cube than on a non-cube shape, due to the gridlike nature of some of the texture inputs.

Sorry some of them look like repeats; I actually tweaked the options very quickly and somewhat randomly, since I didn’t want to spend all night fiddling with hundreds of examples! :slight_smile: There is some method to the madness, though; the first five columns represent the five subtypes for the plugin, the first four rows are the four variants for each algorithm. The next four rows are randomly distorted versions of those, and so on.

At the moment I only generate intensity values, so bump mapping doesn’t work yet… but displacement mapping works great, and I’ve had a lot of fun playing with it!

I’m planning on making the code/plugin available, after a little cleanup, if anyone is interested. I can probably only provide a compiled version for MacOS 10.4, though. I also have two other plugins I’m working on, plus some less boring sample images.

Comments, suggestions, feedback?

Thanks,

Sarah

http://blender.sakelley.org/downloads/imageposts/sarah0_first_tests.jpg

Hi Sarah! Welcome to BA! Hope you have a lot of fun here. And you are already contibuting to the community. Thank you!
When you have cleaned up your code and ready to release it, i dont know exactly, but if you send an email to the MSU professor, he might host it for you. Then we all can get it and use it and have fun with it. It looks very flexible. Good job!

Damned cool! I’m very excited to see the release of these.

Wow, you have some great effects going with that plugin. Very nice work, congratulations on a classy entrance.

you have already learned it i think, thanks for sharing it with us, psst dont forget to share okay?

You should email the code to Ton or another developer and see if he’ll hardcode it into Blender because I see a lot of use for this.:slight_smile:

You keep writing texture plugins like that and you could create a significant amount of new options for Blender procedurals.

Thanks for the warm welcome everybody!

RogerWickes: Thank you very much!

The guy from MSU? Are you talking about this guy?

http://www-users.cs.umn.edu/~mein/blender/

It looks like he has several plugins he’s working on, and in fact, at the moment I’m building my code by putting it in the same directory tree as his plugin distribution package:

http://www-users.cs.umn.edu/~mein/blender/plugins/plugins.src.tgz

If it’s someone else I should know about, please let me know!

Once I get my code a little more finished and polished I’ll probably put it under GPL or whatever, so anyone who wants to distribute it will be welcome to do it! I may also put together a distribution of my own plugins, depending on how many I write before I get bored…

I also have a web site… um, well, a web server. If I compiled Apache, it could probably be a website. I’d get around to that if I’d stop playing with Blender!

Fuzzmaster: Thanks! I’ll try to get at least the first one released as fast as I can, hopefully in a week or two.

BlackBoe: Oooh, I don’t think anyone’s ever called me classy before! I’m honored! :slight_smile:

greboide: I promise I won’t forget to share; that’s more than half the fun of writing code like this! I really want to see what other people will be able to do with my code, particularly since there are so many talented people here!

Cyborg Dragon: I don’t know what the Blender team has planned for the plugin API. There’s a comment in one of the files that says: Since the plugins are about to phase out, we will not sanitize this
code. It will be removed as soon as the replacing system is in
place.
However the file is dated 10/2002, and the latest RC release appears to have exactly the same plugin API, with one added function call, so I’m not sure what the current plans are. Architecturally, my first plugin has two sections, a “distort xyz coordinates” section and a “make funny shapes” section, so it could easily be implemented as a pair of plugin material nodes, which is I guess what some other 3D programs do. But I tend to find the node thing a lot more confusing, as a newbie, and the simplicity of the basic textures somewhat more appealing, because I can just pick a texture from the popup menu, then click the buttons until I make something pretty!

But I guess the Blender people don’t like them, or prefer not to add a bunch of built-in textures, or something, since the plugin distribution package mentioned above has all kinds of cool stuff that hasn’t become part of the regular distribution, and I don’t know why. I also haven’t looked at the blender code enough to know how painful it is to port a couple dozen texture plugins into the core Blender distribution, so there could be tech issues as well.

Once I learn a little more I’ll have a better idea of how best to harass them! :slight_smile:

Whew! Anyway, thanks again everyone!

Oh, and I guess I’ll share a quick test image I threw together last night… all textures done with my first texture plugin. The test pointed out a couple of flaws, since I couldn’t do exactly what I wanted with the sky or the water, so I’ll tweak the code a little, but what the heck, I’ll share the results anyway!

Sarah

http://blender.sakelley.org/downloads/imageposts/sarah0_scream.jpg

Man, that looks like it’ll add a lot to procedural textures, or even just add noise and variation to tiled image textures. Either way, it’s looking good.

I have experience in C/C++ as well. Where do you get the Blender API’s at? Are there any tutorials for writing these?

There’s not a huge amount of documentation, but start here:http://mediawiki.blender.org/index.php/Manual/Blender’s_Plugins_System
The first link there is a repository of plugins, with source:http://www.cs.umn.edu/~mein/blender/plugins
The source includes the necessary header files, makefiles, and utility scripts.

Those have been my two main sources of information. Plus a lot of experimenting.

I’ve tried to write my code a little cleaner than some of the examples; hopefully it will be a useful reference too. :slight_smile:

Sarah

Hi Sarah,

I’m that guy :wink: I’m actually at the University of Minnesota.

But anyway, I just wanted to say its looking good. I’d be happy to look at code
in whatever state you have and or just answer questions about the plugin system.
Feel free to drop me an email any time: [email protected]

Kent

Sarah… What IDE are you using? Assumming you’re on OSX, are you using XCode?

Thanks for the previous info! :smiley:

You’re welcome!

I’m not using XCode; I’m using bbedit, terminal, and “make” and “make install”. I used the exisitng plugin repository’s makefiles, with only minor changes for my system.

I guess I’m kinda old fashioned… :slight_smile:

Sarah

HA!! That’s fine. I can kick it in VI and pico too. BBEdit and Textwrangler as well. I just like XCode’s systax coloring and auto indenting.

I guess my last question would be this… how much math is involved in writing procedural textures? I can traverse binary trees and manipulate bit fields just fine. As soon as I run into a bunch of complicated math, I get stuck fast. What is involved here… Advanced Algebra? Geometry? Trig?

Well, as much math as you want to use, really!

The first plugin I worked on started out as a “hello world”-ish checkerboard pattern, which I did with xors. But for all of those sample textures above, I didn’t ever do any more math than a radius calculation. Which I had to look up on Wikipedia!

How did I manage to get so many textures with so little math? Well, from a plugin you can call the blender noise, perlin noise, soft turbulence, and hard turbulence that are built into blender. All of the cool distortion comes from that, and simple scaling of values by multiplying and dividing. Underneath all the distortion are fairly simple shapes.

I have some significantly more complicated ideas that I haven’t had time to try that involve having to compute whether or not a 3D point is within some particular mathematically defined shape, but for the most part, I plan to just look that stuff up on the internet. :slight_smile: And I don’t have any bump mapping working because you have to compute the tweaked normal for that and I haven’t even tried it yet, so I don’t know how much math is involved.

Mostly, for me, at the moment anyway, it’s a little math and a lot of tinkering to see what looks pretty, and to let my algorithms scale their adjustments so that it will be easy for an end user to get something useful out of it without understanding the details of how the algorithms work. (Besides, I can’t usually remember how they work either!)

If you want to create photorealistic textures, things might be significantly more complicated! But I’m only going for “pretty”. :slight_smile:

Sarah

HA!! That’s why God created Google!

Thanks for the insight. I’ll take a crack at this when I FIND TIME. I’m pretty busy myself.

Just wanted to chime in – Sarah, some of the effects in your plugin are really neat, and I’m glad you’ve stepped into the community with such an offering! I hope you plan to do some other effect variants.

And bbedit’s not that old-fashioned. I still code purely in emacs. :wink:

Thanks, and yes, I have some other ideas for plugins. One is just about ready to go as soon as I’m sure I understand that I’m handling anti-aliasing, bump mapping, and thread safety properly. I have two others that are in the experimental stage but have still done some cool stuff with them. I should probably post some more samples.

I’ve used emacs too, but I never got “into” it. Of course, I’ve also been using vi for 20 years too, and I still hate it. :frowning:

Hi,

I’m still working on my procedural texture plugins, but I’m not quite ready for a public test release. So I thought, to keep my own personal momentum going (and show off a bit :slight_smile: ), I should share some of the test images I’ve done with my first texture plugin (which at the moment goes by the uninspiring name of sarah0), as well as some experiments from a couple others I’m working on.

These are actually fairly early renders, before I added the noise and turbulence features to sarah0, so they only show some of the basic features. I haven’t had time to do any extensive tests with the new “fancy” features yet!

Sorry these are all abstracts; I haven’t learned to write procedural textures that look like things yet! :slight_smile:

Oh, and just a trivia note: because of the heavy subsurfacing, some of these “simple” models ended up with 2.5 million vertices or so. At large render sizes (1600x1200 etc), this really brings out details of the textures!

Okay, so here are the samples!

This one shows both checkerboards and circles used for displacement mapping of the upper cubes and spheres, and just plain color mapping on the bottom two. I believe they both use stencil mode as well. The background is circles, stenciling, some reflection mapping, and also a bit of cloud texture for effect.
http://blender.sakelley.org/downloads/imageposts/dotted_cube-800.jpg

This one shows another texture I’m working on that uses some sin(x) based functions. It still needs some work.
http://blender.sakelley.org/downloads/imageposts/test_sarahsigh-800.jpg

This shows a glass sphere with the circle texture from sarah0 used as a displacement map, creating two different levels of circles on the sphere. It’s inside a plain sphere coated with little sucker-like shapes made via extruding and subsurfacing, which are really there just to give the glass an environment to reflect.
http://blender.sakelley.org/downloads/imageposts/circly_sphere_2-800.jpg

This shows several different kinds of displacement of the sin(x) texure I’m working on. The background is from the same texture.
http://blender.sakelley.org/downloads/imageposts/test_sarahsigh_two-800.jpg

This is the sin(x) texture mapped onto some transparent blocks, just to see what would happen.
http://blender.sakelley.org/downloads/imageposts/test_sarahsigh_two_a-800.jpg

This is a different plugin I’m experimenting with that fiddles with hash functions. Below is a has function based on XORing, applied as a displacement map to a subsurfaced sphere, and a very subsurfaced cube. The background is the same texture.
http://blender.sakelley.org/downloads/imageposts/test_xorhash-800.jpg

More tests of the hash function texture and displacement mapping on subsurfaced cubes.
http://blender.sakelley.org/downloads/imageposts/test_xorsmooth-800.jpg

Hope you like them!

I’ll try to get these plugins out in the world as soon as I can! I’m eager to find out what kinds of things other people will be able to do with these!

Sarah

Incredible stuff, some of these have an artistic flavor while others have a more technological feel to them.

Members here could find many uses for them, oh, and if you want better displacement, I’d use the new displacement modifier, subsurf the mesh with the first modifier, then displace it, then subsurf to smooth things out.

The transparent blocks almost look like some sort of super high tech storage circuitry device to me.:wink: