@@ 7,19 7,49 @@ use time;
def SAMPLES: uint = 50u;
fn init_scene() *hittable = {
- let ground = alloc(make_lambertian(&C(0.8, 0.8, 0.0)));
- let center = alloc(make_lambertian(&C(0.1, 0.2, 0.5)));
- let left = alloc(make_dielectric(1.5));
- let right = alloc(make_metal(&C(0.8, 0.6, 0.2), 1.0));
+ let ground = alloc(make_lambertian(&C(0.5, 0.5, 0.5)));
+ let near = alloc(make_metal(&C(0.7, 0.6, 0.5), 0.00));
+ let mid = alloc(make_dielectric(1.5));
+ let far = alloc(make_lambertian(&C(0.4, 0.2, 0.1)));
let a = alloc(multi([]));
append(a.arr, [
- alloc(make_sphere(V(0.0, 100.5, -1.0), 100.0, ground)),
- alloc(make_sphere(V(0.0, 0.0, -1.0), 0.5, center)),
- alloc(make_sphere(V(1.0, -0.7, -1.0), 0.3, center)),
- alloc(make_sphere(V(-1.0, 0.0, -1.0), 0.5, left)),
- alloc(make_sphere(V(-1.0, 0.0, -1.0), -0.45, left)),
- alloc(make_sphere(V(1.0, 0.0, -1.0), 0.5, right)),
+ alloc(make_sphere(V(0.0, -1000.0, 0.0), 1000.0, ground)),
+ alloc(make_sphere(V(4.0, 1.0, 0.0), 1.0, near)),
+ alloc(make_sphere(V(0.0, 1.0, 0.0), 1.0, mid)),
+ alloc(make_sphere(V(-4.0, 1.0, 0.0), 1.0, far)),
]...);
+ for (let i = -11i; i <= 11; i += 1) {
+ for (let j = -11i; j <= 11; j += 1) {
+ let x = i: f64 + random(0.0, 0.9);
+ let z = j: f64 + random(0.0, 0.9);
+ if ((x - 4.0) * (x - 4.0) + z * z < 0.9f64 * 0.9f64) {
+ continue;
+ };
+
+ let pos = V(x, 0.2, z);
+ let mat = random(0.0, 1.0);
+ let material: *material = if (mat < 0.7) {
+ let c = C(
+ random(0.0, 1.0),
+ random(0.0, 1.0),
+ random(0.0, 1.0)
+ );
+ let c = C(c.r * c.r, c.g * c.g, c.b * c.b);
+ yield alloc(make_lambertian(&c));
+ } else if (mat < 0.9) {
+ let c = C(
+ random(0.5, 1.0),
+ random(0.5, 1.0),
+ random(0.5, 1.0)
+ );
+ let fuzz = random(0.0, 0.4);
+ yield alloc(make_metal(&c, fuzz));
+ } else {
+ yield alloc(make_dielectric(1.5));
+ };
+ append(a.arr, alloc(make_sphere(pos, 0.2, material)));
+ };
+ };
return a;
};
@@ 53,10 83,10 @@ export fn main() void = {
let max_bounce = 50u;
- let from = V(3.0, -3.0, 2.0);
- let at = V(0.0, 0.0, -1.0);
+ let from = V(13.0, 2.0, 3.0);
+ let at = V(0.0, 0.0, 0.0);
let c = make_camera(from, at, V(0.0, 1.0, 0.0),
- 20.0, 4.0/3.0, 2.0, length(diff(from, at)));
+ 20.0, 4.0/3.0, 0.1, 10.0);
let scene = init_scene();