bugfix
This commit is contained in:
parent
37c4cbb666
commit
5dfdf5e32e
13
src/main.rs
13
src/main.rs
|
@ -22,11 +22,11 @@ fn main() {
|
||||||
|
|
||||||
fn camera_render() {
|
fn camera_render() {
|
||||||
|
|
||||||
let scale = 2;
|
let scale = 1;
|
||||||
let width: i32 = 800/scale;
|
let width: i32 = 800/scale;
|
||||||
let height: i32 = 600/scale;
|
let height: i32 = 600/scale;
|
||||||
let sample_times = 50;
|
let sample_times = 127;
|
||||||
let reflect_depth = 100;
|
let reflect_depth = 127;
|
||||||
|
|
||||||
|
|
||||||
let pw_r = PPMWriter::new(
|
let pw_r = PPMWriter::new(
|
||||||
|
@ -59,10 +59,13 @@ fn camera_render() {
|
||||||
let left_m = Some(MaterialKind::Metal(Metal{albedo: Color::new(0.799, 0.599, 0.799), fuzz: 0.0005}));
|
let left_m = Some(MaterialKind::Metal(Metal{albedo: Color::new(0.799, 0.599, 0.799), fuzz: 0.0005}));
|
||||||
let left_behind_m = Some(MaterialKind::Lambertian(Lambertian{albedo: Color::new(0.799, 0.599, 0.599)}));
|
let left_behind_m = Some(MaterialKind::Lambertian(Lambertian{albedo: Color::new(0.799, 0.599, 0.599)}));
|
||||||
let right_m = Some(MaterialKind::Metal(Metal{albedo: Color::new(0.8, 0.6, 0.2), fuzz: 0.003}));
|
let right_m = Some(MaterialKind::Metal(Metal{albedo: Color::new(0.8, 0.6, 0.2), fuzz: 0.003}));
|
||||||
let left_dia_m = Some(MaterialKind::Dielectric(Dielectric{albedo: Color::new(0.8, 0.6, 0.2), refraction_index: 1.5}));
|
// 折射率 1.33
|
||||||
|
let left_dia_m = Some(MaterialKind::Dielectric(Dielectric{albedo: Color::new(0.8, 0.6, 0.2), refraction_index: 1.00 / 1.33}));
|
||||||
|
let left_dia_small_m = Some(MaterialKind::Dielectric(Dielectric{albedo: Color::new(0.8, 0.6, 0.2), refraction_index: 1.00 / 2.5}));
|
||||||
|
|
||||||
// world.put(Box::new(Sphere::new(Point::new(0.0, 0.0, -1.0), 0.5, center_m)));
|
world.put(Box::new(Sphere::new(Point::new(0.0, 0.0, -1.0), 0.5, center_m)));
|
||||||
world.put(Box::new(Sphere::new(Point::new(-1.0, 0.0, -1.0), 0.5, left_dia_m)));
|
world.put(Box::new(Sphere::new(Point::new(-1.0, 0.0, -1.0), 0.5, left_dia_m)));
|
||||||
|
world.put(Box::new(Sphere::new(Point::new(-1.0, 0.0, -1.0), 0.2, left_dia_small_m)));
|
||||||
// world.put(Box::new(Sphere::new(Point::new(-1.0, 0.0, -1.0), 0.5, left_m)));
|
// world.put(Box::new(Sphere::new(Point::new(-1.0, 0.0, -1.0), 0.5, left_m)));
|
||||||
world.put(Box::new(Sphere::new(Point::new(-3.5, 1.5, -5.5), 1.5, left_behind_m)));
|
world.put(Box::new(Sphere::new(Point::new(-3.5, 1.5, -5.5), 1.5, left_behind_m)));
|
||||||
world.put(Box::new(Sphere::new(Point::new(1.0, 0.0, -1.0), 0.5, right_m)));
|
world.put(Box::new(Sphere::new(Point::new(1.0, 0.0, -1.0), 0.5, right_m)));
|
||||||
|
|
|
@ -86,14 +86,6 @@ pub struct Dielectric {
|
||||||
impl Material for Dielectric {
|
impl Material for Dielectric {
|
||||||
fn scatter(&self, r_in: &Ray, hit_record: &mut HitRecord, attenuation: &mut Color, scattered: &mut Ray) -> bool {
|
fn scatter(&self, r_in: &Ray, hit_record: &mut HitRecord, attenuation: &mut Color, scattered: &mut Ray) -> bool {
|
||||||
|
|
||||||
// attenuation = color(1.0, 1.0, 1.0);
|
|
||||||
// double ri = rec.front_face ? (1.0/refraction_index) : refraction_index;
|
|
||||||
|
|
||||||
// vec3 unit_direction = unit_vector(r_in.direction());
|
|
||||||
// vec3 refracted = refract(unit_direction, rec.normal, ri);
|
|
||||||
|
|
||||||
// scattered = ray(rec.p, refracted);
|
|
||||||
// return true;
|
|
||||||
*attenuation = Color::new(1.0, 1.0, 1.0);
|
*attenuation = Color::new(1.0, 1.0, 1.0);
|
||||||
let ri = if hit_record.front_face {
|
let ri = if hit_record.front_face {
|
||||||
1.0 / self.refraction_index
|
1.0 / self.refraction_index
|
||||||
|
@ -102,27 +94,21 @@ impl Material for Dielectric {
|
||||||
};
|
};
|
||||||
|
|
||||||
let unit_direction = r_in.direction.normalize();
|
let unit_direction = r_in.direction.normalize();
|
||||||
let refracted = refract(unit_direction, hit_record.normal, ri);
|
|
||||||
*scattered = Ray::new(hit_record.p, refracted);
|
|
||||||
|
let cos = -unit_direction.dot(hit_record.normal).min(1.0);
|
||||||
|
let sin = (1.0 - cos.powi(2)).sqrt();
|
||||||
|
|
||||||
|
let direction = if self.refraction_index * sin > 1.0 {
|
||||||
|
reflect(unit_direction, hit_record.normal)
|
||||||
|
} else {
|
||||||
|
refract(unit_direction, hit_record.normal, self.refraction_index)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// let refracted = refract(unit_direction, hit_record.normal, ri);
|
||||||
|
*scattered = Ray::new(hit_record.p, direction);
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// *attenuation = Color::new(1.0, 1.0, 1.0);
|
|
||||||
// let ri = if hit_record.front_face {
|
|
||||||
// 1.0/self.refraction_index
|
|
||||||
// } else {
|
|
||||||
// self.refraction_index
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let normalized = r_in.direction;
|
|
||||||
// let refracted = refract(normalized, hit_record.normal, ri);
|
|
||||||
// *scattered = Ray::new(hit_record.p, refracted);
|
|
||||||
// true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue