Environment Maps

From Mod Wiki

Environment maps are made up of 6 images that form a cube (also known as cube maps) to create a fake reflection used on windows, scopes, and any other material that uses environment maps.

Using Environment Maps

An example environment cubemap generated by ETQW.

First you need to create environment maps that match locations in your level. You can do this by placing info_envmap entities in editWorld.

Once you have created an environment map for your level, there are a few ways you can define areas for it to be used in:

Once these areas are defined, you can set up materials to use the cubemaps as environment reflection images.


Placing an info_envmap

What you'll need to do first is place an info_envmap in the area you want to reflect, you'll will need to specify two keys and values:

  • env_size - the size in pixels of the cubemap images (eg. 128)
  • env_name - the path and name of the resulting cubemap images (preferably in the form mapname/location, for example valley/treatment_plant_office).

Once your info_envmap entities are set up, compile your map. After it's compiled, load it up, bring down the console and type makeenvmaps. This will locate all info_envmap entities and make the environment maps.

For best results during this stage, make sure you are running the game in 640x480 and a 4:3 aspect ratio ( r_aspectratio 0 ).

Used with a light_ambient entity

Setting one up with a light_ambient is fairly straight-forward. Bring down the console and type editAmbient, this will load the Ambient Light Editor.

At the bottom of the window it will say Env. Cubemap with a dialog box and button next to it, click that button and go to the /base/env folder where your new environment maps are stored. Locate the environment map which matches the area you are lighting and click OK.

You may need to reload the engine for these changes to take effect.

Used with an info_envbound entity

Repeat the process of placing an info_envmap for each new area you want to have a unique environment map.

To add them to areas that don't use portals (like building interiors) that would be too difficult to portal off, you can use an info_envbound brush entity, which means when a player walks into this brush volume it'll switch to the environment map that you specified in the entity.

To do this, you'll need to drag a brush out over the area you want - the area can consist of multiple brushes. With the brush(es) selected, right-click and navigate to info_envbound. You'll then need to add one key and value to this entity:

  • env_name - the environment map you want to use (eg. env/valley/treatment_plant_office).


Compile your map. Once it's done, load it up and check out your new environment map inside the info_envbound area.

NOTE: Try to avoid having the origin of your info_envbound inside other brushes, as this will stop it from working.

Display environment maps in a material

You can use environment maps in a material, to make reflective surfaces look more convincing. The game will automatically choose the correct environment map for the location the material is in. For example, if a player with a sniper rifle walks from an outdoor area into a building, you will see the reflection on the scope change to use the building's environment map as they enter the room. This means your materials will always look consistent with the environment that surrounds them.

Here's how to set up an environment map stage in a material:

material models/mapobjects/automobiles/car_reflect
{
	surfacetype "metal"
	{
		diffusemap	models/mapobjects/automobiles/car03_d.tga 
		specularmap	models/mapobjects/automobiles/car03_s.tga 
		bumpmap		models/mapobjects/automobiles/car03_local.tga
	}
	{
		maskcolor
		map		makealpha( models/mapobjects/automobiles/car03_s.tga )
	}
	{
		blend		gl_dst_alpha, gl_one
		maskalpha
		program	sfx/cubemap
		red		Parm0
		green   	Parm1
		blue		Parm2
	}
}

You can see above that the material has 3 stages.

  • The 1st stage is the standard setup of diffuse, normal and specular maps.
  • The 2nd stage is where we define the mask that controls the amount of reflection. In this case we're just using the same image as the model's specular map. If you wanted a 100% reflective material, your image here would be pure white. Pure black means no reflection at all.
  • The 3rd stage defines the use of the environment map by program sfx/cubemap. This renderprogram will automatically choose the correct environment map to be drawn on top of your material.

Using a predefined template for reflections

ETQW also has a set of templates for more accurate reflections ("fresnel" effect, so that the reflection gets more pronounced when seen from a wide angle). These are used primarily for windows and glass effects. There are several different templates depending on what effect you want, these are fully shown at the top of the base/materials/window.mtr file.

Here is an example of a material using the templates/windowglass_specular template.

material textures/window/ghosttown_window1_framed
{
	nonsolid
	noshadows
	translucent
	useTemplate templates/windowglass_mask <
		"textures/window/ghosttown_window1_framed_d.tga",
		"textures/window/ghosttown_window1_framed_local.tga",
		"textures/window/ghosttown_window1_framed_mask.tga",
		2, 1.0, 0.6
	>
}

If you use a template like this, it will automatically set up the environment maps in the template. The reflection amount is controlled by the alpha channel of the diffuse texture.