@@ -47,9 +47,9 @@ left_wall = normal_mesh(Rect3f(Vec3f(-5, -1.5, -2), Vec3f(0.01, 5, 10)))
4747sphere1 = Tesselation (Sphere (Point3f (- 2 , - 1.5 + 0.8 , 2 ), 0.8f0 ), 64 )
4848sphere2 = Tesselation (Sphere (Point3f (2 , - 1.5 + 0.6 , 1 ), 0.6f0 ), 64 )
4949
50- # Build our BVH acceleration structure
50+ # Build our BVH acceleration structure with material indices
5151scene_geometry = [cat_mesh, floor, back_wall, left_wall, sphere1, sphere2]
52- bvh = Raycore. BVH (scene_geometry)
52+ bvh = Raycore. BVH (scene_geometry, (mesh_idx, tri_idx) -> UInt32 (mesh_idx) )
5353f, ax, pl = plot (bvh; axis= (; show_axis= false ))
5454```
5555Set the camera to something better:
269269function material_kernel (bvh, ctx, tri, dist, bary, ray)
270270 hit_point = ray. o + ray. d * dist
271271 normal = compute_normal (tri, bary)
272- mat = ctx. materials[tri. material_idx ]
272+ mat = ctx. materials[tri. metadata ]
273273
274274 color = compute_multi_light (bvh, ctx, hit_point, normal, mat, shadow_samples= 2 )
275275 return to_rgb (color)
@@ -287,7 +287,7 @@ Add simple reflections for metallic surfaces:
287287function reflective_kernel (bvh, ctx, tri, dist, bary, ray, sky_color)
288288 hit_point = ray. o + ray. d * dist
289289 normal = compute_normal (tri, bary)
290- mat = ctx. materials[tri. material_idx ]
290+ mat = ctx. materials[tri. metadata ]
291291
292292 # Direct lighting with soft shadows
293293 direct_color = compute_multi_light (bvh, ctx, hit_point, normal, mat, shadow_samples= 8 )
@@ -310,7 +310,7 @@ function reflective_kernel(bvh, ctx, tri, dist, bary, ray, sky_color)
310310 reflection_color = if refl_hit
311311 refl_point = reflect_ray. o + reflect_ray. d * refl_dist
312312 refl_normal = compute_normal (refl_tri, refl_bary)
313- refl_mat = ctx. materials[refl_tri. material_idx ]
313+ refl_mat = ctx. materials[refl_tri. metadata ]
314314 compute_multi_light (bvh, ctx, refl_point, refl_normal, refl_mat, shadow_samples= 1 )
315315 else
316316 to_vec3f (sky_color)
0 commit comments