Difference between revisions of "Reflective Materials"

From Valve Developer Community
Jump to: navigation, search
m (revert)
Line 44: Line 44:
 
<code>"$envmapsaturation" .5</code>
 
<code>"$envmapsaturation" .5</code>
  
'''Note:''' For the reflection to work correctly in the game, your map must have at least one <code>env_cubemap</code> in it, and after you open the map in the game, open the [[console]] and type <code>buildcubemaps</code>.
+
'''Note:''' For the reflection to work correctly in the game, your map must have at least one <code>env_cubemap</code> in it, and after you open the map in the game, open the [[console]] and type <code>buildcubemaps</code>.  The game will then reload all of your materials with correct reflections if sv_cheats 1 is set, otherwise you will need to restart the level to see the reflections correctly.
  
 
Here's an example VMT for a reflective, normalmapped material:
 
Here's an example VMT for a reflective, normalmapped material:

Revision as of 18:05, 23 October 2007

You can add a pseudo-3D reflection to your material. It makes normal mapped materials look far more three-dimensional, because the reflection will bend appropriately according to the normal map. These reflections will be based on the nearest env_cubemap entity.

Adding reflection (shininess) to a material

1. Add this line to your VMT somewhere between the braces:
"$envmap" "env_cubemap"

2. You will probably want to tone your reflection down by adding this line:
"$envmaptint" "[1 1 1]"

Change the three ones to make your reflection dimmer. The three numbers scale red, green, and blue individually, but usually, you will want to change all three to the same number. The numbers you put in here will be multiplied by the opacity of the reflection.

This will require some testing to get just right for each material. If your material has different levels of shininess, then adjust for the most reflective part of the material and then refer to the section on masking below. Here are some values to start you off closer to what you need:

[ 1 1 1 ]
This is the highest level you would probably ever use. It might be used on a polished metal and will look almost as reflective as a mirror.
[ .3 .3 .3 ]
This is a good value for gloss paint.
[ .07 .07 .07 ]
This is a good value for concrete and sand. Shininess is just barely noticeable. Don’t use a reflection on concrete or sand if it doesn’t have a normal map, though (looks weird).

3. You may want to adjust your reflection’s contrast and saturation with this line:
"$envmapcontrast" 0.5

The number should be between zero and one. Higher values will make the reflection look shinier without looking more reflective, if that makes sense. This might be useful for glass, which has more glaring reflections than other materials.

More detail on $envmapcontrast and $envmapsaturation:
ie. to leave envmap color unaffected:
"$envmapcontrast" 0

ie. to square envmap color (color*color):
"$envmapcontrast" 1

ie. to do a 50% blend between envmap color and envmap color squared:
"$envmapcontrast" .5

You can also use $envmapsaturation to tweak the saturation of the envmap, ie:

ie. to leave color unaffected by saturation:
"$envmapsaturation" 1

ie. to make the envmap color greyscale:
"$envmapsaturation" 0

ie. to do a 50% blend between envmap color and greyscale:
"$envmapsaturation" .5

Note: For the reflection to work correctly in the game, your map must have at least one env_cubemap in it, and after you open the map in the game, open the console and type buildcubemaps. The game will then reload all of your materials with correct reflections if sv_cheats 1 is set, otherwise you will need to restart the level to see the reflections correctly.

Here's an example VMT for a reflective, normalmapped material:

"LightmappedGeneric"
{
    "$basetexture" "walls/brickwall"
    "$surfaceprop" "brick"
    "$bumpmap" "walls/brickwall_normal"
    "$envmap" "env_cubemap"
    "$envmaptint" "[.5 .5 .5]"
}

Masking the reflection

Some materials will have varying amounts of shininess. For example, a metal texture would not be very shiny wherever it's rusty. A mask will allow you to determine the reflectivity of each pixel of your texture.

1. Start by making the mask in grayscale at the same resolution as your original texture. The brightness of the mask will be multiplied by the opacity of the envmap, on top of the envmaptint. In other words, black means no reflection and white means full reflection. The rest of the steps depend on whether your material has a normal map:

2a. Masking a material with a normal map
Save the mask into the alpha channel of your normal map. Now add this line to your VMT:

"$normalmapalphaenvmapmask" 1

2b. Masking a material without a normal map
Save the mask as a new TGA file (no alpha channel) with _mask at the end of the name. Convert it to VTF and put it in the same directory as your texture. Add this line to your VMT:

"$envmapmask" "texture name"

and fill in the path and name of your mask.

Here's an example VMT for a material with a normal map. Since we already have a normal map, we'd just embed the mask into the alpha channel of the normal map, as described in step 2a.

"LightmappedGeneric"
{
    "$basetexture" "walls/brickwall"
    "$surfaceprop" "brick"
    "$bumpmap" " walls/brickwall_normal"
    "$envmap" "env_cubemap"
    "$envmaptint" "[.5 .5 .5]"
    "$normalmapalphaenvmapmask" 1
}

HDR and reflections

You might have noticed that in HDR reflective materials are a lot more shiny then LDR. Valve added the following lines to reflective materials in Episode One:

"LightmappedGeneric"
{
    ****normal vmt stuff here***
    "$envmaptint" "[ .56 .67 .75 ]"
    ****normal vmt stuff here***
 
    "LightmappedGeneric_DX9_hdr"
      {
      // put HDR override stuff here
      "$bumpmap" "metal/metalwall077a_normal"
      "$normalmapalphaenvmapmask" 1
      "$envmaptint" "[ .09 .1 .12]"
      }
}

Notice how they lowered the envmaptint value for HDR.

See also