Added Rayleigh Perlin
This commit is contained in:
parent
446eee5fa1
commit
e66dbfe52d
@ -126,6 +126,30 @@ class Perlin_Noise():
|
||||
self.index = 0
|
||||
self.noise = PerlinNoise(octaves=self.octave)
|
||||
|
||||
class P_Perlin_Noise():
|
||||
def __init__(self, known_shape=None, scale=0.1, octave=1):
|
||||
self.known_shape = known_shape
|
||||
self.scale = scale
|
||||
self.octave = octave
|
||||
self.magic = PI # Axis offset, should be (kinda) irrational
|
||||
# We want to genrate samples, that approx ~N(0,1)
|
||||
self.normal_factor = PI/20
|
||||
self.clear_cache_every = 128
|
||||
self.reset()
|
||||
|
||||
def __call__(self, shape=None):
|
||||
if shape == None:
|
||||
shape = self.known_shape
|
||||
self.index += 1
|
||||
noise = [self.noise([self.index*self.scale, self.magic+(2*a)]) / self.normal_factor
|
||||
for a in range(np.prod(shape))]
|
||||
if self.index % self.clear_cache_every == 0:
|
||||
self.noise.cache = {}
|
||||
return th.Tensor(noise).view(shape)
|
||||
|
||||
def reset(self):
|
||||
self.index = 0
|
||||
self.noise = PerlinNoise(octaves=self.octave)
|
||||
|
||||
class Harmonic_Perlin_Noise():
|
||||
def __init__(self, known_shape=None, scale=0.1, octaves=8):
|
||||
@ -173,3 +197,27 @@ class Dirty_Perlin_Noise():
|
||||
def reset(self):
|
||||
self.perlin = Perlin_Noise(known_shape=self.known_shape, scale=self.scale, octave=1)
|
||||
self.white = White_Noise(known_shape=self.known_shape)
|
||||
|
||||
class Rayleigh_Perlin_Noise():
|
||||
def __init__(self, known_shape=None, sigma=0.1):
|
||||
self.known_shape = known_shape
|
||||
self.sigma = sigma
|
||||
self.magic = PI # Axis offset, should be (kinda) irrational
|
||||
# We want to genrate samples, that approx ~N(0,1)
|
||||
self.normal_factor = PI/20
|
||||
self.clear_cache_every = 128
|
||||
self.reset()
|
||||
|
||||
def __call__(self, shape=None):
|
||||
assert shape == self.known_shape or (shape[1:] == self.known_shape[1:] and shape[0] <= self.known_shape[0])
|
||||
self.index += 1
|
||||
noise = [self.noise([self.index*self.scales[a%np.prod(self.known_shape[:-1])], self.magic+(2*a)]) / self.normal_factor
|
||||
for a in range(np.prod(shape))]
|
||||
if self.index % self.clear_cache_every == 0:
|
||||
self.noise.cache = {}
|
||||
return th.Tensor(noise).view(shape)
|
||||
|
||||
def reset(self):
|
||||
self.index = 0
|
||||
self.scales = np.random.rayleigh(scale=self.sigma, size=np.prod(self.known_shape[:-1]))
|
||||
self.noise = PerlinNoise(octaves=1)
|
@ -55,10 +55,12 @@ class Avaible_Noise_Funcs(Enum):
|
||||
DIRTYPERLIN = 5
|
||||
SDE = 6
|
||||
SHORTPINK = 7
|
||||
P_PERLIN = 8
|
||||
RAYLEIGH_PERLIN = 9
|
||||
|
||||
def get_func(self):
|
||||
# stil aaaaaaaa
|
||||
return [noise.White_Noise, noise.Pink_Noise, noise.Colored_Noise, noise.Perlin_Noise, noise.Harmonic_Perlin_Noise, noise.Dirty_Perlin_Noise, noise.SDE_Noise, noise.shortPink_Noise][self.value]
|
||||
return [noise.White_Noise, noise.Pink_Noise, noise.Colored_Noise, noise.Perlin_Noise, noise.Harmonic_Perlin_Noise, noise.Dirty_Perlin_Noise, noise.SDE_Noise, noise.shortPink_Noise, noise.P_Perlin_Noise, noise.Rayleigh_Perlin_Noise][self.value]
|
||||
|
||||
|
||||
def cast_to_enum(inp, Class):
|
||||
|
Loading…
Reference in New Issue
Block a user