adobe / USD-Fileformat-plugins

A collection of USD fileformat plugins
312 stars 21 forks source link

Connections from Shader to Material inputs do not work #20

Closed olihey closed 6 months ago

olihey commented 6 months ago

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
            }
        }
    }
}
kwblackstone commented 6 months ago

Thanks for the report, this is a bug in our layerRead function. https://github.com/adobe/USD-Fileformat-plugins/blob/7bcfd43b79b86360fa23e8dc4775cdb10add6869/utils/layerRead.cpp#L936 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.

kwblackstone commented 6 months ago

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