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

Arnold USD compatibility improvements #5759

Merged
merged 8 commits into from
Apr 3, 2024

Conversation

johnhaddon
Copy link
Member

This makes various improvements to our import/export of Arnold shader networks via USD :

  • Align our naming for outputs with the naming used by Maya-USD and Arnold-USD's Sdr Registry. This means we use outputs:out rather than outputs:DEFAULT_OUTPUT in USD. This also applies to the ShaderNetworks we pass around internally, where we now use "out" rather than "" to refer to the default output.
  • Cope with non-conforming outputs from USD files written by HtoA. These use a completely different convention for the naming of the default output - using out:rgb, out:float etc based on type. I've confirmed that this was not intended to diverge from the Maya/SDR convention, and that it should be fixed in future. In the meantime, we can now translate such outputs to Arnold.
  • Fix rendering of Arnold osl shaders with inline code. We don't author these in Gaffer, but we can now ingest and render them from HtoA and elsewhere.

@johnhaddon johnhaddon self-assigned this Mar 28, 2024
@danieldresser-ie
Copy link
Contributor

LGTM, once you address the failures ( which it sounds like you've got plan for ).

@johnhaddon
Copy link
Member Author

Pushed a fixup for the OSLShader test failures.

@danieldresser-ie
Copy link
Contributor

LGTM

OSL shaders have named outputs, and any ShaderNetworks generated in Gaffer will always provide the output name in the connection.
When Arnold first introduced OSL support, an Arnold C++ shader was only able to have a single output. So when OSL shaders had multiple outputs, we had to translate them to multiple Arnold shaders using the `constant STRING output` parameter to tell Arnold which output to use for each one. Arnold shaders can now have multiple outputs (as of at least 7.0, I didn't check further back), so we can use a single Arnold node per OSL shader.
We were previously omitting it for subclasses which didn't use the `out` plug as a container for named shader outputs, and instead used it to represent a single output. Everything is simpler if outputs always have a name, and this aligns much better with USD too where a name is required. Cortex has a nasty workaround with a `DEFAULT_OUTPUT` to round-trip empty names though USD, and this will no longer be needed.

What we really want to do as well is enforce that the `out` plug is always just a container, and all outputs must be parented under it. This will also allow us to support multiple Arnold outputs, as requested in GafferHQ#5542. But maintaining backwards compatibility for that change is a bigger problem. This commit means that the `IECoreScene::ShaderNetworks` we generate and export have the format we want, even though we haven't yet adopted the plug format we want yet.

Note : the choice of `out` for the default output matches Autodesk's convention for the default (unnamed) output from an Arnold shader, so this means we now export USD using the same conventions as Maya.
We were always connecting from `shader["out"]`, but we should be connecting from `shader["out"]["<name>"]` for well-behaved nodes that represent outputs as we want them.
Otherwise the other parameters we want to set don't exist yet. This didn't occur for any shaders authored in Gaffer, because there we would use the OSLCode node to author a generic shader that comes in via the `isOSLShader` code path. What is being fixed here is Arnold `osl` shaders coming in via USD after being authored somewhere like Houdini.
This matches the networks we now get from `GafferArnold::ArnoldShader` and the convention expected by Arnold-USD. Longer term I think `IECoreScene::ShaderNetwork` will _require_ the output nameas well. Also added a test so that we retain some coverage for legacy outputs serialised into `.scc` and the like.
@johnhaddon johnhaddon force-pushed the arnoldUSDConnections branch from e06daad to 8c6fa4b Compare April 3, 2024 08:48
@johnhaddon johnhaddon merged commit dc38ddd into GafferHQ:main Apr 3, 2024
5 checks passed
johnhaddon added a commit to johnhaddon/gaffer that referenced this pull request Apr 24, 2024
This fixes the rendering of shader balls in the Viewer, which was broken by
GafferHQ#5759. This really is just a workaround though, and the ideal fix is now documented in ShaderView.cpp, along with the reasons we can't make it immediately.

I moved the check for "" and "out" after the search for the valid outputs because of the small chance of there actually being a real output called "out" (and it not being the first one). I think it's unlikely that we need the check for "" as well any more, but I've kept it out of an abundance of caution.

Also changed InternedString equality comparisons to use preconstructed strings - comparing to `char *` actually constructs InternedStrings to compare against on the fly, which is unnecessarily slow.
@johnhaddon johnhaddon deleted the arnoldUSDConnections branch April 25, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants