Bumpmapping

This commit is contained in:
maddiebaka
2023-06-17 01:19:13 -04:00
parent 672ff1adc6
commit 04b166ac72
3 changed files with 73 additions and 41 deletions

View File

@@ -28,31 +28,11 @@ use std::io::{Write,stdout};
use crossterm::{QueueableCommand,cursor,terminal,ExecutableCommand};
fn initialize_scene(camera: &mut PerspectiveCamera) {
camera.lights.push(LightSrc::new(Vec3::new(200.0, 800.0, 300.0), 5.0));
camera.lights.push(LightSrc::new(Vec3::new(1200.0, 800.0, 300.0), 5.0));
camera.lights.push(LightSrc::new(Vec3::new(180000.0, 900.0, 300.0), 2.0));
camera.lights.push(LightSrc::new(Vec3::new(1100.0, 800.0, 300.0), 2.0));
for i in 0..15 {
let mut rng = rand::thread_rng();
let x: f64 = rng.gen::<f64>() * 250.0 * 10.0;
let y: f64 = rng.gen::<f64>() * 250.0 * 10.0;
let z: f64 = rng.gen::<f64>() * 250.0 * 10.0;
let radius: f64 = rng.gen::<f64>() * 40.0 * 10.0;
let red: f32 = rng.gen::<f32>() * 100.0;
let green: f32 = rng.gen::<f32>() * 100.0;
let blue: f32 = rng.gen::<f32>() * 100.0;
let color = Color { red, green, blue };
let sphere = Sphere {
pos: Vec3::new(x, y, 100.0),
radius: radius,
material: Material::new(Coloration::Color(color), 2.0, SurfaceType::Reflective { reflectivity: rng.gen::<f32>() }),
};
//camera.elements.push(Element::Sphere(sphere));
}
let color = Color { red: 30.0, green: 30.0, blue: 30.0 };
let back_plane = Plane {
//pos: Vec3::new(0.0, 0.0, 100.0),
pos: Vec3::new(0.0, 0.0, 1500.0),
@@ -62,38 +42,41 @@ fn initialize_scene(camera: &mut PerspectiveCamera) {
};
camera.elements.push(Element::Plane(back_plane));
let path = Path::new("texture/granite_base.png");
let texture_path = Path::new("texture/granite_base.png");
let height_path = Path::new("texture/granite_height.png");
let normal_path = Path::new("texture/granite_normal.png");
let texture_image = image::open(&path).unwrap();
let texture_image = image::open(&texture_path).unwrap();
let height_image = image::open(&height_path).unwrap();
let normal_image = image::open(&normal_path).unwrap();
let base_texture = Texture { texture: texture_image };
let center_sphere = Sphere {
pos: Vec3::new(1280.0, 1290.0, 1000.0),
radius: 300.0,
material: Material::new(Coloration::Texture(base_texture.clone()), 2.0, SurfaceType::Reflective { reflectivity: 0.1 }),
};
camera.elements.push(Element::Sphere(center_sphere));
let base_texture = Texture { texture: texture_image.clone(), heightmap: height_image };
let left_sphere = Sphere {
pos: Vec3::new(200.0, 1800.0, 500.0),
radius: 200.0,
material: Material::new(Coloration::Texture(base_texture.clone()), 2.0, SurfaceType::Reflective { reflectivity: 0.1 }),
pos: Vec3::new(800.0, 1290.0, 1000.0),
radius: 300.0,
material: Material::new(Coloration::Texture(base_texture.clone()), 2.0, SurfaceType::Diffuse),
};
camera.elements.push(Element::Sphere(left_sphere));
let top_sphere = Sphere {
pos: Vec3::new(1080.0, 700.0, 500.0),
radius: 200.0,
let right_sphere = Sphere {
pos: Vec3::new(1480.0, 1290.0, 1000.0),
radius: 300.0,
material: Material::new(Coloration::Texture(base_texture.clone()), 2.0, SurfaceType::Diffuse),
};
camera.elements.push(Element::Sphere(top_sphere));
camera.elements.push(Element::Sphere(right_sphere));
let center_sphere = Sphere {
pos: Vec3::new(1280.0, 690.0, 1100.0),
radius: 300.0,
material: Material::new(Coloration::Texture(base_texture.clone()), 2.0, SurfaceType::Reflective { reflectivity: 0.2 }),
};
camera.elements.push(Element::Sphere(center_sphere));
}
fn main() {
let mut camera = PerspectiveCamera {
pos: Vec3::new(1280.0, 1280.0, -1000.0),
pos: Vec3::new(1280.0, 1280.0, -200.0),
output_img: Image::new(2560,2560),
elements: Vec::new(),
lights: Vec::new(),