Implemented Harmonic Perlin Noise

This commit is contained in:
Dominik Moritz Roth 2023-06-26 16:18:35 +02:00
parent 01e8b9f8d3
commit 1516cb765d

View File

@ -90,10 +90,10 @@ class SDE_Noise():
class Perlin_Noise():
def __init__(self, known_shape=None, scale=0.1, octaves=1):
def __init__(self, known_shape=None, scale=0.1, octave=1):
self.known_shape = known_shape
self.scale = scale
self.octaves = octaves
self.octave = octave
self.magic = 3.141592653589 # Axis offset, should be (kinda) irrational
# We want to genrate samples, that approx ~N(0,1)
self.normal_factor = 14/99
@ -102,9 +102,30 @@ class Perlin_Noise():
def __call__(self, shape):
self.index += 1
noise = [self.noise([self.index*self.scale, self.magic*a]) / self.normal_factor
for a in range(self.known_shape[-1])]
for a in range(shape[-1])]
return th.Tensor(noise)
def reset(self):
self.index = 0
self.noise = PerlinNoise(octaves=self.octaves)
self.noise = PerlinNoise(octaves=self.octave)
class Harmonic_Perlin_Noise():
def __init__(self, known_shape=None, scale=0.1, octaves=8):
self.known_shape = known_shape
self.scale = scale
if type(octaves) == int:
octaves = [1/(i+1) for i in range(octaves)]
octaves = np.array(octaves)
self.octaves = octaves / np.linalg.norm(octaves)
self.reset()
def __call__(self, shape):
harmonics = [noise(shape)*self.octaves[i] for i, noise in enumerate(self.noises)]
return sum(harmonics)
def reset(self):
self.index = 0
self.noises = []
for octave, amplitude in enumerate(self.octaves):
self.noises += [Perlin_Noise(known_shape=self.known_shape, scale=self.scale, octave=(octave+1))]