In rasterization, at least in the context of game development, it is a common to have many instances of the same 3D object in a scene (think many identical rocks in different sizes/positions/rotations) and to render them by only putting the 3D object in GPU memory once and just updating the model matrix every time. This works relatively easily in rasterization since the rendering is done "object by object", but it allows to be way more efficient than if we were to upload several copies of the same mesh.
I was wondering: is that possible/usually done in raytracing? I was looking at the code from Raytracing in one Weekend and the author allocates one new sphere every time he adds a sphere to the scene:
for (int a = -11; a < 11; a++) {
for (int b = -11; b < 11; b++) {
auto choose_mat = random_double();
point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double());
if ((center - point3(4, 0.2, 0)).length() > 0.9) {
shared_ptr<material> sphere_material;
if (choose_mat < 0.8) {
// diffuse
auto albedo = color::random() * color::random();
sphere_material = make_shared<lambertian>(albedo);
world.add(make_shared<sphere>(center, 0.2, sphere_material));
} else if (choose_mat < 0.95) {
// metal
auto albedo = color::random(0.5, 1);
auto fuzz = random_double(0, 0.5);
sphere_material = make_shared<metal>(albedo, fuzz);
world.add(make_shared<sphere>(center, 0.2, sphere_material));
} else {
// glass
sphere_material = make_shared<dielectric>(1.5);
world.add(make_shared<sphere>(center, 0.2, sphere_material));
}
}
}
}
I wonder: is this done just for simplicity (after all it is a beginners raytracing course) or is it not an usual practice to reuse geometry in such renderers (possibly because the algorithms do not make it possible, as they evaluate the whole scene ar once)?