Skip to content

Fix vec3 variant of gltf_image to include scaling factor - #3055

Open
kwokcb wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
kwokcb:gltf_image_vec3_factor
Open

kwokcb wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
kwokcb:gltf_image_vec3_factor

Conversation

@kwokcb

@kwokcb kwokcb commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Update

Change

  • Add in factor interface input to gltf_image (vec3 variant) of glTF library
  • Update existing BoomBox material to have this factor specified. ORM set to 1,1,1 so no difference for rendering.

Results

This is a sample glTF converted to MaterialX. The ORM texture is scaled in roughness and metallic channels.

glTF

  • metallicFactor = 0.2, and roughnessFactor = 0.8 are the scaling factors to apply on specific channels on the ORM image outputs.
{
  "asset": {
    "generator": "pygltflib@v1.16.5",
    "version": "2.0"
  },
  "images": [
    {
      "uri": "resources/Images/brick_base_gray.jpg",
      "name": "gltf_color"
    },
    {
      "uri": "resources/Images/brick_roughness.jpg",
      "name": "gltf_metallic_roughness"
    }
  ],
  "materials": [
    {
      "pbrMetallicRoughness": {
        "baseColorFactor": [
          0.7714629769325256,
          0.0016784999752417207,
          0.011678500100970268,
          0.5
        ],
        "metallicFactor": 0.2,
        "roughnessFactor": 0.8,
        "baseColorTexture": {
          "index": 0,
          "texCoord": 0
        },
        "metallicRoughnessTexture": {
          "index": 1,
          "texCoord": 0
        }
      },
      "emissiveFactor": [
        0,
        0,
        0
      ],
      "alphaMode": "OPAQUE",
      "doubleSided": false,
      "name": "gltf_pbr_surfaceshader"
    }
  ],
  "samplers": [
    {
      "magFilter": 9729,
      "minFilter": 9986,
      "wrapS": 10497,
      "wrapT": 10497
    }
  ],
  "textures": [
    {
      "sampler": 0,
      "source": 0,
      "name": "gltf_color"
    },
    {
      "sampler": 0,
      "source": 1,
      "name": "gltf_metallic_roughness"
    }
  ]
}

MaterialX Equivalent

The factor input on the ORM image (image_orm) match to the glTF factors as a vector of
[ occluson factor = 1, roughness factor, metalic factor ]. The colorscaling factor on
image_base_color is already supported.

<?xml version="1.0"?>
<materialx version="1.39" doc="" >
  <gltf_pbr name="gltf_pbr_surfaceshader" type="surfaceshader" nodedef="ND_gltf_pbr_surfaceshader">
    <input name="base_color" type="color3" nodename="image_base_color" output="outcolor" />
    <input name="alpha" type="float" value="0.5" />
    <input name="metallic" type="float" nodename="extract_metallic" />
    <input name="roughness" type="float" nodename="extract_roughness" />
    <input name="occlusion" type="float" nodename="extract_occlusion" />
  </gltf_pbr>
  <surfacematerial name="MAT_gltf_pbr_surfaceshader" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="gltf_pbr_surfaceshader" />
  </surfacematerial>
  <gltf_colorimage name="image_base_color" type="multioutput">
    <input name="file" type="filename" value="resources/Images/brick_base_gray.jpg" colorspace="srgb_texture" />
    <output name="outcolor" type="color3" />
    <output name="outa" type="float" />
    <input name="color" type="color4" value="0.771463, 0.0016785, 0.0116785, 0.5" />
  </gltf_colorimage>
  <gltf_image name="image_orm" type="vector3">
    <input name="file" type="filename" value="resources/Images/brick_roughness.jpg" />
    <input name="filtertype" type="string" value="linear" />
    <input name="uaddressmode" type="string" value="periodic" />
    <input name="vaddressmode" type="string" value="periodic" />
    <input name="factor" type="vector3" value="1.0, 0.8, 0.2" /> <!-- new factor -->
  </gltf_image>
  <extract name="extract_occlusion" type="float">
    <input name="in" type="vector3" nodename="image_orm" />
    <input name="index" type="integer" value="0" />
  </extract>
  <extract name="extract_roughness" type="float">
    <input name="in" type="vector3" nodename="image_orm" />
    <input name="index" type="integer" value="1" />
  </extract>
  <extract name="extract_metallic" type="float">
    <input name="in" type="vector3" nodename="image_orm" />
    <input name="index" type="integer" value="2" />
  </extract>
</materialx>

MaterialX Graph Editor

The resulting graph looks like this in the graph Editor

Color + ORM factors Roughness Modified Metallic Modified
image image image

@fallenmi fallenmi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vector3 gltf_image path now matches the existing color3, color4, and float variants: factor is declared on the NodeDef, its neutral default preserves existing documents, and the implementation graph applies it before returning the sampled value. This enables the intended per-channel ORM scaling without changing the default result.

I verified exact head a4de710993f61d0087c70f197b21367ae8dce07c against exact base 39e4c9e04580bb690235667f6b28686e60344773 and current GitHub merge 3f2db9abc2cc2d8cc23c442741a6bc58dde616a1 using the public MaterialX 1.39.5 APIs. A factor-bearing vector3 document is rejected at base with the expected NodeDef interface error; at head and merge it validates and generates factor * image_out in GLSL, MSL, OSL, and MDL. The combined library, boombox example, and neutral-factor compatibility control also validate. All 35 check runs and EasyCLA are green.

Disclosure: I used Codex to inspect the change and run exact-base, exact-head, and current-merge validation and shader-generation oracles. I verified the results and live pull-request state before preparing this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

glTF Vector3 image definition variant does not include a scale factor

2 participants