I implemented reflection on my ray tracer. I had very few objects in the scene, so the reflected rays would less likely intersect. If most of the rays don't intersect, metallic objects would appear less metallic. What I tried to do was use the dot product of the direction from the reflected ray's origin to the light source and the reflected ray's direction. It doesn't look very metallic. It just makes the parts of the object closer to the specular highlight brighter. I was wondering what'd be a better way to deal with reflected rays that don't intersect.

This is what I got with rendering a silver sphere.enter image description here

Here is an example of how a metallic surface should be handled.

enter image description here


1 Answer 1


For metallic materials to look metallic, they should have some environment surrounding them for them to reflect. In the sphereflake image you posted, the metal spheres are reflecting the yellow ground and a blue sky, together with getting specular highlights from three light sources, and this is enough to give the impression of metal. The reflected rays are either hitting the other spheres, the ground plane, or if they miss (don't hit anything) they are assumed to hit the sky, and assigned the sky color.

So, providing some sort of colored sky is useful. For instance, you can map a texture onto the sky based on the direction the ray is heading. There are many free environment maps available on the web that can be used for this purpose. Set it up so that "miss" rays sample the environment map, and the detail in the texture will provide the cues your brain needs to perceive the material as metallic. This is also known as "image-based lighting" since the lighting environment is determined by an image rather than (or in addition to) specified light sources.

For a simpler version of this, you could create a 1D gradient or color ramp mapped from the top of the sky to the bottom (i.e. based on the ray's vertical angle). It won't be quite as effective as a full HDR environment map but will still work better than a single flat color.

  • $\begingroup$ I've decided to add a large metal plane behind the camera. It did make part of the sphere metallic. $\endgroup$
    – RoyTron
    Dec 24, 2021 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.