Jump to content

Convert Unity mask texture to occlusion / roughness / metal map


Recommended Posts

This extension adds a menu item in the texture editor that will do the necessary channel swizzle to convert a unity "mask texture" into the standard occlusion / roughness / metal map that Khronos glTF and Ultra use. After the process finishes you can save the texture, probably in DDS format with BC7 compression, and start using it. 

Unity Mask Texture.lua

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

If you want to convert a lot of files in a batch process, you can do something like this:

local dir = LoadDir("mask")

for n = 1, #dir do

    collectgarbage()

    local pixmap = LoadPixmap("mask/"..dir[n])
    if pixmap ~= nil then

        local x, y, r, g, b, a
        for x = 0, pixmap.size.x - 1 do
            for y = 0, pixmap.size.y - 1 do
                local rgba = pixmap:ReadPixel(x, y)
                r = Red(rgba)
                g = Green(rgba)
                b = Blue(rgba)
                a = Alpha(rgba)
                rgba = Rgba(g, 255 - a, r, 255)
                pixmap:WritePixel(x, y, rgba)
            end
        end

        pixmap:Save("mask/"..dir[n])    
    end
end

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...