PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.18k stars 1.23k forks source link

MaterialX scalar displacement is misdetected as vector displacement inside UsdMtlxRead #3325

Closed jessey-git closed 1 month ago

jessey-git commented 2 months ago

Description of Issue

The MaterialX <displacement> construct can either be a float scalar or a vector3 vector[1] which should end up resolving to either a ND_displacement_float or a ND_displacement_vector3 respectively[2].

However, it looks like the USD MaterialX reader doesn't take the input type into account and always assigns scalar float displacement as ND_displacement_vector3

[1] https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/documents/Specification/MaterialX.Specification.md#standard-library-shader-nodes [2] See the nodedefs inside: https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/pbrlib/pbrlib_defs.mtlx

Steps to Reproduce

  1. Given the following MaterialX document:

    <?xml version="1.0"?>
    <materialx version="1.38">
    <displacement name="Displacement" type="displacementshader">
    <input name="displacement" type="float" value="0.5" />
    <input name="scale" type="float" value="0.1" />
    </displacement>
    <surfacematerial name="TestMaterial" type="material">
    <input name="displacementshader" type="displacementshader" nodename="Displacement" />
    </surfacematerial>
    </materialx>
  2. Observe what happens while loading it -- here I'm also using TF_DEBUG=USDMTLX_READER

    MaterialX::DocumentPtr mtlx_doc = MaterialX::createDocument();
    MaterialX::readFromXmlFile(mtlx_doc, "t:/scalar-displace.mtlx");
    pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory();
    pxr::UsdMtlxRead(mtlx_doc, stage, pxr::SdfPath("/root"));

Output:

Adding mtlxMaterial 'TestMaterial'
Adding shaderNode 'Displacement' type: 'displacementshader'
Created shader mtlx ND_displacement_vector3, as usd ND_displacement_vector3
Add shader output out of type displacementshader
Coding Error: in _SetValueImpl at line 6725 of C:\db\build\S\VS1564R\build\usd\src\external_usd\pxr\usd\usd\stage.cpp -- Type mismatch for </root/Materials/TestMaterial.inputs:displacement>: expected 'GfVec3f', got 'float'

System Information (OS, Hardware)

Package Versions

Build Flags

jesschimein commented 2 months ago

Filed as internal issue #USD-10209

klucknav commented 1 month ago

This issue is fixed in 24.08 and above.