Search Results for

    Show / Hide Table of Contents

    合并 PBR 遮罩贴图

    中文 | English

    在仓库根目录运行以下命令,用本机 Unity MCP 回放本页示例。

    python Docs/Manual/manual/tools/tutorials.py run merge-texture-channels
    
    1. 在模组 SDK 的 GM 编辑器 → 合并遮罩贴图 打开 Remap PBR Masks。
    2. 按槽位填入 metallic、occlusion、smoothness。手里只有粗糙度图时,将它放入 smoothness 槽,勾选 Is Roughness。
    3. 点击 Create Mask Map 并保存 PNG。输出使用 metallic 贴图的尺寸,未指定 metallic 时使用 512 × 512。
    输出通道 读取内容
    R metallic 的红色通道
    G occlusion 的绿色通道
    B 0
    A smoothness 的红色通道,经工具的平滑度转换。使用 roughness 时转换后再反相
    点击展开 MCP 操作点击收起 MCP 操作
    [
      {
        "tool": "inspect",
        "arguments": {
          "path": "static:UnityEngine.SystemInfo/graphicsDeviceName"
        },
        "expect": {
          "contains": "(String)"
        }
      }
    ]
    
    点击展开 MCP 操作点击收起 MCP 操作

    DE 中验证 shader 的独立样例。需有相邻的 Panzer-War-Mod-SDK 工作副本,且工程内的 TutorialMaskTest 目录尚未存在。

    [
      {
        "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"
        }
      }
    ]
    

    将输出用作材质的遮罩贴图。回放验证了 SDK shader 的数值和粗糙度分支,最终外观在载具材质上检查。

    In this article
    Back to top Panzer War Document