# Advice on implementing new prim type

**URL:** <https://forum.aousd.org/t/advice-on-implementing-new-prim-type/611>\
**Category:** Hydra\
**Created:** [September 7, 2023, 2:01pm UTC](https://forum.aousd.org/t/advice-on-implementing-new-prim-type/611 "2023-09-07T14:01:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisK](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@ChrisK](https://forum.aousd.org/u/ChrisK)\
**Post date:** [September 7, 2023, 2:01pm UTC](https://forum.aousd.org/t/advice-on-implementing-new-prim-type/611/1 "2023-09-07T14:01:57Z")

</div>

Hi,  
I have been ask to implement a feature in our USD/Solaris pipeline at Dneg. Before I go to far with this I thought I should ask for advice here. Maybe somebody has done something similar.

I need to display a rectangle in the viewport with a texture applied. However, I need to do a couple of things with that texture that I don’t think I can do with a preview surface shader.

1. I need to be able to display data from the texture outside of the crop window.
2. I need to apply artistic color adjustments available as OCIO “looks”.

We have this functionality in our Maya pipeline and we want to match that in Houdini Solaris.  
At first glance, I think the easiest thing will be to implement a custom hydra prim that does what I need. I am starting with Richard Lei’s wonderful plugin examples. [GitHub - wetadigital/USDPluginExamples: Simple Examples to demonstrate how to compile and build USD plugins](https://github.com/wetadigital/USDPluginExamples).

Does this sound like a reasonable approach? Am I missing anything?

Thanks,  
Chris King  
Dneg

---

<div class="post-metadata">

**Author:** ![spiff](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/spiff/32/22_2.png) [@spiff](https://forum.aousd.org/u/spiff)\
**Post date:** [September 9, 2023, 10:30pm UTC](https://forum.aousd.org/t/advice-on-implementing-new-prim-type/611/2 "2023-09-09T22:30:46Z")

</div>

Hey Chris,  
Seems like the unknowns here are all Hydra-related, so I’m recategorizing over to the Hydra category.

–spiff

---

<div class="post-metadata">

**Author:** ![ChrisK](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@ChrisK](https://forum.aousd.org/u/ChrisK)\
**Post date:** [September 11, 2023, 6:02pm UTC](https://forum.aousd.org/t/advice-on-implementing-new-prim-type/611/3 "2023-09-11T18:02:44Z")

</div>

After thinking about this for a bit it seems like what work is a custom texture sampler that implements the behaviors I’m looking for.

This brings up a few questions?

1. Is is possible to register a custom texture sampler in a plugin?
2. The glsl code for the uvTexture node is intentionally left blank. I assume that some internal code detects the existing of a uvTextureNode and wires up a sampler object such that HdGet\_diffuseColor does the right thing. I think what I am trying to do is to create a new node similar to uvTexture but gets wired up to a sampler that implements the behaviour that I need. Is that possible? Do you have any clues on how it might be done?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![mtucker](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mtucker](https://forum.aousd.org/u/mtucker)\
**Post date:** [September 22, 2023, 8:17pm UTC](https://forum.aousd.org/t/advice-on-implementing-new-prim-type/611/4 "2023-09-22T20:17:36Z")

</div>

Hey Chris,

I just wanted to make sure that it’s clear that any changes you make involving glsl shaders are only going to apply to Storm, not HoudiniGL… Hopefully this isn’t a problem for what you’re trying to accomplish.

I didn’t really understand the description of what you’re trying to do, but have you looked at using Mtlx to describe the appearance of your rectangle? Storm and Houdini GL both support Mtlx shaders, at least in theory 🙂 You mention creating a custom hydra prim (like hdTri?) which implies you are targeting only your own custom render delegate, in which case I guess you have a lot more options and control…

Mark

---

<div class="post-metadata">

**Author:** ![ChrisK](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@ChrisK](https://forum.aousd.org/u/ChrisK)\
**Post date:** [September 22, 2023, 8:43pm UTC](https://forum.aousd.org/t/advice-on-implementing-new-prim-type/611/5 "2023-09-22T20:43:19Z")

</div>

Hey Mark,  
Thanks so much for responding.

When I started investigating this I thought a custom Hydra prim might be a way forward but I realize now that is not really workable.  
I always thought that Solaris was using Storm under the hood. Doh!  
I think the main thing I need to accomplish is to build a custom texture node. I think a normal texture node will just read the pixels that in the crop rectangle that is stored in the image. In our workflow for camera image planes, artist want to be able to see “overscan” pixels.  
I didn’t realize HoudiniGL supported materialX. I’ll give that a shot.

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![mtucker](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mtucker](https://forum.aousd.org/u/mtucker)\
**Post date:** [September 22, 2023, 9:12pm UTC](https://forum.aousd.org/t/advice-on-implementing-new-prim-type/611/6 "2023-09-22T21:12:35Z")

</div>

Great, let me know if you hit any snags!

---

<div class="post-metadata">

**Author:** ![tomc](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tomc](https://forum.aousd.org/u/tomc)\
**Post date:** [October 6, 2023, 11:41pm UTC](https://forum.aousd.org/t/advice-on-implementing-new-prim-type/611/7 "2023-10-06T23:41:21Z")

</div>

Hey Chris,

Sounds like you have a direction already, and MaterialX is a great thing to try, but just to clarify: you’re correct that hdStorm generates code for UsdUVTexture, as well as the other texture nodes. You can edit sampling parameters on the texture node, and those will be set in the corresponding shader sampler.

I don’t 100% understand your use case, but if you’re just looking to load up an image whose UV space is larger than [0, 1]^2 (e.g. the texture is mapped to [-0.2, 1.2]^2 but [0,1]^2 represents the “viewport” part), do note that you can transform UV space with the UsdTransform2d texture node: [UsdPreviewSurface Specification — Universal Scene Description 23.08 documentation](https://openusd.org/release/spec_usdpreviewsurface.html#transform2d).

Thanks,  
Tom
