Skip to content

Wrong shader generated when nodes have the same name #2784

@simdvr

Description

@simdvr

This issue is split from #1871.

The shader generators do not generate the correct code when two nodes have the same name inside two different nodegraphs.
It produces no errors, but a wrong render result.
Apparently this affects all backends. We confirmed it for MDL, GLSL and OSL in MaterialX 1.39.4.

I attached two example mtlx files in the zip: nodenames-example-mtlx.zip
Each material has 2 compounds. Both compounds contain a crosshatch node.
The only difference between the files is the naming of the crosshatch nodes:

  • 2x-crosshatch-diffName.mtlx -- correct rendering (names: crosshatch1 and crosshatch2)
  • 2x-crosshatch-sameName.mtlx -- broken rendering (names: crosshatch1 and crosshatch1)

After PR #2768, the render result is unchanged. One difference to 1.39.4 is that the generated shader code now calls NG_crosshatch_color3 twice instead of once, but both calls use identical parameters. I verified this behavior in both MDL and GLSL. For example, in MDL the generated code now looks like this:

color crosshatch1_out = NG_crosshatch_color3(geomprop_UV0_out1, crosshatch1_uvtiling, crosshatch1_uvoffset, crosshatch1_thickness, crosshatch1_staggered);
color crosshatch1_out1 = NG_crosshatch_color3(geomprop_UV0_out1, crosshatch1_uvtiling, crosshatch1_uvoffset, crosshatch1_thickness, crosshatch1_staggered);

The two crosshatch nodes in the have different input values though (different uvtiling, uvoffset, thickness, and staggered values).

So the end result is the same as before with 1.39.4.

A workaround on the application side is to set globally unique node names on the MaterialX document before passing to the shader generator. Of course we would prefer not needing to apply this workaround.

For reference, this is how the rendering looks in the MaterialXGraphEditor.
The blue one is the correct render result:
Image
Wrong rendering:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions