Difference between revisions of "Reflective Materials"

From Valve Developer Community
Jump to: navigation, search
m (Masking the reflection)
m (Reverted edit of Trtac4tcab, changed back to last version by TomEdwards)
(17 intermediate revisions by 14 users not shown)
Line 1: Line 1:
[[category:material system]][[category:tutorials]]
#redirect [[$envmap]]
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:<br/>
<code>"$envmap" "env_cubemap"</code>
'''2.''' You will probably want to tone your reflection down by adding this line:<br/>
<code>"$envmaptint" "[1 1 1]"</code>
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:<br/>
;[ 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.<br/>
;[ .3 .3 .3 ]
:This is a good value for gloss paint.<br/>
;[ .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 with this line:<br/>
<code>"$envmapcontrast" 0.5</code>
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.
'''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 <code>buildcubemaps</code>.
Here's an example VMT for a reflective, normalmapped material:
    "$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. The rest of the steps depend on whether your material has a normal map:
'''2a.'''  ''Masking a material with a normal map''<br/>
Save the mask into the alpha channel of your normal map. Convert this new normal map to a VTF and replace the original normal map. Now add this line to your VMF:
<code>"$normalmapalphaenvmapmask" 1</code>
'''2b.''' ''Masking a material without a normal map''<br/>
Save the mask as a new TGA file (no alpha channel) with _mask at the end of the name. Convert it to a VTF and put it in the same directory as your texture. Add this line to your VMF:
<code>"$envmapmask" "''texture name''"</code>
and fill in the path and name of your mask.
For the example, perhaps we would want to make the bricks shinier than the plaster.  Since we already have a normalmap, we'd just embed the mask into the alpha channel of the normal map, as described in step 2a.  The example VMT from above would now look like this:
    "$basetexture" "walls/brickwall"
    "$surfaceprop" "brick"
    "$bumpmap" " walls/brickwall_normal"
    "$envmap" "env_cubemap"
    "$envmaptint" "[.5 .5 .5]"
    "$normalmapalphaenvmapmask" 1
==See also==
[[Creating Materials]]
[[Creating Normal Maps]]
[[Creating a Material Tutorial]]

Latest revision as of 19:37, 16 December 2008

Redirect to: