Creating glass reflections

This tutorial will go over the basics of creating reflections in the glass of a scope.  You will need an image editor that can create 32-bit TGA images as well as create and edit alpha channels.

BEFORE AND AFTER:

## Getting Started

Start by creating a base texture, called a "diffuse" material, for your glass.  This texture should be **darker than you think you need it to be!**  This is because adding the specular (the reflectivity) will brighten it up quite a bit.

Your diffuse texture should have an alpha channel that is pretty bright.  The brighter your alpha channel, the more reflectivity there will be.  For my alpha channel, I made it slightly darker around the outside so that the effect is most visible in the center of the glass.

Save this diffuse as a 32-bit TGA.  Now it's time to create the TexEnvMap.

## Creating the Environment Map

The environment map, called "TexEnvMap" in the engine, is a set of textures mapped to a 3d space.  As it moves or you move, it can create the illusion of changing lighting or mirroring.

We'll start by mapping textures to a six-sided cube.  In your image editor, make the following textures:

* a completely black square
* a black square with a bit of blurry grey near the center
* a couple black squares with some blurry grey as well as a bright reflection oval

Export all of these as 32-bit TGAs or 24-bit BMPs.

## Assembling in UnrealEd

Open up UnrealEd, and import your diffuse texture.  If you choose to compress the diffuse, choose DXT3 or DXT5 compression (DXT1 will compress the alpha channel too much).  Then import your textures for the 3d reflection effect.  These can be compressed up to DXT1 since they have no alpha information.

Next, choose File > New, and create a new Raw Material.  Make sure the MaterialClass is set to cubemap.  Once the cubemap is created, in the properties, open up the Cubemap section and apply your reflection textures to the faces.  **Make sure that #4 is your square with a little bit of grey but no oval, and #5 is your all-black square.**  This will ensure that reflections of the sky are a little brighter, and reflections of the floor are darker, since face 4 is up and face 5 is down.  Set the other faces to be your textures with ovals as well as the dark face too.

Now choose File > New, and create a new Raw Material with the MaterialClass set to texenvmap.  This is the environment map, that will use our 3d cube we just created, and dynamically move the textures to simulate reflections.  In the texenvmap properties, set your cubemap as the Material.  Make sure EnvMapType is set to EM\_WorldSpace - this makes sure that the light reflects as if it were the world around the glass moving.  (If this is intended for an object in the world that does not move, set this instead to EM\_CameraSpace since it's the camera that will move to create the reflection illusion.) And finally, set m\_bDynamicMaterial to true, since this is a dynamic material - it's a material that can move and change in game.

Now once again choose File > New, and create a Raw Material with the MaterialClass set to Shader.  This is the final material, that will put together everything we've created.  Set the diffuse to our main glass texture we created in the beginning.  Also set the specularity mask to this texture as well; this will use the glass's alpha channel to darken the reflection effect.  Next, set the specular to be our texenvmap that we just created.  Finally, set m\_bDynamicMaterial to true.  And now we have a beautiful shiny texture that reflects the 3d cube textures we made!

Try it out on an object in game - you will notice a huge difference!