Re: [cgkit-user] Noise Newbie
Brought to you by:
mbaas
|
From: Matthias B. <mat...@gm...> - 2008-07-10 20:59:21
|
Greg Taylor wrote:
> I'm new to noise generation and am having a hard time figuring out how
> to use your noise.fBm() function to generate elevations for my terrain
> engine. I see the prototype looks like this:
>
> *fBm*( point, octaves, lacunarity=2.0, gain=0.5)
>
> So given a map that is 500x500, would I iterate through each cell and
> change one of these variables to add some random-ness?
If (x,y) is your pixel/map position, then you could set the point to
(x,y,0) and obtain your height value using the above call. All other
values would be fixed. lacunarity and gain can be used to modify the
look of the generated noise pattern. You can start with the default
values and then just play around with other values.
The octaves parameter is the number of noise functions that get added.
If you had a look at the docs you will have noticed that fBm is just
summing up noise functions. Each iteration adds a function that has a
higher frequency. At some point, adding more frequencies doesn't make
any sense because your pixel (or geometry) resolution wouldn't be able
to capture the differences. Again, just play around with values and you
will see what it does. Start with 1 in which case fBm is equivalent to
noise and then increase the value step by step to add more detail. When
you can't spot any difference anymore, then you can stop increasing the
value. You can play around with this using a little program like the
following (requires PIL) that just creates an image similar to the one
in the docs:
#############################################################
import Image
from cgkit.cgtypes import *
from cgkit.noise import *
size = 300
img = Image.new("RGB", (size, size))
for y in range(size):
print "\015%d"%y,
for x in range(size):
p = 0.01*vec3(x, y, 0)
h = fBm(p, octaves=6, lacunarity=2.0, gain=0.5)
c = int(h*255)
img.putpixel((x,y), (c, c, c))
print 'Writing image "out.png"...'
img.save("out.png")
#############################################################
Play around with the values (the scaling factor in the computation of p
and the parameters to fBm).
And the quiz of the day: If you change the scaling factor from 0.01 to 1
you just get a plain gray image without any noise pattern at all. Why is
that? (the answer is in the docs) ;-)
> I don't want to
> get the same height map each time, I assume I should change the Z
> coordinate to something random.
Yes exactly, you can use the z coordinate to get different patterns
(alternatively (or in addition), you could add arbitrary values (not too
small) to x and y).
- Matthias -
|