Sep. 30th, 2024

miriam_e: from my drawing MoonGirl (Default)
For a couple of weeks I've been trying to work out how I might create my own procedural textures like those in POV-Ray. Partly this is an intellectual exercise, but partly it's because I'd like the versatility of being able to control textures myself when I make virtual worlds.

Today I think I've solved a crucial part of the problem. I used a simple pattern of waves and distorted them in a way that if taken further can create marble and granite textures.

Here is how I did it:

I began by making a very orderly heightfield of straight, parallel, sawtooth waves (so named because they ramp up from black to white in a linear gradient, then down again in a linear gradient, which if you graph their values look like the teeth of a saw). I made that using ImageMagick. Here's how...

Make a gradient:

convert -size 512x32 gradient: -rotate 90 ramp.png



Duplicate it reversed horizontally to make a single full sawtooth wave:

convert ramp.png \( +clone -flop \) +append sawtooth_1.png



Duplicate it multiple times to make 8 waves:

convert sawtooth_1.png +clone +append +clone +append +clone +append sawtooth_8.png



Okay. That's the nice orderly image that I want to mess up and distort. To do the next step I need a displacement map to tell G'MIC how much to displace each pixel in the image I want to distort. G'MIC can produce a number of noise images. Its "turbulence" command, is perfect for making a nice displacement map.

Generate a blank canvas of 255x255x1 (X,Y,Z) with one color channel so that it is grayscale. (3 channels would be 3 color rgb) Then add turbulent noise with a radius of 80 pixels, so that large structures dominate. All the other parameters, leave at their default settings.

gmic 512,512,1,1 turbulence 80 -o turbulence_80.png



Now we warp the orderly image with the turbulent noise image :

gmic turbulence_80.png sawtooth_8.png -warp[-1] [-2],1,2,2,1 -n[-1] 0,255 -o sawtooth_turbulence_80_warp.png



Ta-da!!!!

Hard to believe this took me so long to work out. Interestingly, GPT-4 was almost no help at all... other than the fact that it introduced me to G'MIC, which I hadn't heard of before. GPT-4 slowed me down by sending me off on several wild goose chases with its terrible efforts to write code.

Profile

miriam_e: from my drawing MoonGirl (Default)
miriam_e

May 2025

S M T W T F S
    123
45678910
11121314151617
18192021222324
252627282930 31

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 9th, 2025 07:24 pm
Powered by Dreamwidth Studios