Brandon Eleuterio


Learning Rust – Part 10: Dielectrics

Brandon Eleuterio

In the previous post, we implemented a trait called Material which we used to render metallic spheres. This time, we’ll create a new struct called Dielectrics which implements the Material trait and renders glass spheres.

Fairly Straightforward…Sort Of

Nothing too tricky with this concept, we just had to implement a refract() function as opposed to the reflect() function we used for metal. Of course, the actual implementation of the refraction isn’t as straightforward. Glass mostly refracts, but sometimes reflects, and it also absorbs no light. A flat piece of glass, like a window, has little depth to it. Rendering the curved shape of a sphere adds another dimension of complexity.

Ooo, Glass!

This looks awesome! Something odd I notice is the glass sphere has no shadow. It almost appears as if it’s floating! I assume that this is realistic, but I have no actual glass spheres laying around to test this assumption.

Glass Sphere
Glass, diffuse, and metal spheres


Up next, we’ll explore changing the camera angle to give us some new perspectives. Until then, feel free to follow my code on GitHub and check out the online book I’m following called Ray Tracing In One Weekend.


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top