-
Notifications
You must be signed in to change notification settings - Fork 202
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
Optimize VP2 rendering of USD objects with geometric cut-outs #3952
Optimize VP2 rendering of USD objects with geometric cut-outs #3952
Conversation
a29f6ab
to
2729579
Compare
Hi @jufrantz, looks very interesting, but I definitely need to ask... Have you tried making _isTransparent return false for the cut-out cases? That would remove any need for transparency mitigation at the render item level since these items would correctly declare their shading to be opaque. |
Tried it locally. I only kept your new //! Return true if the surface shader needs to be rendered in a transparency pass.
bool _IsTransparent(const HdMaterialNetwork& network)
{
+ if (_IsMaskedTransparency(network)) {
+ return false;
+ }
+
using OpaqueTestPair = std::pair<TfToken, float>; And, for your scene, performance went from bad enough to cause a TDR to 30fps with correct visual results. |
Hello @JGamache-autodesk, That's definitely a good question especially since you are right, I just tested this and it works correctly on my scene, rendering is correct including shadows and SSAO (wow!). To be myself transparent, this was my first intention and I tried it. I didnt test on this kind of scenes but on a simpler scene with just a non-instanced mesh and I detected issues with SSAO that was occluding the discarded surface. We are encountering these performance issues on scenes with instancing and I didn't want to introduce a regression with SSAO, I ended up with this solution and its complications. I re-tested with this scene and still have the issue on non-instanced geometry, while it works on the same geometry and shader when point-instanced. Something is happening behind the scene but I have no clue. |
Another test I did during #3947. It isn’t related to vp2RenderDelegate / MPxSubsceneOverride but might still be interesting, it led me to the idea that beauty fragment discards and marking the shader as opaque would not be enough for post effects. On this scene with maya native meshs and shading, if usdPreviewSurface shading node sets @@ -479,6 +479,7 @@ MStatus PxrMayaUsdPreviewSurface::compute(const MPlug& plug, MDataBlock& dataBlo
}
float transparencyOn = false;
+ if (opacityThreshold <= 0.0) {
if (opacityConnected) {
transparencyOn = true;
} else {
@@ -489,6 +490,7 @@ MStatus PxrMayaUsdPreviewSurface::compute(const MPlug& plug, MDataBlock& dataBlo
transparencyOn = true;
}
}
+ } I traced that VP2 correctly classifies shaded items as opaque and I get this result with SAAO: Versus the PR unchanged (all items marked transparent): Hope it helps, |
Thanks for all the tests, they helped me do a quick investigation in Maya rendering code. Also interesting in your last scene is instancing the masked panels and seeing better SSAO results with GPU instancing enabled. Can you update the PR with your latest code that properly declares masked as opaque in material.cpp and usdPreviewSurface.cpp? We will accept the SSAO issue this reveals and log a bug to eventually have this fixed in Maya. |
…dered as opaque. As discussed in PR [Autodesk#3952](Autodesk#3952).
I have pushed the requested changes. All materials with masked transparency are now simply marked as opaque in this PR, and I’ve also updated usdPreviewSurface shading node in #3947. Could you please provide us with the Maya issue ID once it’s logged so that we can follow up with the support team? Thank you for your feedback. |
The SSAO issue with cut-out shaders is logged as MAYA-135575. |
… transparency. HdVP2Material now detects when its shader's transparency is used for a geometric cut-out, such as a UsdPreviewSurface with opacityThreshold (e.g., for `cards` drawMode). In this case, transparency does not require alpha blending or depth sorting. We can setup the transparent MRenderItem to still leverage GPU instanced draw thanks to `MPxSubSceneOverride::setAllowTransparentInstances`. cf Maya API Reference: https://help.autodesk.com/cloudhelp/2025/ENU/MAYA-API-REF/cpp_ref/class_m_h_w_render_1_1_m_px_sub_scene_override.html#ab5f84f5ba90bb3caabbb69ab3d52cb37
…eview. Removes the special case for instanced render items, all objects with materials that have masked transparency are now consistently marked as opaque.
e68f973
to
d0d2e9c
Compare
Hello, |
There was a single test failure on Windows 2022 with |
@jufrantz Just as an FYI, we are using clang format version 10 (which is quite old). It formats differently than newer versions which is why we haven't updated yet. |
Hello @seando-adsk, |
Building upon #3947 , this PR leverages transparency cut-outs, achieved through
UsdPreviewSurface.opacityThreshold>0
or glTFalpha_mode=MASK
, to optimize instancing in vp2RenderDelegate.In HdStorm, draw items using these materials are detected as "masked". They are rendered efficiently without depth sorting or OIT, and they still contribute to shadows, unlike translucent items.
VP2 sdk does not expose such feature. An MRenderItem can only be declared as "transparent" which implies alpha blending. These transparent items also receive special treatment in shadow and post-effects passes (e.g. SSAO). To achieve correct blended transparency, VP2 will automatically de-instantiate items with transparent shader. In cases of massive instancing, this severely impacts draw performance. For example, depth sorting thousands of individual objects is quite expensive, and consolidating all instanced geometries will produce very fat geometry data.
This PR specifically optimizes the case of instanced geometry with
masked
materials thanks to MPxSubsceneOverride::setAllowTransparentInstances. This flag allows us to preserve instancing even for transparent items. These items are consequently correctly treated in shadow and post-effects passes, beauty pass remains correct without sorting (without the huge cost of de-instantiation) since the material does not produce semi-transparent fragments.These geometric cut-outs are typically used for vegetation foliage, which is important to instantiate massively in complex environments. Additionally, USD 23.02+ uses
UsdPreviewSurface.opacityThreshold
forcards drawMode
, it is aimed at lightweight and fast rendering; instanced cards will also be optimized. These two cases are common in our productions, and we need them to be efficient within maya.Changes
Added "masked" transparency feature detection, inspired by HdStorm ( materialNetwork.cpp, materialXFilter.cpp )
Added
HdVP2Material._drawItemFlags
: These flags indicate if the material is transparent and masked. They are computed during material sync, when parameters changed, and are retained for later access during rprim sync.Ensured affected renderables are re-synced, and MRenderItems are updated, whenever a material changes its
drawItemFlags
.Finally, set up MRenderItems during this rprim sync so GPU instancing is not broken, when possible, thanks to MPxSubsceneOverride::setAllowTransparentInstances.
Results
Tests were conducted in maya 2025.2 with this scene, featuring 100000 instances of a sphere that has textured opacity and a masked UsdPreviewSurface. The camera is framing the whole instancer. I profiled using this script:
Before optimization:
TraceRenderPipeline reports:
Profiler reports:
After optimization:
TraceRenderPipeline reports a single render item, instanced:
Profiler reports: