jalberse / RayTracingInOneWeekendInRust

Ray Tracing In One Weekend, in Rust
1 stars 0 forks source link

Add image texture mapping #22

Closed jalberse closed 1 year ago

jalberse commented 1 year ago

https://raytracing.github.io/books/RayTracingTheNextWeek.html#imagetexturemapping

jalberse commented 1 year ago

Note that I think I should start with this tutorial but when I add triangulated meshes, such an approach isn't totally sufficient.

https://www.cs.cornell.edu/courses/cs4620/2017sp/slides/06rt-textures.pdf

We would need to associate UV data with each vertex of a textured model. Points within the tri would find their UV via barycentric coordinates. We would use a single UV coordinate for each vertex for all of diffuse, normal, bump, emmissive, etc textures (though we would start with only diffuse). All of the tris would have a smart pointer to a single image for the model.

jalberse commented 1 year ago

Actually, I think the ImageTexture representation will be fine even when we add polygonal models. The Tris will be hittable objects that store the UV information as described previously, and they just need to use that to call ImageTexture::value().

As far as sharing the image data across all tris, I think the simple solution is that we create the ImageTexture once, make the Lambertian (or any arbitrary material) once with it. That Material is already passed as an Arc to hittable objects (our Sphere and MovingSphere). So, we just clone that Arc for each Tri that should share that material, and that way all the tris reference the same image data.