Difference between revisions of "Environment Maps"

From Mod Wiki
 
(Updated with material info and better descriptions)
Line 3: Line 3:
 
{{main|Environment Maps}}</includeonly><noinclude>
 
{{main|Environment Maps}}</includeonly><noinclude>
  
== Using Environment Maps ==
+
= Using Environment Maps =
 +
First you need to create environment maps that match locations in your level. You can do this by placing [[entity info_envmap|info_envmap]] entities in editWorld.
  
There are a few ways you can use an environment map:
+
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:
* '''specify it inside a material'''
+
* '''Use it with a [[entity light_ambient|light_ambient]] entity.'''
* '''used with a light_ambient'''
+
* '''Use it with an [[entity info_envbound|info_envbound]] entity.'''
* '''used by info_envbounds'''
 
  
We'll go over how to setup an environment map with a light_ambient and an info_envbounds.
+
Once these areas are defined, you can set up materials to use the cubemaps as environment reflection images.
  
=== Placing info_envmaps ===
 
  
Setting one up with a light_ambient is fairly straight forward. 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''' which tells the entity what size you want the images to be, so give that a value of '''128''' then you need to set the name of your environment map '''env_name''' and give it a value of '''my_env_map'''.
+
== Placing an [[entity info_envmap|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'').
  
Compile your map, after it's done load it, and bring down the console and type '''makeenvmaps''' this will locate all info_envmaps and make the environment maps.
+
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.
  
=== Adding it to light_ambients ===
+
For best results during this stage, make sure you are running the game in 640x480 and a 4:3 aspect ratio ( '''r_aspectratio 0''' ).
  
Bring down the console still open, type in editambient, this will bring up a new window, at the bottom of the window it will have '''Env. Cubemap''' with a dialogue and button next to it, click that button and go to the '''base/env''' folder where your new environment map is stored and click ok, you may need to reload the engine for it take effect.
 
  
=== Using info_envbounds ===
+
== Used with a [[entity light_ambient|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]].
  
Repeat the process of placing an info_envmap.
+
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.
  
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_envbounds brush entity, which means when a player walks into this brush volume it'll switch to the environment map that you specified in the info_envbounds.
+
You may need to reload the engine for these changes to take effect.
  
To do this, you'll need to drag a brush out over the area you want to have the info_envounds (they can consist of multiple brushes) and with the brush/es still selected right click and navigate to info_envbounds.
 
  
You'll then need to add one key and value to this entity which is '''env_name''' and for example '''env/my_env_map''' so it knows what environment map to use.
+
== Used with an [[entity info_envbound|info_envbound]] entity ==
 +
Repeat the process of placing an info_envmap for each new area you want to have a unique environment map.
  
Compile your map, after it's completed compiling, load it up and check out your new environment inside the info_envbounds.
+
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 [[entity info_envbound|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.
 
'''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 [[materials|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
 +
}
 +
<font color="blue"><b>{
 +
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
 +
}</b></font>
 +
}
 +
 +
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.
 +
  
 
[[Category:Level Design]]
 
[[Category:Level Design]]
 
[[Category:Art]]
 
[[Category:Art]]
 
</noinclude>
 
</noinclude>

Revision as of 11:56, 5 November 2007

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

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.