I'm a gameplay programmer
focused on developing
engaging and unique experiences!

My Resume Learn more

Metals & Environment Maps

Rendering metals poses an interesting problem because they have no diffuse. This means that specular lighting is what gives them their distinctive look. However, currently our rendering capabilities are only limited to specular highlights, when metals need the additional component of specular reflection. Specular reflection is when you can actually see objects reflected on the metal's surface like a mirror. This poses another question of how does the metal know what to reflect? There are different levels of complexity in answering that question, but let's explore reflecting a basic environment map.

Environment Maps

Environment maps are a way of mapping a three dimensional perspective into a single texture. One way to picture this is drawing a scene on the inside of a cardboard box. Afterwards, unfold the cardboard box so that it's entirely flat. Now our 3D scene is two dimensional! That 2D texture can then be used to draw the inside of a cube, which can provide a lot of background detail in a scene that only has a clear color.

Rendering Environment Maps

Rendering an environment map is really simple as we just need to know the direction a fragment is from the camera. If the environment map is acting as a skybox, this simplifies the problem because we always want the camera to be at the center of the environment map. If it wasn't, the player could walk straight through the texture!

We know which texel to sample from an environment map by the direction it's from the camera. Since the camera is always at the center we can just use the world position of the fragment!

Reflection

If we get an environment map implemented in a scene, we then have something for metals to reflect! By calculating the reflection vector from the camera to the rendered surface, we know which texel to sample from our environment map. Something to note that the amount that the reflected light comes back to us also follows the Fresnel effect. One last thing to note about metals is that they also tint their specular highlights and reflections. Gold is good to imagine for this scenario, as it seems to emanate a yellow glow as light hits it. Nonmetals don't exhibit this behavior!

Result

If we get environment maps and reflection implemented, we can get a metal rendered like the animation below!

The characteristic reflectance I set this metal to reflect is gold, which we can really see in its specular highlight! Notice how it also almost acts like a mirror based on the smoothness of parts of the texture. Let's look at a nonmetal exhibiting specular reflection.

Notice how we can still see the grey outlines of buildings on the texture. However, it isn't mirror like the metal. We can test with a nighttime environment map to really demonstrate this

Again, notice how well the metal reflects the night lights. We'll see in the animation below that a nonmetal may only catch the brightest of the night lights:

No Comments Yet.

Leave a comment