adobe/USD-Fileformat-plugins

Connections from Shader to Material inputs do not work

olihey opened this issue · 2 comments

Expected Behaviour

The example USDA file (see end) should export as two red planes.

Actual Behaviour

The plane which has the connection from the shader to the custom input on the material (/test/does_not_work) is white and not red while to one with the color set is still red in the exports. Usdview shows two red planes.
I only tried GLB & FBX but could see the behavior in both.

Reproduce Scenario (including but not limited to) & Steps to Reproduce

Export the attached USDA to re-produce

usdcat.exe .\test.usda -o .\test.fbx

Platform and Version

Windows 11, USD 23.11, compiled with Visual Studio 2022

Sample Code that illustrates the problem

#usda 1.0
(
    defaultPrim = "test"
)

def Scope "test"
{
    def Mesh "does_not_work" (
        prepend apiSchemas = ["MaterialBindingAPI"]
    )
    {
        uniform bool doubleSided = 1
        float3[] extent = [(-0.5, 0, -0.5), (0.5, 0, 0.5)]
        int[] faceVertexCounts = [4]
        int[] faceVertexIndices = [0, 1, 3, 2]
        rel material:binding = </test/does_not_work/material>
        point3f[] points = [(-0.5, 0, 0.5), (0.5, 0, 0.5), (-0.5, 0, -0.5), (0.5, 0, -0.5)]
        texCoord2f[] primvars:st = [(0, 0), (1, 0), (0, 1), (1, 1)] (
            interpolation = "faceVarying"
        )
        int[] primvars:st:indices = [0, 1, 3, 2]

        def Material "material"
        {
            color3f inputs:color = (1, 0, 0)
            token outputs:surface.connect = </test/does_not_work/material/shader.outputs:surface>
            def Shader "shader"
            {
                uniform token info:id = "UsdPreviewSurface"
                color3f inputs:diffuseColor.connect = </test/does_not_work/material.inputs:color>
                token outputs:surface
            }
        }
    }

    def Mesh "works" (
        prepend apiSchemas = ["MaterialBindingAPI"]
    )
    {
        uniform bool doubleSided = 1
        float3[] extent = [(-0.5, 0, -0.5), (0.5, 0, 0.5)]
        int[] faceVertexCounts = [4]
        int[] faceVertexIndices = [0, 1, 3, 2]
        rel material:binding = </test/works/material>
        point3f[] points = [(-0.5, 0, 0.5), (0.5, 0, 0.5), (-0.5, 0, -0.5), (0.5, 0, -0.5)]
        texCoord2f[] primvars:st = [(0, 0), (1, 0), (0, 1), (1, 1)] (
            interpolation = "faceVarying"
        )
        int[] primvars:st:indices = [0, 1, 3, 2]

        double3 xformOp:translate = (-1.1, 0, 0)
        uniform token[] xformOpOrder = ["xformOp:translate"]

        def Material "material"
        {
            token outputs:surface.connect = </test/works/material/shader.outputs:surface>
            def Shader "shader"
            {
                uniform token info:id = "UsdPreviewSurface"
                color3f inputs:diffuseColor = (1, 0, 0)
                token outputs:surface
            }
        }
    }
}

Thanks for the report, this is a bug in our layerRead function.

UsdShadeSourceInfoVector sources = shadeInput.GetConnectedSources();
needs to be refactored to use https://openusd.org/release/api/class_usd_shade_input.html#a2850314096019df0a017b321719b3c70. There might be a fix for the next release, I'll keep you posted.

This is fixed in v1.0.4. Please reopen if you are still having issues.