57 lines
1.8 KiB
Markdown
57 lines
1.8 KiB
Markdown
# rsrt
|
|
|
|
A raytracer built using https://raytracing.github.io as a follow up to my last attempt back in 2020 https://github.com/EliseZeroTwo/rs-ytrace/.
|
|
|
|
## Renders
|
|
|
|
### 2024-06-29
|
|
|
|
A slightly modified version of the cover of the first book "Ray Tracing in One Weekend".
|
|
|
|

|
|
|
|
```rs
|
|
let mut builder = Raytracer::builder()
|
|
.image_size(3840, 2160)
|
|
.samples_per_pixel(500)
|
|
.max_depth(50)
|
|
.vertical_fov(20.0)
|
|
.look_from(13.0, 2.0, 3.0)
|
|
.look_at(0.0, 0.0, 0.0)
|
|
.vup(0.0, 1.0, 0.0)
|
|
.defocus_angle(0.6)
|
|
.focus_dist(10.0)
|
|
.with_sphere(0.0, -1000.0, 0.0, 1000.0)
|
|
.lambertian(1.0, 0.6, 0.7);
|
|
|
|
for a in -11..11 {
|
|
for b in -11..11 {
|
|
let choose_mat = random_f64();
|
|
let center = Point3::new(a as f64 + 0.9 * random_f64(), 0.2, b as f64 + 0.9 * random_f64());
|
|
|
|
if (center - Point3::new(4.0, 0.2, 0.0)).len() > 0.9 {
|
|
let shape_builder = builder.with_sphere(center.x(), center.y(), center.z(), 0.2);
|
|
|
|
builder = if choose_mat < 0.8 {
|
|
let albedo = Color::random() * Color::random();
|
|
shape_builder.lambertian(albedo.r(), albedo.g(), albedo.b())
|
|
} else if choose_mat < 0.95 {
|
|
let albedo = Color::random_range(0.5, 1.0);
|
|
let fuzz = random_f64_range(0.0, 0.5);
|
|
shape_builder.metal(albedo.r(), albedo.g(), albedo.b(), fuzz)
|
|
} else {
|
|
shape_builder.dielectric(1.5)
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
let raytracer = builder
|
|
.with_sphere(0.0, 1.0, 0.0, 1.0)
|
|
.dielectric(1.5)
|
|
.with_sphere(-4.0, 1.0, 0.0, 1.0)
|
|
.lambertian(1.0, 0.5, 0.6)
|
|
.with_sphere(4.0, 1.0, 0.0, 1.0)
|
|
.metal(0.7, 0.6, 0.5, 0.0)
|
|
.finish();
|
|
``` |