# Object mask with primId AOV

**URL:** <https://forum.aousd.org/t/object-mask-with-primid-aov/2085>\
**Category:** Hydra\
**Tags:** beginner\
**Created:** [December 16, 2024, 7:46pm UTC](https://forum.aousd.org/t/object-mask-with-primid-aov/2085 "2024-12-16T19:46:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Volodymyr](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@Volodymyr](https://forum.aousd.org/u/Volodymyr)\
**Post date:** [December 16, 2024, 7:46pm UTC](https://forum.aousd.org/t/object-mask-with-primid-aov/2085/1 "2024-12-16T19:46:50Z")

</div>

Hello,

I’m trying to obtain object mask for data labeling. My initial idea was to render scene a couple of times with entire scene once and with only enabled needed object. But using primId would also solve the problem if it worked. Instead i’m receiving rgba (0, 0, 0, 255)

so I have  
`drawTarget.AddAttachment("color", GL_RGBA, GL_FLOAT, GL_RGBA);`  
and  
`renderer_.SetRendererAov(TfToken("primId"));`  
but the whole buffer rendered with one Id.

Rendering color works fine.  
Renderer HdStorm,

```auto
    params_.frame = 1.0;
    params_.complexity = 1.f;

    params_.enableLighting = true;
    params_.enableSceneLights = true;
    params_.enableSceneMaterials = true;
    params_.complexity = 1.f;
    params_.cullStyle = UsdImagingGLCullStyle::CULL_STYLE_BACK_UNLESS_DOUBLE_SIDED;
    params_.drawMode = UsdImagingGLDrawMode::DRAW_SHADED_SMOOTH;

    params_.enableIdRender = false;
    params_.enableSampleAlphaToCoverage = true;
    params_.forceRefresh = false;
    params_.gammaCorrectColors = true;
    params_.highlight = true;

```

And at the end if it were working, how do I map back from primId to prim path.

Thanks.

---

<div class="post-metadata">

**Author:** ![fhecht](https://avatars.discourse-cdn.com/v4/letter/f/d07c76/32.png) [@fhecht](https://forum.aousd.org/u/fhecht)\
**Post date:** [December 18, 2024, 9:29pm UTC](https://forum.aousd.org/t/object-mask-with-primid-aov/2085/2 "2024-12-18T21:29:18Z")

</div>

Hi Volodymyr,

I’m not certain about the issue with not getting the right data into your frame buffer, but I do know how the mapping from `primId` works.

Have a look at `UsdImagingGLEngine::DecodeIntersection()`

> <https://github.com/PixarAnimationStudios/OpenUSD/blob/9b0c13b2efa6233c8a4a4af411833628c5435bde/pxr/usdImaging/usdImagingGL/engine.cpp#L863>

This function does a decoding step from the color values, which is something I have not used yet. But once the `primId` is there it calls this

`SdfPath primPath = _renderIndex->GetRprimPathFromPrimId(primId);`

Which returns an Rprim Path, which is an internal Hydra path and that can be mapped to the path on the original UsdStage.

Also note that in order to support instanced prims in your selection/masking setup you also need to get the `instanceId` buffer as well. If you look at the posted code, you can see how that is decoded, which makes it a bit more complicated.

I hope this pointer is helpful.

- Florian

---

<div class="post-metadata">

**Author:** ![dlanier](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/dlanier/32/166_2.png) [@dlanier](https://forum.aousd.org/u/dlanier)\
**Post date:** [December 19, 2024, 8:15am UTC](https://forum.aousd.org/t/object-mask-with-primid-aov/2085/3 "2024-12-19T08:15:07Z")

</div>

Hi,

I think another good example is to look at :

> <https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/imaging/hdx/testenv/testHdxIdRender.cpp>

Regards,  
David

---

<div class="post-metadata">

**Author:** ![Volodymyr](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@Volodymyr](https://forum.aousd.org/u/Volodymyr)\
**Post date:** [December 22, 2024, 11:14am UTC](https://forum.aousd.org/t/object-mask-with-primid-aov/2085/4 "2024-12-22T11:14:14Z")

</div>

Thanks for code samples.

For now I went with twice rendering to obtain mask. I guess I will need to implement object mask using primId if performance will be a concern.  
I guess I can mark it as a solution than.
