this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

schlick approximation

Altagos 9c69e2f4 12cf5271

+12 -2
+3 -1
src/main.zig
··· 29 29 // Setting up the world 30 30 var material_ground = Material.lambertian(zm.f32x4(0.8, 0.8, 0.0, 1.0)); 31 31 var material_center = Material.lambertian(zm.f32x4(0.1, 0.2, 0.5, 1.0)); 32 - var material_left = Material.dielectric(1.0 / 1.33); 32 + var material_left = Material.dielectric(1.5); 33 + var material_bubble = Material.dielectric(1.0 / 1.5); 33 34 var material_right = Material.metal(zm.f32x4(0.8, 0.6, 0.2, 1.0), 1.0); 34 35 35 36 var world = HittableList.init(allocator); 36 37 try world.add(Hittable.sphere(Sphere{ .center = zm.f32x4(0, -100.5, -1, 0), .radius = 100, .mat = &material_ground })); 37 38 try world.add(Hittable.sphere(Sphere{ .center = zm.f32x4(0, 0, -1, 0), .radius = 0.5, .mat = &material_center })); 38 39 try world.add(Hittable.sphere(Sphere{ .center = zm.f32x4(-1, 0, -1, 0), .radius = 0.5, .mat = &material_left })); 40 + try world.add(Hittable.sphere(Sphere{ .center = zm.f32x4(-1, 0, -1, 0), .radius = 0.4, .mat = &material_bubble })); 39 41 try world.add(Hittable.sphere(Sphere{ .center = zm.f32x4(1, 0, -1, 0), .radius = 0.5, .mat = &material_right })); 40 42 41 43 const s = spall.trace(@src(), "Raytracer", .{});
+9 -1
src/material.zig
··· 1 + const math = @import("std").math; 2 + 1 3 const zm = @import("zmath"); 2 4 3 5 const hittable = @import("hittable.zig"); ··· 69 71 70 72 const cannot_refract = ri * sin_theta > 1.0; 71 73 const direction = blk: { 72 - if (cannot_refract) { 74 + if (cannot_refract or reflectance(cos_theta, ri) > util.randomF32()) { 73 75 break :blk util.reflect(unit_direction, rec.normal); 74 76 } else { 75 77 break :blk util.refract(unit_direction, rec.normal, ri); ··· 77 79 }; 78 80 79 81 return Ray.init(rec.p, direction); 82 + } 83 + 84 + fn reflectance(cosine: f32, refraction_index: f32) f32 { 85 + var r0 = (1 - refraction_index) / (1 + refraction_index); 86 + r0 = r0 * r0; 87 + return r0 + (1 - r0) * math.pow(f32, 1 - cosine, 5); 80 88 } 81 89 };