Preview a mask texture in Unity
中文 | 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 mask-texture-preview
Click to expand MCP actionsClick to collapse MCP actions
Prepare the teaching sample. The recipe provides ${variables}.
{
"variables": {
"material": "${fixture}/Tutorial_Prop.mat",
"settings": "${fixture}/Tutorial_MaterialSettings.asset",
"model": "${fixture}/Tutorial_Material.prefab",
"texture": "${fixture}/TutorialMask.png"
},
"calls": [
{
"tool": "invoke",
"arguments": {
"path": "static:UnityEditor.AssetDatabase/CreateFolder",
"args": [
"${fixtureParent}",
"${folder}"
]
},
"expect": {
"contains": "(String)"
}
}
]
}
- Import your mask texture and turn off sRGB (Color Texture). Check the channel mapping in PBR mask channel merging.
- Duplicate the preview material and select WindyVerse/Vehicle/FullPBR. Assign the texture to _MaskMap, then put the material on a separate model.
Click to expand MCP actionsClick to collapse MCP actions
[
{
"tool": "invoke",
"arguments": {
"path": "static:ShanghaiWindy.Core.AssetBundleManager/LuaEnv/DoString",
"args": [
"local U = CS.UnityEngine\nlocal source = U.Texture2D(2, 2, U.TextureFormat.RGBA32, false, true)\nlocal color = U.Color(0.24, 0.76, 0, 0.5)\nfor x = 0, 1 do\n for y = 0, 1 do source:SetPixel(x, y, color) end\nend\nsource:Apply()\nlocal png = U.ImageConversion.EncodeToPNG(source)\nCS.System.IO.File.WriteAllBytes('${texture}', png)\nlocal copy = U.Texture2D(2, 2, U.TextureFormat.RGBA32, false, true)\nassert(U.ImageConversion.LoadImage(copy, png, false))\nlocal pixel = copy:GetPixel(0, 0)\nassert(math.abs(color.r - pixel.r) < .005 and math.abs(color.g - pixel.g) < .005)\nassert(math.abs(color.b - pixel.b) < .005 and math.abs(color.a - pixel.a) < .005)\nU.Object.DestroyImmediate(source)\nU.Object.DestroyImmediate(copy)\nreturn \"PNG channel sample verified\"\n",
"tutorial-pbr-mask",
"null"
]
},
"expect": {
"contains": "PNG channel sample verified"
}
},
{
"tool": "invoke",
"arguments": {
"path": "static:UnityEditor.AssetDatabase/ImportAsset",
"args": [
"${texture}",
"ForceSynchronousImport"
]
},
"expect": {
"contains": "OK:"
}
},
{
"tool": "inspect_set",
"arguments": {
"path": "importer:${texture}/sRGBTexture",
"value": "false"
},
"expect": {
"contains": "OK:"
}
},
{
"tool": "inspect",
"arguments": {
"path": "importer:${texture}/sRGBTexture"
},
"expect": {
"contains": "(Boolean) False"
}
},
{
"tool": "invoke",
"arguments": {
"path": "static:UnityEditor.AssetDatabase/CopyAsset",
"args": [
"Packages/com.shanghaiwindy.coreresources/BuiltInVehicles/Altius-U/Art/Default-FastProp.mat",
"${material}"
]
},
"expect": {
"contains": "(Boolean) True"
}
},
{
"tool": "inspect",
"arguments": {
"path": "asset:${material}/shader/name"
},
"expect": {
"contains": "WindyVerse/Vehicle/FullPBR"
}
},
{
"tool": "invoke",
"arguments": {
"path": "asset:${material}/HasProperty",
"args": [
"_MaskMap"
]
},
"expect": {
"contains": "(Boolean) True"
}
},
{
"tool": "invoke",
"arguments": {
"path": "asset:${material}/SetTexture",
"args": [
"_MaskMap",
"@asset:${texture}"
]
},
"expect": {
"contains": "OK:"
}
},
{
"tool": "inspect",
"arguments": {
"path": "asset:${material}/GetTexture(_MaskMap)/name"
},
"expect": {
"contains": "(String) TutorialMask"
}
},
{
"tool": "prefab_edit",
"arguments": {
"json": {
"path": "${model}",
"mode": "create",
"component": "UnityEngine.MeshRenderer",
"values": {
"m_Materials": [
{}
]
},
"references": [
{
"property": "m_Materials.Array.data[0]",
"asset": "${material}",
"type": "UnityEngine.Material"
}
]
}
},
"expect": {
"equals": {
"ok": true
}
}
},
{
"tool": "inspect",
"arguments": {
"path": "asset:${model}/MeshRenderer/sharedMaterial/GetTexture(_MaskMap)/name"
},
"expect": {
"contains": "(String) TutorialMask"
}
}
]
- In a lit scene, check metallic response, occlusion, and smoothness. Review the model's runtime material overrides. Material component guide