This blog series is a part of the write-up assignments of my Real-Time Game Rendering class in the Master of Entertainment Arts & Engineering program at University of Utah. The series will focus on C++, Direct3D 11 API and HLSL.

In this post, I will talk about how I added support for environment map to use with the sky sphere and to add reflectance on meshes.

Cube Map

For my environment mapping, I am using some cube maps from this website. With cube maps, we can sample the desired texel easily with a 3D vector (float3) to use with the sky sphere or for reflection calculation.

A cube map of Yokohama at night (

Declaring cube map textures is different from declaring normal 2D textures. Usually, we declare 2D textures as Texture2D, but cube maps need to be declared as TextureCube.

Since environment maps won’t be inside any material, we cannot rely on the material file to specify and register it to be built. Instead, I need to specifically specify it for the asset builder to build it correctly.

Declare cube map texture.
Add environment map into the asset builder.

Sky Sphere

For the sky sphere, I am using a sphere mesh that is large enough to give a sense of distance, and simply move it along with the player’s camera.

Sampling the environment map texture for the sky sphere

Environment Mapping Reflection

To show reflection on meshes, we can calculate the reflected vector according to the incoming view direction and the fragment’s normal vector. With the reflected vector, we can sample the environment map texture just like how we did for the sky sphere, and use the texel value to modify the shaded color of fragments. Notice that the reflected strength is calculated with the Fresnel Schlick approximation.

Sampling the reflected color.

First, let’s take a look at how metal objects will react to the reflection. Below are three different materials which represent copper, gold, and aluminum. You can see how the difference in reflectivity tints the color of the reflection.

Different reflectivity for different material.

Now let’s look at something that is not metal. You can see that the reflection is more subtle compared to the metal materials.

Now let’s try another environment map. The environment map that I am using below is a night view of Yokohama, Japan.