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

LOOKDEVX-1847 - Fix rendering of gltf texture nodes #3295

Merged

Conversation

JGamache-autodesk
Copy link
Collaborator

We previously were adding default geompropvalue nodes on dangling texcoord inputs in the source MaterialX document.

We now let them be, and process them post shadergen as re-implementation of the texcoord node into geompropvalue code. This allows dealing with the texcoord nodes embedded in the glTf texture nodes added to MaterialX 1.38.6.

We previously were adding default geompropvalue nodes on dangling texcoord inputs in the source MaterialX document.

We now let them be, and process them post shadergen as re-implementation of the
texcoord node into geompropvalue code. This allows dealing with the
texcoord nodes embedded in the glTf texture nodes added to MaterialX
1.38.6.
//
// Copyright Contributors to the MaterialX Project
// SPDX-License-Identifier: Apache-2.0
//
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied from MaterialX GeomPropValueNodeGlsl.cpp but adapted to read the index input of a texcoord node and convert it to USD "st" primvar naming scheme.

// Copyright Contributors to the MaterialX Project
// SPDX-License-Identifier: Apache-2.0
//

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied from MaterialX GeomPropValueNodeGlsl.h.

// system. To make these graphs compatible, we will redirect any unconnected input that uses such an
// auto-connection scheme to instead read a texcoord geomprop called "st" which is the canonical
// name for UV at index zero.
void _AddMissingTexcoordReaders(mx::DocumentPtr& mtlxDoc)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No longer necessary since we handle that in the shadergen.

@JGamache-autodesk
Copy link
Collaborator Author

This allows getting proper VP2 shadergen with MaterialX glTf texture nodes, as described in AcademySoftwareFoundation/MaterialX#1486

Copy link
Collaborator

@vlasovi vlasovi left a comment

Choose a reason for hiding this comment

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

Nice

vlasovi
vlasovi previously approved these changes Aug 24, 2023
Also handle USDMTLX_PRIMARY_UV_NAME env var.
// functor instead of a hardcoded Token. This way we could add the equivalent of this code as a
// functor in the MaterialX parser, and the _ExtractPrimvarsFromNode function found in
// pxr\usdImaging\usdImaging\materialParamUtils.cpp would then be able to handle indexed values.
#if 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

The old code used to try to use the index. With this #if 0, index is not considered at all. Doesn't this create a regression?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The previous code would try and fail because Hydra would not have provided texcoord data. Here I have a grid with 2 UV sets.
image
From left to right:

  • Grid with texture reading geompropvalue "st"
  • Grid with texture reading texcoord at index 0
  • Grid with texture reading geompropvalue "st1"
  • Grid with texture reading texcoord at index 1

And this is before my changes. I started a discussion in AOUSD forums to see if I can fix that in USD, which would enable me to remove the #if 0.

With the changes in this PR, the last grid will look like the second one for texcoord at index 0, matching the results obtained with usdview.

I will add a unit test for the texcoord case so we can follow future developments on the texcoord 1 front.
Texcoord_1.zip

vlasovi
vlasovi previously approved these changes Aug 28, 2023
Copy link
Collaborator

@vlasovi vlasovi left a comment

Choose a reason for hiding this comment

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

Thanks @JGamache-autodesk for the explanation. This will do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This one is clearer than the MTLXUVStream test. We can clearly see that using UV1 will render using the "st" stream instead of "st1" as the bottom left one.

def Shader "texcoord1"
{
uniform token info:id = "ND_texcoord_vector2"
int inputs:index = 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will be ignored with current code. Fixes are being discussed.

float outputs:out
}


def Shader "multiply10"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding the UV multiplier node makes the noise more visible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Original image had a noise that was varying so slowly that we could not actually see that it was not varying at all since UV1 was not read correctly. We can now see the UV0 noise and will be able to tell when UV1 gets read correctly.

@JGamache-autodesk JGamache-autodesk added the ready-for-merge Development process is finished, PR is ready for merge label Aug 28, 2023
@JGamache-autodesk
Copy link
Collaborator Author

@seando-adsk Ready for merge.

@seando-adsk seando-adsk merged commit 2a3adf3 into dev Aug 29, 2023
12 checks passed
@seando-adsk seando-adsk deleted the gamaj/LOOKDEVX-1847/fix_rendering_of_gltf_texture_nodes branch August 29, 2023 14:06
JGamache-autodesk added a commit that referenced this pull request Sep 1, 2023
Previous work in PR #3295 broke normal mapping by pessimistically using
the arbitrary tangent generator. Bring back the texcoord tangents if we
detect that implicit texcoords are going to be used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge vp2renderdelegate Related to VP2RenderDelegate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants