-
Notifications
You must be signed in to change notification settings - Fork 119
/
texturejade.rs
77 lines (62 loc) · 2.79 KB
/
texturejade.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() {
// Primary jade texture. The ridges from the ridged-multifractal function
// produces the veins.
let primary_jade = RidgedMulti::<Perlin>::new(0)
.set_frequency(2.0)
.set_lacunarity(2.20703125)
.set_octaves(6);
// Base of the secondary jade texture. The base texture uses concentric
// cylinders aligned on the z axis, which will eventually be perturbed.
let base_secondary_jade = Cylinders::new().set_frequency(2.0);
// Rotate the base secondary jade texture so that the cylinders are not
// aligned with any axis. This produces more variation in the secondary
// jade texture since the texture is parallel to the y-axis.
let rotated_base_secondary_jade =
RotatePoint::new(base_secondary_jade).set_angles(90.0, 25.0, 5.0, 0.0);
// Slightly perturb the secondary jade texture for more realism.
let perturbed_base_secondary_jade = Turbulence::<_, Perlin>::new(rotated_base_secondary_jade)
.set_seed(1)
.set_frequency(4.0)
.set_power(1.0 / 4.0)
.set_roughness(4);
// Scale the secondary jade texture so it makes a small contribution to the
// final jade texture.
let secondary_jade = ScaleBias::new(perturbed_base_secondary_jade)
.set_scale(0.25)
.set_bias(0.0);
// Add the two jade textures together. These two textures were produced
// using different combinations of coherent noise, so the final texture
// will have a lot of variation.
let combined_jade = Add::new(primary_jade, secondary_jade);
// Finally, perturb the combined jade texture to produce the final jade
// texture. A low roughness produces nice veins.
let final_jade = Turbulence::<_, Perlin>::new(combined_jade)
.set_seed(2)
.set_frequency(4.0)
.set_power(1.0 / 16.0)
.set_roughness(2);
let planar_texture = PlaneMapBuilder::new(&final_jade)
.set_size(1024, 1024)
.build();
let seamless_texture = PlaneMapBuilder::new(final_jade)
.set_size(1024, 1024)
.set_is_seamless(true)
.build();
// Create a jade palette.
let jade_gradient = ColorGradient::new()
.clear_gradient()
.add_gradient_point(-1.000, [24, 146, 102, 255])
.add_gradient_point(0.000, [78, 154, 115, 255])
.add_gradient_point(0.250, [128, 204, 165, 255])
.add_gradient_point(0.375, [78, 154, 115, 255])
.add_gradient_point(1.000, [29, 135, 102, 255]);
let mut renderer = ImageRenderer::new().set_gradient(jade_gradient);
utils::write_image_to_file(&renderer.render(&planar_texture), "texture_jade_planar.png");
utils::write_image_to_file(
&renderer.render(&seamless_texture),
"texture_jade_seamless.png",
);
}