Skip to content

Commit ab99084

Browse files
cpichardCopilot
andauthored
Support for matte in RenderPass (#2593)
* Handle render pass matte and add a way to pass the render pass prim path when using kick * Update libs/common/procedural_reader.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update libs/translator/reader/reader.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update plugins/procedural/main.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * ignore test_2549 in the testsuite --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8ede17f commit ab99084

12 files changed

Lines changed: 231 additions & 19 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Bug Fixes
1111

1212
- [usd#2582](https://github.com/Autodesk/arnold-usd/issues/2582) - Arnold-disabled nodes should not be authored to USD
13+
- [usd#2549](https://github.com/Autodesk/arnold-usd/issues/2549) - Support matte in hydra2 render passes
1314

1415
## [7.5.1.0] (Unreleased)
1516

‎libs/common/constant_strings.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ ASTR2(arnold_color_space, "arnold:color_space");
6262
ASTR2(arnold_filename, "arnold:filename");
6363
ASTR2(arnold_image, "arnold:image");
6464
ASTR2(arnold_light, "arnold:light");
65+
ASTR2(arnold_matte, "arnold:matte");
6566
ASTR2(arnold_node_entry, "arnold:node_entry");
6667
ASTR2(arnold_prefix, "arnold:");
6768
ASTR2(arnold_relative_path, "arnold_relative_path");
@@ -451,6 +452,7 @@ ASTR(region_min_x);
451452
ASTR(region_min_y);
452453
ASTR(render_device);
453454
ASTR(render_outputs);
455+
ASTR(render_pass);
454456
ASTR(render_settings);
455457
ASTR(request_imager_update);
456458
ASTR(repeat);

‎libs/common/procedural_reader.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ProceduralReader {
1919
virtual void SetPurpose(const std::string &p) = 0;
2020
virtual void SetMask(int m) = 0;
2121
virtual void SetRenderSettings(const std::string &renderSettings) = 0;
22+
virtual void SetRenderPass(const std::string &renderPass) = 0;
2223
virtual void CreateViewportRegistry(AtProcViewportMode mode, const AtParamValueMap* params) = 0;
2324
virtual void ReadStage(UsdStageRefPtr stage,
2425
const std::string &path) = 0;

‎libs/render_delegate/reader.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,14 @@ void HydraArnoldReader::SetMask(int m) {GetArnoldRenderDelegate()->SetMask(m); }
440440
void HydraArnoldReader::SetPurpose(const std::string &p) { _purpose = TfToken(p.c_str()); }
441441
void HydraArnoldReader::SetId(unsigned int id) { _id = id; }
442442
void HydraArnoldReader::SetRenderSettings(const std::string &renderSettings) {_renderSettings = renderSettings;}
443+
void HydraArnoldReader::SetRenderPass(const std::string &renderPass) {
444+
if (_sceneGlobalsSceneIndex) {
445+
SdfPath renderPassPrimPath(renderPass);
446+
if (!renderPassPrimPath.IsEmpty()) {
447+
_sceneGlobalsSceneIndex->SetActiveRenderPassPrimPath(renderPassPrimPath);
448+
}
449+
}
450+
}
443451

444452
void HydraArnoldReader::Update()
445453
{
@@ -490,6 +498,10 @@ HydraArnoldReader::_AppendOverridesSceneIndices(
490498
HdsiPrimTypePruningSceneIndexTokens->bindingToken,
491499
HdRetainedTypedSampledDataSource<TfToken>::New(
492500
HdMaterialBindingsSchema::GetSchemaToken()));
501+
// Add a SceneGlobals scene index that we can use to set the render pass, render settings
502+
// shutter, frame, etc.
503+
sceneIndex = _sceneGlobalsSceneIndex =
504+
HdsiSceneGlobalsSceneIndex::New(sceneIndex);
493505

494506
// Prune scene materials prior to flattening inherited
495507
// materials bindings and resolving material bindings

‎libs/render_delegate/reader.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "pxr/usdImaging/usdImaging/rootOverridesSceneIndex.h"
2222
#include "pxr/imaging/hd/retainedDataSource.h"
2323
#include "pxr/imaging/hdsi/primTypePruningSceneIndex.h"
24+
#include "pxr/imaging/hdsi/sceneGlobalsSceneIndex.h"
2425
#include "pxr/imaging/hd/materialBindingsSchema.h"
2526

2627
#endif
@@ -53,6 +54,7 @@ class HydraArnoldReader : public ProceduralReader {
5354
void SetPurpose(const std::string &p) override;
5455
void SetId(unsigned int id) override;
5556
void SetRenderSettings(const std::string &renderSettings) override;
57+
void SetRenderPass(const std::string &renderPass) override;
5658
void Update() override;
5759
void CreateViewportRegistry(AtProcViewportMode mode, const AtParamValueMap* params) override {}; // Do we need to create a registry with hydra ???
5860

@@ -77,6 +79,7 @@ class HydraArnoldReader : public ProceduralReader {
7779
HdsiLegacyDisplayStyleOverrideSceneIndexRefPtr _displayStyleSceneIndex;
7880
HdsiPrimTypePruningSceneIndexRefPtr _materialPruningSceneIndex;
7981
HdsiPrimTypePruningSceneIndexRefPtr _lightPruningSceneIndex;
82+
HdsiSceneGlobalsSceneIndexRefPtr _sceneGlobalsSceneIndex;
8083

8184
AtUniverse *_universe = nullptr;
8285
HdRenderPassSharedPtr _syncPass;

‎libs/translator/reader/reader.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class UsdArnoldReader : public ProceduralReader {
6969
void SetPurpose(const std::string &p) override { _purpose = TfToken(p.c_str()); }
7070
void SetId(unsigned int id) override { _id = id; }
7171
void SetRenderSettings(const std::string &renderSettings) override {_renderSettings = renderSettings;}
72-
72+
void SetRenderPass(const std::string &) override {/* Not implemented */}
7373
const UsdStageRefPtr &GetStage() const { return _stage; }
7474
const std::vector<AtNode *> &GetNodes() const override { return _nodes; }
7575
float GetFrame() const { return _time.frame; }

‎plugins/procedural/main.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,15 @@ scene_load
488488
AtString renderSettings;
489489
if (AiParamValueMapGetStr(params, str::render_settings, &renderSettings) && renderSettings.length() > 0)
490490
reader->SetRenderSettings(std::string(renderSettings.c_str()));
491-
491+
// We use the "render_pass" argument to set the path to the render pass to use for rendering
492+
// With kick you can use -sceneload_arg to pass the argument, note that it works only with the scene index enabled (hydra2)
493+
//
494+
// kick -sceneload_arg render_pass /Render/Passes/renderpass2 myscene.usda
495+
//
496+
AtString renderPass;
497+
if (AiParamValueMapGetStr(params, str::render_pass, &renderPass) && renderPass.length() > 0) {
498+
reader->SetRenderPass(std::string(renderPass.c_str()));
499+
}
492500
}
493501
reader->SetFrame(frame);
494502

‎plugins/scene_index/renderPassSIP.cpp‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,18 @@ HdSceneIndexPrim HdArnoldRenderPassSceneIndex::GetPrim(const SdfPath &primPath)
170170
primvarVals.push_back(cameraInvisDs);
171171
}
172172

173-
// TODO to Arnold matte
174-
// Matte -> ri:Matte
175-
//
176-
// If the matte pattern matches this prim, set ri:Matte=1.
173+
// Matte -> arnold:matte
174+
// If the matte pattern matches this prim, set arnold:matte=1.
177175
// Matte only applies to geometry types.
178-
// We do not bother to check if the upstream prim already
179-
// has matte set since that is essentially never the case.
180-
//
181-
// if (_activeRenderPass.DoesOverrideMatte(primPath, prim)) {
182-
// static const HdContainerDataSourceHandle matteDs =
183-
// HdPrimvarSchema::Builder()
184-
// .SetPrimvarValue(HdRetainedTypedSampledDataSource<int>::New(1))
185-
// .SetInterpolation(HdPrimvarSchema::BuildInterpolationDataSource(HdPrimvarSchemaTokens->constant))
186-
// .Build();
187-
// primvarNames.push_back(_tokens->riAttributesRiMatte);
188-
// primvarVals.push_back(matteDs);
189-
// }
176+
if (_activeRenderPass.DoesOverrideMatte(primPath, prim)) {
177+
static const HdContainerDataSourceHandle matteDs =
178+
HdPrimvarSchema::Builder()
179+
.SetPrimvarValue(HdRetainedTypedSampledDataSource<bool>::New(true))
180+
.SetInterpolation(HdPrimvarSchema::BuildInterpolationDataSource(HdPrimvarSchemaTokens->constant))
181+
.Build();
182+
primvarNames.push_back(str::t_arnold_matte);
183+
primvarVals.push_back(matteDs);
184+
}
190185

191186
// Apply any accumulated primvar overrides.
192187
if (!primvarNames.empty()) {

‎testsuite/groups‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ darwin:
4242
#######################
4343

4444
# Tests in this group will never be executed (you can use it to temporarily disable some tests and/or groups)
45-
ignore: unit_render_delegate unit_ndr_plugin unit_translator scene_index_to_fix
45+
ignore: unit_render_delegate unit_ndr_plugin unit_translator scene_index_to_fix hydra2_only
4646

4747
# Tests that require the render delegate library, its dependencies and google test
4848
unit_render_delegate: test_0039 test_0134 test_0136 test_0146 test_0147 test_0152 test_0153 test_0154 test_0155 test_0156
@@ -56,6 +56,9 @@ unit_translator: test_0045
5656
# Test disabled as failing with the scene index (hydra2)
5757
scene_index_to_fix: test_1524
5858

59+
# Test disabled as they work only with hydra2
60+
hydra2_only: test_2549
61+
5962
############################
6063
# USER-DEFINED TEST GROUPS #
6164
############################

‎testsuite/test_2549/README‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Test render pass with matte
2+
3+
It works only in hydra2 mode with the scene index.
4+
5+
Fixes #2549
6+
7+
author: cyril.pichard@autodesk.com
8+
9+
PARAMS: {'scene':'test.usda', 'kick_params': '-sceneload_arg render_pass /Render/Passes/renderpass2'}

0 commit comments

Comments
 (0)