===== Creating Alpha Masks in Blender =====
==== Introduction ====
Alpha is the fourth channel of an image, it acts as a mask and is usually used for transparency. In Source engine it can be used for multiple things such as transparency, colorable textures, and different kind of masks, e.g. phong mask.
This tutorial will cover the creation of transparent and colorable textures using Blender.
----
==== Why Blender ====
I'm using Blender because it allows you to paint directly on the model and preview how it's gonna look in-game. If you know how to apply this tutorial to your own software then feel free to do so.
----
==== Requirements ====
Tools that you will need:
**[[:tools#blender|Blender + Blender Source Tools]]**
**[[:tools#crowbar|Crowbar]]** - Decompiling
**[[:tools#texture-image-editors|VTFEdit or Paint.NET + .VTF plugin]]** - Converting textures
----
==== Preparation ====
=== Getting files ===
First you have to get the model and texture that you want to edit. See **[[tutorial:extracting-files|]]** for information on how to extract those from the game.
For this tutorial I'll be using **Alyx**, and my goal is to make part of her pants invisible, the required files are:
**Model** (all model files are required):
* **alyx.mdl**
* **alyx.dx80.vtx**
* **alyx.dx90.vtx**
* **alyx.phy**
* **alyx.vvd**
**Texture** (only get the textures you want to edit):
* **plyr_sheet.vtf**
Material files are not needed but you can extract and open them if you don't know which textures you should get.
----
=== Decompiling Models ===
To actually do something with the extracted model you have to decompile it first.
To decompile your model open **[[:tools#crowbar|Crowbar]]** and go to the **Decompile** tab. Select your model by clicking **''Browse''** in the **MDL input** line, then select the output folder and click **''Decompile''**.
From all the decompiled files only one is actually needed, in this case alyx_reference.smd. The name will be different depending on the model you're using but for most GMod models its _reference.smd.
----
=== Converting Textures ===
Before you can edit the textures you'll have to convert them to a different format. This step is pretty simple, all you have to do is open the **.vtf** file in **[[:tools#vtfedit|VTFEdit]]** or **[[:tools#paint.net|Paint.NET]]** and save it as a **.png** file.
----
==== Working with Blender ====
At this point you should have:
* **Blender** and **Blender Source Tools** installed
* **.SMD** model file (alyx_reference.smd)
* **.PNG** texture file (plyr_sheet.png)
----
=== Importing ===
First you have to import your model to **Blender**.
- Open **Blender** and go to **''File''** > **''Import''** > **''Source Engine''**.
- In the window that appears, go to where you extracted your files.
- Select your **.smd** file and click **''Import SMD...''** at the bottom.
----
=== Basic controls ===
Here are some very basic controls if you're new to **Blender**:
* **''RMB''** - Select objects
* **''MMB''** - Rotate view
* **''Shift + MMB''** - Pan view
* **''Mouse Wheel''** - Zoom
* **''. Numpad''** - View selected
----
=== Material Setup ===
Before you paint the texture you need to set up the material so that you get a preview of how it's gonna look in the game.
- **''Right Click''** on the skeleton (one of the spheres) and press H to hide it.
- Switch to the **Shading** workspace (at the top).
- Go to the **Material Properties** panel.
- Select the material that you want to work on. The material name is always the same as the in-game material (**.VMT** file). In my case it is plyr_sheet.
- Click on **''Use Nodes''**.
- Scroll down to **Settings** and change **Blend Mode** to **Alpha Clip**.
----
== Node Controls ==
* **''RMB''** - Select Node
* **''X''** - Delete Node
* **''Shift''** + **''A''** - Add Node
* **''G''** - Move
----
== Node Setup ==
- Delete the ''**Principled BSDF**'' node.
- Add **''Mix Shader''** node, connect the //**Shader**// output to the //**Surface**// input on **''Material Output''**.
- Add **''Diffuse BSDF''** node, connect the //**BSDF**// output to the bottom //**Shader**// input on **''Mix Shader''**.
- Add **''Transparent BSDF''** node, connect the //**BSDF**// output to the top //**Shader**// input on **''Mix Shader''**.
- Add **''Image Texture''** node, connect the //**Color**// output to the //**Color**// input on **''Diffuse BSDF''** and the //**Alpha**// output to the //**Fac**// input on ''**Mix Shader**'', then click **''Open''** and select your texture.
----
=== Texture Painting ===
Switch to the **Texture Paint** workspace (at the top). The left panel shows your texture, the right one shows the model, you can paint on any of them. That's it, now you can paint on your texture. There isn't much to say about it, just remember:
* To decrease the alpha value change the blending mode to **Erase Alpha**.
* To increase the alpha value change the blending mode to **Add Alpha**.
----
=== Saving ===
- Once you're done painting, hover over the texture and press **''Shift''** + **''Alt''** + **''S''**.
- In the window that pops up select the save location.
- Set **File Format** to **.PNG** and **Color** to **RGBA**.
- Click **''Save As Image''**.
----
=== Replacing the texture in PAC ===
If you don't know how to use it in PAC follow [[:tutorial:replacing-materials]].
----
If you have any questions ask in the **#help** channel of the {{icon:discord.png?nolink}} [[https://discordapp.com/invite/utpR3gJ|Official PAC Discord]]