~turminal/raytracing

779a6c9cf77adb0862116ccb969917db009b91ee — Bor Grošelj Simić 2 years ago 6d123e2
imperfect metal reflectance
2 files changed, 7 insertions(+), 4 deletions(-)

M main.ha
M material.ha
M main.ha => main.ha +2 -2
@@ 6,8 6,8 @@ use time;
fn init_scene() *hittable = {
	let ground = alloc(make_lambertian(&C(0.8, 0.8, 0.0)));
	let center = alloc(make_lambertian(&C(0.7, 0.3, 0.3)));
	let left = alloc(make_metal(&C(0.8, 0.8, 0.8)));
	let right = alloc(make_metal(&C(0.8, 0.6, 0.2)));
	let left = alloc(make_metal(&C(0.8, 0.8, 0.8), 0.3));
	let right = alloc(make_metal(&C(0.8, 0.6, 0.2), 1.0));
	let a = alloc(multi([]));
	append(a.arr, [
		alloc(make_sphere(V(0.0, 100.5, -1.0), 100.0, ground)),

M material.ha => material.ha +5 -2
@@ 45,11 45,13 @@ fn lambertian_scatter(
export type metal = struct {
	material,
	albedo: color,
	fuzz: f64,
};

export fn make_metal(c: *color) metal = metal {
export fn make_metal(c: *color, fuzz: f64) metal = metal {
	scatter = &metal_scatter,
	albedo = *c,
	fuzz = fuzz,
};

fn reflect(v: *const vector, n: *const vector) vector =


@@ 63,9 65,10 @@ fn metal_scatter(
	r_out: *ray
) bool = {
	let m = m: *const metal;
	let reflected = reflect(&unit(r_in.direction), &rec.normal);
	*r_out = ray {
		origin = rec.point,
		direction = reflect(&unit(r_in.direction), &rec.normal),
		direction = sum(reflected, scale(random_unit(), m.fuzz)),
	};
	*att = m.albedo;
	return dot(r_out.direction, rec.normal) > 0.0;