-
Notifications
You must be signed in to change notification settings - Fork 119
/
textureslime.rs
77 lines (63 loc) · 2.49 KB
/
textureslime.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
extern crate noise;
use noise::{utils::*, *};
mod utils;
fn main() {
// Large slime bubble texture.
let large_slime = Billow::<Perlin>::new(0)
.set_frequency(4.0)
.set_lacunarity(2.12109375)
.set_octaves(1);
// Base of the small slime bubble texture. This texture will eventually
// appear inside cracks in the large slime bubble texture.
let small_slime_base = Billow::<Perlin>::new(1)
.set_frequency(24.0)
.set_lacunarity(2.14453125)
.set_octaves(1);
// Scale and lower the small slime bubble values.
let small_slime = ScaleBias::new(small_slime_base)
.set_scale(0.5)
.set_bias(-0.5);
// Create a map that specifies where the large and small slime bubble
// textures will appear in the final texture map.
let slime_map = RidgedMulti::<Perlin>::new(2)
.set_frequency(2.0)
.set_lacunarity(2.20703125)
.set_octaves(3);
// Choose between the large or small slime bubble textures depending on
// the corresponding value from the slime map. Choose the small slime
// bubble texture if the slime map value is within a narrow range of
// values, otherwise choose the large slime bubble texture. The edge
// falloff is non-zero so that there is a smooth transition between the
// two textures.
let slime_chooser = Select::new(large_slime, small_slime, slime_map)
.set_bounds(-0.375, 0.375)
.set_falloff(0.5);
// Finally, perturb the slime texture to add realism.
let final_slime = Turbulence::<_, Perlin>::new(slime_chooser)
.set_seed(3)
.set_frequency(8.0)
.set_power(1.0 / 32.0)
.set_roughness(2);
let planar_texture = PlaneMapBuilder::new(&final_slime)
.set_size(1024, 1024)
.build();
let seamless_texture = PlaneMapBuilder::new(final_slime)
.set_size(1024, 1024)
.set_is_seamless(true)
.build();
// Create a slime palette.
let slime_gradient = ColorGradient::new()
.clear_gradient()
.add_gradient_point(-1.0, [160, 64, 42, 255])
.add_gradient_point(0.0, [64, 192, 64, 255])
.add_gradient_point(1.0, [128, 255, 128, 255]);
let mut renderer = ImageRenderer::new().set_gradient(slime_gradient);
utils::write_image_to_file(
&renderer.render(&planar_texture),
"texture_slime_planar.png",
);
utils::write_image_to_file(
&renderer.render(&seamless_texture),
"texture_slime_seamless.png",
);
}