Merge PBR mask channels
中文 | English
Run this command at the repository root to replay the examples through the local Unity MCP.
python Docs/Manual/manual/tools/tutorials.py run merge-texture-channels
- In the mod SDK's GM Editor, open Remap PBR Masks.
- Assign metallic, occlusion, and smoothness. If you have a roughness map, put it in the smoothness slot and enable Is Roughness.
- Select Create Mask Map and save a PNG. The output uses the metallic texture's dimensions, or 512 × 512 if you omit metallic.
| Output channel | Source |
|---|---|
| R | Red channel of metallic |
| G | Green channel of occlusion |
| B | 0 |
| A | Red channel of smoothness, transformed by the tool. For roughness, the tool inverts the transformed value |
Click to expand MCP actionsClick to collapse MCP actions
[
{
"tool": "inspect",
"arguments": {
"path": "static:UnityEngine.SystemInfo/graphicsDeviceName"
},
"expect": {
"contains": "(String)"
}
}
]
Click to expand MCP actionsClick to collapse MCP actions
Standalone shader check in DE. It needs an adjacent Panzer-War-Mod-SDK checkout and an unused TutorialMaskTest folder.
[
{
"tool": "invoke",
"arguments": {
"path": "static:UnityEditor.AssetDatabase/CreateFolder",
"args": [
"Assets",
"TutorialMaskTest"
]
},
"expect": {
"contains": "(String)"
}
},
{
"tool": "invoke",
"arguments": {
"path": "static:System.IO.File/Copy",
"args": [
"../../../Panzer-War-Mod-SDK/Packages/Sdk/com.shanghaiwindy.middlelayer/Tools/TextureMergeTool/Editor/MaskMap.shader",
"Assets/TutorialMaskTest/SDKMask.shader"
]
},
"expect": {
"contains": "OK:"
}
},
{
"tool": "invoke",
"arguments": {
"path": "static:UnityEditor.AssetDatabase/ImportAsset",
"args": [
"Assets/TutorialMaskTest/SDKMask.shader",
"ForceSynchronousImport"
]
},
"expect": {
"contains": "OK:"
}
},
{
"tool": "invoke",
"arguments": {
"path": "static:ShanghaiWindy.Core.AssetBundleManager/LuaEnv/DoString",
"args": [
"local U = CS.UnityEngine\nlocal function texture(r, g)\n local image = U.Texture2D(2, 2, U.TextureFormat.RGBA32, false, true)\n for x = 0, 1 do\n for y = 0, 1 do\n image:SetPixel(x, y, U.Color(r, g, 0, 1))\n end\n end\n image:Apply()\n return image\nend\nlocal shader = U.Shader.Find(\"Hidden/MaskMap\")\nassert(shader and shader.isSupported, 'SDK MaskMap shader did not import')\nlocal material = U.Material(shader)\nlocal metal, ao, smooth = texture(0.25, 0.4), texture(0.1, 0.75), texture(0.48, 0.8)\nlocal readout = texture(0, 0)\nlocal target = U.RenderTexture(2, 2, 0, U.RenderTextureFormat.ARGB32, U.RenderTextureReadWrite.Linear)\nlocal active = U.RenderTexture.active\nlocal ok, failure = pcall(function()\n material:SetTexture(\"_Metallic\", metal)\n material:SetTexture(\"_Occlusion\", ao)\n material:SetTexture(\"_Smoothness\", smooth)\n for useRoughness = 0, 1 do\n material:SetFloat(\"_UseRoughness\", useRoughness)\n U.Graphics.Blit(metal, target, material)\n U.RenderTexture.active = target\n readout:ReadPixels(U.Rect(0, 0, 2, 2), 0, 0)\n local read = readout:GetPixel(0, 0)\n local expect = smooth:GetPixel(0, 0).r ^ 0.45\n if useRoughness == 1 then expect = 1 - expect end\n assert(math.abs(read.r - .25) < .015 and math.abs(read.g - .75) < .015 and read.b < .01)\n assert(math.abs(read.a - expect) < .015, tostring(read.a) .. ' != ' .. tostring(expect))\n end\nend)\nU.RenderTexture.active = active\nfor _, asset in ipairs({ material, metal, ao, smooth, readout, target }) do U.Object.DestroyImmediate(asset) end\nassert(ok, failure)\nreturn \"SDK RGBA channels and roughness passed\"\n",
"tutorial-mask",
"null"
]
},
"expect": {
"contains": "SDK RGBA channels and roughness passed"
}
},
{
"tool": "invoke",
"arguments": {
"path": "static:UnityEditor.AssetDatabase/DeleteAsset",
"args": [
"Assets/TutorialMaskTest"
]
},
"expect": {
"contains": "(Boolean) True"
}
}
]
Use the output as the material's mask texture. The replay checked numeric values from the SDK shader with both roughness settings. Inspect the final appearance on the vehicle material.