1

I've been trying to figure out a way to mix textures in USDZ, but I can't find anything.

Say I have a model with three textures and three UV Channels. I have texture A on channel 1, texture B on channel 2, and a mask texture on channel 3. I want to blend texture A with texture B using the mask texture and use this composition as color texture. Its a simple math like:

(A * mask) + (B * (1 - mask)) 

Is there no way of doing this by editing the USDA material def? I did get the textures connected to the respective UV channels, they show up with the assigned UVs when viewing on iOS, but can't find any documentation on adding/multipying the textures.

EDIT: illustration bellow enter image description here

Need a way to define Texture3 in USDA code for desired result. Or a similar workaround:

def Material "MixedMaterial"
{
    token outputs:surface.connect = </Object1/MixedMaterial/SurfaceShader.outputs:surface>

    def Shader "SurfaceShader"
    {
        uniform token info:id = "UsdPreviewSurface"
        color3f inputs:diffuseColor.connect = </Object1/MixedMaterial/Texture3.outputs:rgb>
        token outputs:surface
    }

    def Shader "Texture0"
    {
        uniform token info:id = "UsdUVTexture"
        asset inputs:file = @textureA.jpg@
        float2 inputs:st.connect = </Object1/MixedMaterial/Texture0/TexCoordReader0.outputs:result>
        token inputs:wrapS = "repeat"
        token inputs:wrapT = "repeat"
        float outputs:r
        float3 outputs:rgb

        def Shader "TexCoordReader0"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            token inputs:varname = "UV_Channel_1"
            float2 outputs:result
        }
    }

    def Shader "Texture1"
    {
        uniform token info:id = "UsdUVTexture"
        asset inputs:file = @textureB.jpg@
        float2 inputs:st.connect = </Object1/MixedMaterial/Texture1/TexCoordReader1.outputs:result>
        token inputs:wrapS = "repeat"
        token inputs:wrapT = "repeat"
        float outputs:r
        float3 outputs:rgb

        def Shader "TexCoordReader1"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            token inputs:varname = "UV_Channel_2"
            float2 outputs:result
        }
    }

    def Shader "Texture2"
    {
        uniform token info:id = "UsdUVTexture"
        asset inputs:file = @Mask.jpg@
        float2 inputs:st.connect = </Object1/MixedMaterial/Texture1/TexCoordReader2.outputs:result>
        token inputs:wrapS = "repeat"
        token inputs:wrapT = "repeat"
        float outputs:r
        float3 outputs:rgb

        def Shader "TexCoordReader2"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            token inputs:varname = "UV_Channel_3"
            float2 outputs:result
        }
    }   
    
}
AGogel
  • 21
  • 5

1 Answers1

0

Python scripting for USD

AFAIK, at the moment, there's no multi-channel compositing ops for USD. However, I could be wrong.

CoreImage compositing

CoreImage framework can help you apply appropriate compositing operations to your textures. There are four filters that similar to The Foundry NUKE's Merge node operations: Over, Out, Multiply and Plus.

  • CISourceOverCompositing
  • CISourceOutCompositing
  • CIMultiplyCompositing
  • CIAdditionCompositing

The pipeline is as simple as that: apply math to your textures using CoreImage compositing tools, save a result to disk, and then apply a brand-new texture to USDZ model in RealityKit.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • Hello Andy, thanks for your input. I think I might not have been very clear with my question though. I need to blend the texutres without editing the textures themselves. I'm looking for a way to do this by editing the material definition in an usda file. I've edited the original post, added an illustration to clarify. – AGogel Nov 11 '21 at 15:32
  • 1
    Sorry about that, didn't know that. It's just that the extra info didnt fit here in comments (character limit). – AGogel Nov 11 '21 at 15:33
  • I have a 3D model with UV coordinates. It's got three UV channels containing three sets of UVs. Each texture is mapped using a different set of UV coordinates - i.e. a different UV channel. I export it to USDZ and I need to recreate the material. – AGogel Nov 11 '21 at 15:36
  • Andy I don't really know that. I don't have deep knowlage of USD. Just working on a project where I need to export quite a few textured 3D models for viewing online on iOS devices in AR. It just so happens that a few of those models have multitexture materials where the textures are blended with a mask - just like in the example in the original question. Its a really simple composition in 3ds max or photoshop, think of it as a layer with a mask on top of another layer. I was able to do this with three.js for example. – AGogel Nov 11 '21 at 16:23