-
Notifications
You must be signed in to change notification settings - Fork 201
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
Fix VP2 rendering of UsdPreviewSurface with opacityThreshold #3947
base: dev
Are you sure you want to change the base?
Fix VP2 rendering of UsdPreviewSurface with opacityThreshold #3947
Conversation
…urface fragment graphs.
…s greater than or equal to the opacityThreshold.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done! Thank you!
@jufrantz Unfortunately the preflight failed two different build configurations:
I believe here you just need to conditionally run your new test:
I'm not sure if your changes have affected this test. Maybe @JGamache-autodesk can help with this one? Sean |
The change also affects the card draw mode (which uses UsdPreviewSurface since 23.02 with an opacityThreshold of 0.1). This means @jufrantz will have to provide a set of updated baseline images for the testVP2RenderDelegateDrawModes.py unit test. |
You can also take these: |
… UsdPreviewSurface VP2 shader changes.
Thank you @seando-adsk @JGamache-autodesk. |
@jufrantz I re-ran the preflight and it still failed on "Maya 2022, Python 2, interactive, Windows"
|
Sorry for this @seando-adsk, |
Hello, |
UsdPreviewSurface fragment graph for v1 does not support opacityThreshold input.
…dered as opaque. As discussed in PR [Autodesk#3952](Autodesk#3952).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Only one minor comment.
PxrMayaUsdPreviewSurfaceTokens->OpacityThresholdAttrName.GetText()); | ||
const MDataHandle opacityThresholdData | ||
= dataBlock.inputValue(opacityThresholdAttr, &status); | ||
CHECK_MSTATUS(status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you replicate the opacityConnected
code you see for opacity
, but on opacityThreshold
? A connected opacityThreshold
should also activate masked mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @JGamache-autodesk for your feedback,
Interesting point, but I think I disagree with this solution.
As you know, marking the whole material as transparent
informs the rasterizer to use alpha blending for proper rendering (e.g. GL_BLEND and object sorting). Conversely, opaque
material allows the rasterizer to perform simple depth testing and overwrite fragments. Moreover for masked
materials, some fragments will be discarded without writing to the depth or color buffers, which still works with simple depth testing.
OpacityThreshold
functions similarly to a combination of glTF alphaMode
and alphaCutoff
. For a material with authored opacity:
- A zero
opacityThreshold
is equivalent toglTF.alphaMode = BLEND
- Positive values would translate to
glTF.alphaMode=MASK
andglTF.alphaCutoff=opacityThreshold
.
Texturing opacityThreshold
is akin to texturing both alphaCutoff
AND alphaMode
: since you can get zero-valued threshold texels, you would expect a partially masked
and partially translucent
material. In this scenario, to ensure proper rendering of the semi-transparent regions, the only viable solution to me is to render these objects in the transparent pass (that would also still work with alpha cut/discarded regions).
For reference, HdStorm’s implementation of masked
detection for GLSLFX UsdPreviewSurface only tests for a constant positive opacityThreshold
value, while for translucent
it tests opacity input connections and decides that a varying opacity differs from plain one, like the current VP2 shading node implementation.
// Next check for authored terminal.opacityThreshold value > 0
for (auto const& paramIt : terminal.parameters) {
if (paramIt.first != _tokens->opacityThreshold) continue;
VtValue const& vtOpacityThreshold = paramIt.second;
if (vtOpacityThreshold.Get<float>() > 0.0f) {
return HdStMaterialTagTokens->masked;
}
}
Moreover, I may have over-interpreted it but - as I understand it - the USDPreviewSurface Specification discourages a material with a texture used for translucency and mask.
Thus,` the opacityThreshold serves as a switch for how the opacity input is interpreted; this 'translucent or masked' behavior is common in engines and renderers, and makes the UsdPreviewSurface easier to interchange. It does imply, however, that it is not possible to faithfully recreate a glassy/translucent material that also provides an opacity-based mask… so no single-polygon glass leaves.
If we want to improve this, an alternative could be to disallow connections to the opacityThreshold parameter during VP2 shader translation. This restriction can be implemented with MPxShadingNodeOverride.
void PxrMayaUsdPreviewSurfaceShadingNodeOverride::getCustomMappings( |
Please let me know if this approach meets your requirements,
Best,
Julien
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good explanation. I agree with you. This would mean the implementation of _GetUsdPreviewSurfaceMaterialTag() I added to materialXFilter.cpp is buggy since it considers textured opacityThreshold
as masked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably no need to forbid connections since the result is not fatal and will render correctly, albeit slowly, in a transparency pass.
This PR fixes VP2 support for the UsdPreviewSurface
opacityThreshold
input, aligning it with Pixar's UsdPreviewSurface Specification.Included Changes:
UsdPreviewSurfaceLightAPI*.xml
fragment graphs to exposeopacityThreshold
. TheShadeFragment
node input was not connected to theMShaderInstance
parameter, which had no effect.opacityThreshold
is positive.PxrMayaUsdPreviewSurface::compute
for software rendering.Results:
Snaphots of the scene included in the unit tests. TestOpacityThreshold.usda features 5 planes with materials bound that have textured opacity, with opacityThreshold gradually increasing from 0.0 to 1.0 from left to right.
usdview/HdStorm
vp2RenderDelegate before PR
vp2RenderDelegate after PR