aboutsummaryrefslogtreecommitdiff
path: root/src/texture/noise_texture.rs
diff options
context:
space:
mode:
authorlamp2023-03-05 21:45:56 +0000
committerlamp2023-03-05 21:45:56 +0000
commit78ddaff5855bf8446adef9e18eb0d7b7ddcee52a (patch)
tree0d0e93cfa28751a2f96518eeb231cf715958e1fa /src/texture/noise_texture.rs
init
Diffstat (limited to 'src/texture/noise_texture.rs')
-rw-r--r--src/texture/noise_texture.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/texture/noise_texture.rs b/src/texture/noise_texture.rs
new file mode 100644
index 0000000..92ac166
--- /dev/null
+++ b/src/texture/noise_texture.rs
@@ -0,0 +1,22 @@
+use super::{Texture, perlin::Perlin};
+use crate::{vec3::Color, vec3::Point3};
+
+pub struct NoiseTexture {
+ noise: Perlin,
+ scale: f64,
+}
+
+impl NoiseTexture {
+ pub fn new(scale: f64) -> Self {
+ Self {
+ noise: Perlin::new(),
+ scale,
+ }
+ }
+}
+
+impl Texture for NoiseTexture {
+ fn value(&self, _: f64, _: f64, p: &Point3) -> Color {
+ Color { x: 1.0, y: 1.0, z: 1.0 } * 0.5 * (1.0 + (self.scale * p.z + 10.0 * self.noise.turb(p, 7)).sin())
+ }
+}