From 24d1a0d60e3b008d6672fa71bb6734f78783bb81 Mon Sep 17 00:00:00 2001 From: NorthernScott Date: Sun, 29 Sep 2024 23:03:54 -0600 Subject: [PATCH] Pre-compute strength and roughness calculations. --- lathe/terrain.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lathe/terrain.py b/lathe/terrain.py index a1ced79..0e67e86 100644 --- a/lathe/terrain.py +++ b/lathe/terrain.py @@ -75,17 +75,23 @@ def sample_octaves( # Initialize elevations array. elevations = np.ones(shape=len(points), dtype=np.float64) - # NOTE: In my separate-sampling experiment, rough/strength pairs of (1.6, 0.4) (5, 0.2) and (24, 0.02) were good for 3 octaves. The final 3 results were added and then multiplied by 0.4 + # INFO: In Bob's separate-sampling experiment, rough/strength pairs of (1.6, 0.4) (5, 0.2) and (24, 0.02) were good for 3 octaves. The final 3 results were added and then multiplied by 0.4 + + # Pre-compute roughness and strength values for each octave + roughness_values = np.array( + [(init_roughness * (roughness**i)) / radius for i in range(octaves)] + ) + strength_values = np.array( + [(init_strength * (persistence**i)) / radius for i in range(octaves)] + ) for i in prange(octaves): std_con.print(f"Octave: {i+1} ", "\r\n") elevations += sample_noise( points=points, - roughness=init_roughness / radius, - strength=init_strength / radius, + roughness=roughness_values[i], + strength=strength_values[i], radius=radius, ) - init_roughness *= roughness - init_strength *= persistence return elevations