Garry's Mod

Garry's Mod

评价数不足
How to make a functional light reflector
由 An_Unknown_Player[FIN] 制作
In this guide I'll show a way on how to make a fully functional light reflector on the source engine, without using "$selfillum" (emissive or self illuminated materials). If you have any questions or better ways on how to create a similar effect, then feel free to put them in the comments :)

Note: This guide doesn't tell how to use the tools, so please search the appropriate tutorials for them. Thank you!

Hope you find this useful!
   
奖励
收藏
已收藏
取消收藏
Tools used
Here's a list of tools that were used during the creation of this guide.
  • Krita
    (Texture creation and editing)
  • VTFEdit
    (Converting textures into VTFs)
  • Notepad++
    (VMT creation)
  • Blender
    (Model/material editing)
  • Blender Source Tools
    (Giving Blender the ability to import and export SMDs/DMXs)
  • Source IO
    (Giving Blender the ability to import Source files)
  • Crowbar Source Engine Modding Tool
    (For compiling/decompiling models)
Textures
Here we'll go through the textures that are needed.
Base texture
Obviously you'll need a base texture, it can also be called a color, albedo or diffuse texture.
Pretty self-explanatory on what it is, but here's an example anyway:


Normal map with an alpha channel
Next thing you'll need is a Normal map, which adds bumps to your base texture, so it'll look a bit more realistic. But you might be asking, why does it need an alpha channel? Well that's required, because the alpha channel is used as a phong boost mask. So the more transparent it is the weaker the phong will be and when making reflective textures you should make all nonreflective parts be transparent and the reflective parts be nontransparent.
Here's an example:


Phong exponent texture
Then finally you'll need a phong exponent texture, which controls the size of the highlight. Now normally you would make it a grayscale image, but on the source engine we use a colored image.
Here's what each of the RGB channels do:
  • Red: Controls the size of the highlight (0 = big highlight and 255 = small highlight)
  • Green: Controls the tint of the highlight (0 = no tint and 255 = full tint)
    (Only works when you've set $phongalbedotint to 1 in your VMT)
  • Blue: Nothing
(If you want to learn more about phong lighting the go here: https://developer.valvesoftware.com/wiki/$phong )
Example image:

When making reflective textures you should make the reflective parts green (preferably solid green), because then that part of the texture will make the highlight have the color of the base texture and the nonreflective parts red, the shade of red depends on the material that your texture is supposed to be. (Just fiddle around with the shades until you're happy with the result)
More about alpha channel normal maps
As I said transparent parts of a normal map makes the phong highlight weaker, but how do you make a normal map with an alpha channel? Here's the steps you'll need to do. (If there's another way feel free to tell me)

First you take your normal map and it'll look something like this:


Now add a new layer and paint over the nonreflective parts (doesn't matter what color you use, just have the opacity of the brush at 100%) and you'll be left with something like this:


Next click on the blend modes and select "Erase" and your normal map will look like this:

It's also a good idea to set the opacity of the erase layer to 99% or lower if you want the nonreflective parts to still have some amount of phong lighting.

If your image editing software doesn't have a blend mode that's called erase, then go through the list of blend modes until you find one that does a similar effect.
You can use a transparency mask to get it to work as well, but I would recommend to make an erase layer, because it's a bit more controllable.

In game screenshots
Without alpha channel:


With alpha channel
VMT (Vavle Material) parameters
In this section we'll go through the VMT parameters you'll need to use.

Here's what the VMT for the reflector strap model looks like:
Material name: Reflector_Strap
"VertexLitGeneric" { "$basetexture" "models\Unknowns_Models\Reflectors\Reflector_Strap\Reflector_Strap_diffuse" "$bumpmap" "models\Unknowns_Models\Reflectors\Reflector_Strap\Reflector_Strap_normal" "$halflambert" "1" "$phong" "1" "$phongboost" "10" "$phongalbedotint" "1" "$phongexponenttexture" "models\Unknowns_Models\Reflectors\Reflector_Strap\Reflector_Strap_exp" "$phongfresnelranges" "[1 1 0.5]" }
Parameter short explanations (mostly for new creators):
  • $basetexture: base texture (duh)
  • $bumpmap: normal map
  • $phong: enables/disables phong lighting
  • $phongboost: sets the strength of phong lighting
  • $phongalbedotint: makes phong lighting use the tint of the base texture
  • $phongexponenttexture: texture that determines the exponent of phong lighting (size of the highlight)
Better explanations for:

Mess around with the parameters until you'll have a pleasing result.
(Optional) Reassigning materials to mesh
We've now gone through the main steps of creating reflective textures and materials, but sometimes these steps are not the best way for some models, so we'll sometimes need to separate the materials. This also makes it not require a normal map with an alpha channel, because we can control the phong strength with "$phongboost", which also gives us even more control over it.

I'll tell you two ways to separate the materials, because some models require a more complex way to do so.

Easy model
  1. Open Blender and open the .blend file for your model.
    If you're using Source tools and have a decompiled model, import an SMD.
    If you're using Source IO, you can import the .mdl file directly.
  2. Select the model and go to edit mode
  3. Then select the faces of the model that you want to make a reflective texture.

  4. Go to materials (1), add a new material (2) then click assign (3).

    Now you've assigned the selected faces to the new material.
  5. Name the material something like this "(material name) reflective", so that you'll instantly know that it's supposed to be the reflective one.

"Complex" model
  1. Follow steps 1 and 2 from above.
  2. Select the faces of the mesh that include your reflective material.

  3. Press shift + D or go to "mesh -> Duplicate" to create a duplicate of the selected faces.
  4. Press P or go to "mesh -> Separate" and click on "by selection" to separate the selected faces to it's own mesh.
  5. Follow steps 4 and 5 from above.
Now you've separated the faces and created the new material, but we're not done yet. We need to add transparency to the base texture, so that only the transparent parts of the texture will be visible on the reflective material and we'll be using the same trick as with the normal map.
  1. Open the base texture image.
  2. Create a new layer and paint over the nonreflective parts.
  3. Change the blend mode of the layer to erase.
  4. Save the texture.
Now you've made the a new material and made the base texture transparent around the reflective parts.
Now if I were to make this for the reflector strap model I would need to make a new material (VMT) and also change the VMT parameters.
Reflective material:
Material name: Reflector_Strap_Reflective
(Italic bold means new parameter)
"VertexLitGeneric" { "$basetexture" "models\Unknowns_Models\Reflectors\Reflector_Strap\Reflector_Strap_diffuse" "$bumpmap" "models\Unknowns_Models\Reflectors\Reflector_Strap\Reflector_Strap_normal" "$translucnet" "1" "$halflambert" "1" "$phong" "1" "$phongboost" "10" "$phongalbedotint" "1" "$phongexponenttexture" "models\Unknowns_Models\Reflectors\Reflector_Strap\Reflector_Strap_exp" "$phongfresnelranges" "[1 1 0.5]" }
Nonreflective material:
Material name: Reflector_Strap
(Underline means changed parameters)
"VertexLitGeneric" { "$basetexture" "models\Unknowns_Models\Reflectors\Reflector_Strap\Reflector_Strap_diffuse" "$bumpmap" "models\Unknowns_Models\Reflectors\Reflector_Strap\Reflector_Strap_normal" "$halflambert" "1" "$phong" "1" "$phongboost" "0.01" "$phongalbedotint" "1" "$phongexponenttexture" "models\Unknowns_Models\Reflectors\Reflector_Strap\Reflector_Strap_exp" "$phongfresnelranges" "[1 1 0.5]" }
Explanation for the $translucent parameter can be found here:
https://developer.valvesoftware.com/wiki/$translucent
End of guide
This has been the guide for fully functioning reflectors hope this was useful.


As said before, feel free to ask about any unclarities within this guide.

Thank you for reading!

Greetings:
An_Unnkown_Player