Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture baker updates #1141

Merged

Conversation

kwokcb
Copy link
Contributor

@kwokcb kwokcb commented Nov 9, 2022

Issue

Changes

  • Add in option to write output to single document: writeDocumentPerMaterial

    • Add texturebaker utility option
    • Add translateshader utility option
  • Update MTLXView to have a minimum bake size set to 1K to match texturebaker and allow for single document option:

Results

  • Example translating shader to N (default)
python translateshader.py resources\Materials\Examples\StandardSurface\standard_surface_look_brass_tiled.mtlx x.mtlx gltf_pbr --writeDocumentPerMaterial True
Processing material: Tiled_Brass
Wrote baked image: Tiled_Brass_gltf_pbr_base_color.png
Wrote baked image: Tiled_Brass_gltf_pbr_roughness.png
Wrote baked image: Tiled_Brass_gltf_pbr_clearcoat.png
Wrote baked image: Tiled_Brass_gltf_pbr_clearcoat_roughness.png

Processing material: Greysphere_Calibration
Wrote baked document: x_SR_brass1.mtlx
Wrote baked document: x_SR_Greysphere_Calibration.mtlx

vs 1 document:

python translateshader.py resources\Materials\Examples\StandardSurface\standard_surface_look_brass_tiled.mtlx single_doc.mtlx gltf_pbr --writeDocumentPerMaterial False
Processing material: Tiled_Brass
Wrote baked image: Tiled_Brass_gltf_pbr_base_color.png
Wrote baked image: Tiled_Brass_gltf_pbr_roughness.png
Wrote baked image: Tiled_Brass_gltf_pbr_clearcoat.png
Wrote baked image: Tiled_Brass_gltf_pbr_clearcoat_roughness.png

Processing material: Greysphere_Calibration
Wrote baked document: single_doc.mtlx

with the following result:

<?xml version="1.0"?>
<materialx version="1.38">
  <nodegraph name="NG_baked" colorspace="srgb_texture">
    <image name="base_color_baked" type="color3">
      <input name="file" type="filename" value="Tiled_Brass_gltf_pbr_base_color.png" />
    </image>
    <output name="base_color_output" type="color3" nodename="base_color_baked" />
    <image name="roughness_baked" type="float">
      <input name="file" type="filename" value="Tiled_Brass_gltf_pbr_roughness.png" />
    </image>
    <output name="roughness_output" type="float" nodename="roughness_baked" />
    <image name="clearcoat_baked" type="float">
      <input name="file" type="filename" value="Tiled_Brass_gltf_pbr_clearcoat.png" />
    </image>
    <output name="clearcoat_output" type="float" nodename="clearcoat_baked" />
    <image name="clearcoat_roughness_baked" type="float">
      <input name="file" type="filename" value="Tiled_Brass_gltf_pbr_clearcoat_roughness.png" />
    </image>
    <output name="clearcoat_roughness_output" type="float" nodename="clearcoat_roughness_baked" />
  </nodegraph>
  <gltf_pbr name="SR_brass1_baked" type="surfaceshader">
    <input name="base_color" type="color3" output="base_color_output" nodegraph="NG_baked" />
    <input name="roughness" type="float" output="roughness_output" nodegraph="NG_baked" />
    <input name="clearcoat" type="float" output="clearcoat_output" nodegraph="NG_baked" />
    <input name="clearcoat_roughness" type="float" output="clearcoat_roughness_output" nodegraph="NG_baked" />
  </gltf_pbr>
  <surfacematerial name="Tiled_Brass_baked" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="SR_brass1_baked" />
  </surfacematerial>
  <gltf_pbr name="SR_Greysphere_Calibration_baked" type="surfaceshader">
    <input name="base_color" type="color3" value="0.478431, 0.47451, 0.47451" colorspace="srgb_texture" />
    <input name="metallic" type="float" value="0" />
    <input name="roughness" type="float" value="0.698039" />
    <input name="clearcoat_roughness" type="float" value="0.0980392" />
  </gltf_pbr>
  <surfacematerial name="Greysphere_Calibration_baked" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="SR_Greysphere_Calibration_baked" />
  </surfacematerial>
</materialx>
  • Note that an invalid arg will now throw an exception error: argument --writeDocumentPerMaterial: Boolean value expected.
    which is performed in a new stringToBoolean() utility added to MaterialX datatypes.py

  • Chess set bake result:
    standard_surface_chess_set_baked.mtlx.txt

kwokcb and others added 17 commits November 4, 2022 10:34
…tory and parent if found to contain a libraries folder.

The latter is the default config for builds and installations currently.
Allow for minimum bake size option in viewer.
Signed-off-by: Jonathan Stone <jstone@lucasfilm.com>
Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

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

This looks really promising, thanks @kwokcb.

I would recommend that we harmonize on a single name for the flag that controls this new behavior, rather than inverting the name between our Python scripts and C++ classes (e.g. "writeSingleDocument" vs "writeSeparateDocuments").

One suggestion for a unified naming convention would be "writeDocumentPerMaterial", which seems clear enough for new readers to follow. We would then provide this same flag name in both Python scripts and C++ classes, and follow your existing convention of defaulting its value to "true" for backwards compatibility.

@kwokcb
Copy link
Contributor Author

kwokcb commented Feb 9, 2023

This looks really promising, thanks @kwokcb.

I would recommend that we harmonize on a single name for the flag that controls this new behavior, rather than inverting the name between our Python scripts and C++ classes (e.g. "writeSingleDocument" vs "writeSeparateDocuments").

One suggestion for a unified naming convention would be "writeDocumentPerMaterial", which seems clear enough for new readers to follow. We would then provide this same flag name in both Python scripts and C++ classes, and follow your existing convention of defaulting its value to "true" for backwards compatibility.

Sorry, I missed this. I will clean up the naming issues. Thanks.

@kwokcb
Copy link
Contributor Author

kwokcb commented Feb 12, 2023

Fixed to use consistent option naming and added in example.

source/MaterialXView/Viewer.cpp Outdated Show resolved Hide resolved
python/MaterialX/datatype.py Outdated Show resolved Hide resolved
Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks @kwokcb! I'd be interested in thoughts from @lfl-eholthouser as well, since she has done development work in this area.

@jstone-lucasfilm
Copy link
Member

@kwokcb With the recent contribution of Metal support, you may need to update this changelist to accommodate the refactoring of GLSL/MSL rendering functionality.

Copy link
Contributor

@lfl-eholthouser lfl-eholthouser left a comment

Choose a reason for hiding this comment

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

I think this look great @bernardkwok. Thanks!

@kwokcb
Copy link
Contributor Author

kwokcb commented Mar 17, 2023

Merge is done. The only change is to add the Python wrapper for Metal version of the TextureBaker interface.

@jstone-lucasfilm jstone-lucasfilm merged commit 37bd2d3 into AcademySoftwareFoundation:main Mar 17, 2023
@kwokcb kwokcb deleted the texture_baker_updates branch March 24, 2023 14:46
kwokcb added a commit to kwokcb/glTF_MaterialX that referenced this pull request Aug 17, 2023
* Pre-update pre for1.38.7 which now includes bake to single doc checked in.
AcademySoftwareFoundation/MaterialX#1141

* Update reults files.

* Update MaterialX.

* Update gitmodule to use ASWF main.

* Update MTLX.

* Update to head for MaterialX.
Michaelredaa pushed a commit to Michaelredaa/MaterialX that referenced this pull request Oct 21, 2023
Add in option to write output to single document: writeDocumentPerMaterial

- Add texturebaker utility option
- Add translateshader utility option
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.

3 participants