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

Improve stream handling in Viewer and GraphEditor #1517

Closed
wants to merge 23 commits into from

Conversation

kwokcb
Copy link
Contributor

@kwokcb kwokcb commented Sep 6, 2023

Issue

Fixes #1495
Fixed #1494

  • The glTF loader does not load in multiple texcoords so can't use them if they exist. It does for colors.
  • Both the Viewer and GraphEditor force all texcoord node lookups to be 0 so no other set can be used.

Fixes

  • Update Mesh class to create "fallback" streams if not found. This is similar action to what the Web Viewer does using three.js. Will handle if normal, tangent, bitangent or color or texcoord sets do not exist. Missing texcoord sets map to texcoord set 0. Missing color sets map to position.
  • Change Glsl and Msl renderers to create fallbacks if needed.

Tests

glTF Texcoord Test

  • MultiUVTest from glTF Sample Repository. Uses existing texcoord set 1 from glTF file.

image

<?xml version="1.0"?>
<materialx version="1.38">
  <gltf_pbr name="SHD_Material" type="surfaceshader" xpos="13.768116" ypos="-0.672414">
    <input name="base_color" type="color3" nodename="image_basecolor" />
    <input name="metallic" type="float" value="1" />
    <input name="roughness" type="float" value="1" />
    <input name="occlusion" type="float" value="1" />
    <input name="emissive" type="color3" nodename="image_emission" />
  </gltf_pbr>
  <surfacematerial name="MAT_Material" type="material" xpos="17.391304" ypos="0.000000">
    <input name="surfaceshader" type="surfaceshader" nodename="SHD_Material" />
  </surfacematerial>
  <gltf_image name="image_basecolor" type="color3" xpos="10.144928" ypos="-0.896552">
    <input name="file" type="filename" value="uv0.png" colorspace="srgb_texture" />
  </gltf_image>
  <gltf_image name="image_emission" type="color3" xpos="10.144928" ypos="0.422414">
    <input name="file" type="filename" value="uv1.png" colorspace="srgb_texture" />
    <input name="texcoord" type="vector2" nodename="texcoord" />
  </gltf_image>
  <texcoord name="texcoord" type="vector2" xpos="6.463768" ypos="-0.517241">
    <input name="index" type="integer" value="1" />
  </texcoord>
</materialx>

Missing Stream Test

image

<?xml version="1.0"?>
<materialx version="1.38">
  <texcoord name="texcoord" type="vector2" xpos="8.666667" ypos="0.870690">
    <input name="index" type="integer" value="10" />
  </texcoord>
  <geomcolor name="geomcolor_color3" type="color3" xpos="8.434783" ypos="-0.810345">
    <input name="index" type="integer" value="100" />
  </geomcolor>
  <checkerboard name="checkerboard_color3" type="color3" xpos="10.637681" ypos="1.146552">
    <input name="texcoord" type="vector2" nodename="texcoord" />
    <input name="uvtiling" type="vector2" value="20, 20" />
    <input name="color1" type="color3" value="0.374083, 0.368595, 0.368595" />
  </checkerboard>
  <surface_unlit name="surface_unlit" type="surfaceshader" xpos="13.797101" ypos="-2.258621">
    <input name="emission_color" type="color3" nodename="geomcolor_color3" />
  </surface_unlit>
  <surface_unlit name="surface_unlit2" type="surfaceshader" xpos="14.000000" ypos="0.931035">
    <input name="emission_color" type="color3" nodename="checkerboard_color3" />
  </surface_unlit>
  <tangent name="tangent_vector3" type="vector3" xpos="8.884058" ypos="3.206897">
    <input name="index" type="integer" value="34" />
  </tangent>
  <bitangent name="bitangent_vector3" type="vector3" xpos="8.565217" ypos="5.801724">
    <input name="index" type="integer" value="200" />
  </bitangent>
  <convert name="convert_vector3_surfaceshader" type="surfaceshader" xpos="12.326087" ypos="3.758621">
    <input name="in" type="vector3" nodename="tangent_vector3" />
  </convert>
  <convert name="convert_vector3_surfaceshader2" type="surfaceshader" xpos="12.028986" ypos="6.232759">
    <input name="in" type="vector3" nodename="bitangent_vector3" />
  </convert>
  <surfacematerial name="surfacematerial" type="material" xpos="16.463768" ypos="-1.620690">
    <input name="surfaceshader" type="surfaceshader" nodename="surface_unlit" />
  </surfacematerial>
  <surfacematerial name="surfacematerial2" type="material" xpos="16.434782" ypos="0.439655">
    <input name="surfaceshader" type="surfaceshader" nodename="surface_unlit2" />
  </surfacematerial>
  <surfacematerial name="surfacematerial3" type="material" xpos="16.695652" ypos="3.629310">
    <input name="surfaceshader" type="surfaceshader" nodename="convert_vector3_surfaceshader" />
  </surfacematerial>
  <surfacematerial name="surfacematerial4" type="material" xpos="16.666666" ypos="5.732759">
    <input name="surfaceshader" type="surfaceshader" nodename="convert_vector3_surfaceshader2" />
  </surfacematerial>
</materialx>

Note

  • The render test suite already creates fallbacks for any missing streams before-hand (vs on demand here).

kwokcb and others added 4 commits September 6, 2023 10:05
@jstone-lucasfilm
Copy link
Member

This looks really promising, thanks @kwokcb, and I should have a chance to take a closer look soon.

kwokcb and others added 3 commits September 14, 2023 10:10
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 nearly ready to merge, thanks @kwokcb, and I had just a few recommendations for adjustments.

source/MaterialXRender/Mesh.cpp Outdated Show resolved Hide resolved
source/MaterialXTest/MaterialXRender/RenderUtil.cpp Outdated Show resolved Hide resolved
kwokcb and others added 6 commits January 30, 2024 11:28
* Web viewer formatting improvements and fixes (AcademySoftwareFoundation#1635)

- Add colouring to items and folders which can be set vis CSS. This makes it easier to tell what areas are under what folders.
- Fix string disable setting (was using old API).
- Fix parenting of enum widgets to be under current folder instead of top level.

* Add HwImplementation class

This changelist adds an intermediate HwImplementation class, allowing the sharing of common features between node implementations in hardware shading languages.

* Merge geometry node implementations

This changelist merges the implementations of geometry nodes across hardware shading languages, allowing a greater degree of code sharing.

* Merge application node implementations

This changelist merges the implementations of application and NPR nodes across hardware shading languages, allowing a greater degree of code sharing.

* Add vector2 variant of normalmap (AcademySoftwareFoundation#1355)

The materialx specification defines the scale attribute of the normalmap to be either a float or a vector2 but the vector2 variant was missing from the implementation. This PR adds it.

* Renderable logic improvements to web viewer (AcademySoftwareFoundation#1644)

- Adds in proper parsing of renderable elements vs always just picking the first surface shader found.
  - The test suite files which have (multiple) nodegraph outputs and top level outputs will now load properly.
- Adds in UI to mark folders as renderable (using a shaderball icon) 
- Adds in "soloing" capability to allow picking a renderable and have it show up on all geometry. When nothing is solo'ed the default material assignment is used.
- Includes fixes for:
  - Dag path assignment matching .
  - Missing exposure of NodeGraph::getDownStreamPorts() in JS.
  - Addressing the big performance hit when binding materials to geometry in ThreeJS. The code by default is some quite slow code for reflection / debugging purposes which is now turned off. Chess set load is seconds vs minutes. This affects the 'solo'ing workflow significantly as each switch is a geometry re-bind. If the material is not already cached then slow code will be hit which can cause seconds to pass when selecting a new material -- which appears like a "hang" from a user perspective.

* Fix irradiance generation in MaterialXView (AcademySoftwareFoundation#1647)

This changelist fixes a regression to environment irradiance generation in MaterialXView, caused by a change to image caching logic for GLSL rendering in MaterialX 1.38.8.  This fix restores the ability to render environment maps that are missing their pre-generated irradiance data, with irradiance being generated on the fly via spherical harmonics.

* Add UI limits for useSpecularWorkflow and normal in UsdPreviewSurface (AcademySoftwareFoundation#1646)

UsdPreviewSurface allows useSpecularWorkflow to be 0 or 1. Normals should have values between -1 to 1, inclusive. This PR puts these limits into place.

* Unify noise unit tests

This changelist merges two sets of noise unit tests into a single document, and aligns their implementations for clarity.

* Static analysis optimizations

This changelist addresses a handful of static analysis optimizations flagged by PVS-Studio and cppcheck, including the following:

- Pass immutable std::string, FilePath, and FileSearchPath arguments by const reference.
- Mark immutable ShaderGenerator references as const.
- Prefer std::string::empty over comparison against an empty string.
- Remove unused private methods Graph::findLinkId, Graph::findInput, and Graph::selectMaterial.
- Remove variable assignments with no impact on code behavior.

* Improvements to noise implementations (AcademySoftwareFoundation#1653)

- Leverage node graphs to share the conversion aspects of noise implementations across languages.
- Simplify noise unit tests to cover only unique implementations.

* Fix shader generation typos

This changelist fixes a handful of minor typos in shader generation, introduced in AcademySoftwareFoundation#1355 and AcademySoftwareFoundation#1553.

* Add frame capture to web viewer (AcademySoftwareFoundation#1636)

Add frame capture code to trigger on 'f' key. This is the same key as used for the desktop viewer.

* Document format updates

This changelist applies the mxformat.py script to the libraries and resources folders in the repository, updating formatting for a handful of documents.

* Add versioning rules to Developer Guide (AcademySoftwareFoundation#1664)

This changelist adds two new sections to the Developer Guide, describing the categories of changes to the MaterialX API and data libraries that are allowed in version upgrades.

* Improve robustness of TypeDesc pointer comparisons (AcademySoftwareFoundation#1665)

- The globals presets defined for TypeDesc are pointers which may not be shared between shared modules. This occurs for instance in Python where the pointers are declared locally for each module.
- Any pointer comparison between the same TypeDesc preset can thus result in a failure status.

* Improvements to smoothstep implementations

- Leverage node graphs to share the conversion aspects of smoothstep implementations across languages.
- Simplify smoothstep unit tests to cover only unique implementations.

* Update changelog for recent work

* Update comments in stdlib_ng.mtlx

This changelist updates the comments in stdlib_ng, aligning them with the conventions for nodegraph definitions in the data libraries.

* Fix orphaned links when deleting node in graph editor (AcademySoftwareFoundation#1667)

This PR introduces fixes related to the removal of orphaned links when deleting a node in the Graph Editor:
- remove the attribute `INTERFACE_NAME_ATTRIBUTE` of input pins that were connected to the deleted node
(Fixes AcademySoftwareFoundation#1577) 
- iterate over all of the output pins instead of only handling the first one.
(Fixes AcademySoftwareFoundation#1666)

* Add facingratio node to nprlib (AcademySoftwareFoundation#1671)

This changelist adds a `facingratio` node to the NPR data library, providing an additional intermediate node for building NPR graphs.

* Add geometry drag & drop to web viewer (AcademySoftwareFoundation#1663)

- Add support to recognize dropping of individual geometry (glb) files.
- Minor cleanup to stop if no MTLX or GLB files loaded.

* Apply JavaScript formatting

This changelist applies automated formatting to the MaterialX JavaScript codebase, aligning it with the 4-space indentation and Allman braces used in MaterialX C++.

* Add missing classification of VolumeShader nodes (AcademySoftwareFoundation#1675)

ShaderNodes.cpp had missing classification information for Volume Shaders. This PR is a simple addition of that classification.

* Add invert node to specification (AcademySoftwareFoundation#1676)

The node exists in the standard library code, but is missing from the specification.

* Improvements to facingratio

- Fix syntax of input default values.
- Use the invert node in facingratio for compactness.
- Clarify the edge brighten example material.

* Always build GLFW as a static library (AcademySoftwareFoundation#1680)

Currently the embedded glfw build for MaterialXGraphEditor inherits the value of BUILD_SHARED_LIBS from MATERIALX_BUILD_SHARED_LIBS, but we're not installing libglfw, per AcademySoftwareFoundation#1245 the intention was to statically link.

---------

Co-authored-by: Jonathan Stone <jstone@lucasfilm.com>
Co-authored-by: mnikelsky <michael.nikelsky@autodesk.com>
Co-authored-by: Eric Haines <erich@acm.org>
Co-authored-by: Leo Belda <leo.belda@wanadoo.fr>
Co-authored-by: Dhruv Govil <dgovil2@apple.com>
Co-authored-by: ld-kerley <154285602+ld-kerley@users.noreply.github.com>
Signed-off-by: Jonathan Stone <jstone@lucasfilm.com>
@jstone-lucasfilm jstone-lucasfilm changed the title Fix multi stream and missing stream support for Viewer and GraphEditor. Improve stream handling in Viewer and GraphEditor Feb 2, 2024
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 is looking very promising, thanks @kwokcb, and I had two notes about design choices in the review comments.

return stream;
}
}
if (allowFallback)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this design choice, where the formerly const method Mesh::getStream will silently create new streams when data is missing.

As an alternative design, what if we were to leave Mesh::getStream as a const method, and move the stream construction logic into a new Mesh::createStream method. In the two locations where we need fallbacks for missing streams, we would simply check for a null result from Mesh::getStream and then call Mesh::createStream explicitly.


/// Add a mesh stream
void addStream(MeshStreamPtr stream)
{
for (MeshStreamPtr s : _streams)
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a surprising behavior for Mesh::addStream, where it will silently skip the requested addition when a stream by the same name already exists. In this situation, the caller has no way to know that the mesh stream that they have constructed is not actually referenced or needed by the mesh.

Would it instead be better to thrown an exception in this situation, so that the logic bug leading to this situation can be addressed?

@kwokcb kwokcb changed the base branch from main to dev_1.39 March 16, 2024 13:01
@kwokcb
Copy link
Contributor Author

kwokcb commented Mar 19, 2024

Don't really have time to continue pursuing this. Wil close for now.

@kwokcb kwokcb closed this Mar 19, 2024
@kwokcb kwokcb deleted the multi_stream branch June 10, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants