# Name collision from MaterialX generated shaders in Storm

**URL:** <https://forum.aousd.org/t/name-collision-from-materialx-generated-shaders-in-storm/393>\
**Category:** Hydra\
**Created:** [August 21, 2023, 3:35pm UTC](https://forum.aousd.org/t/name-collision-from-materialx-generated-shaders-in-storm/393 "2023-08-21T15:35:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashwin.bhat](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ashwin.bhat](https://forum.aousd.org/u/ashwin.bhat)\
**Post date:** [August 21, 2023, 3:35pm UTC](https://forum.aousd.org/t/name-collision-from-materialx-generated-shaders-in-storm/393/1 "2023-08-21T15:35:17Z")

</div>

Hi  
I’m running into an issue with uniform name collision from MaterialX generated shaders in Storm. In our library we have a node called `normal_map` and one of the inputs is (float) `normal_scale`. This node is namespaced as `adsk:normal_map` to prevent node collison.

```auto
  <nodedef name="ND_adsk_normal_map" node="normal_map" nodegroup="texture2d" version="1.0.1" isdefaultversion="true" namespace="adsk">
    <input name="file" type="filename" />
    <!-- normal scale -->
    <input name="normal_scale" type="float" value="1.0" />
    ...
    <output name="out" type="vector3" />
  </nodedef>

```

For the normal\_scale input, MaterialX generates a uniform parameter `float normal_map_normal_scale`

Since normal\_map is connected to Standard Surface normal input the the resolved parameter in Storm is normal\_map\_normal. Now, since Storm adds a scale and bias uniform for texture types this adds a `vec4 normal_map_normal_scale` to the parameter list. The final glsl fails to compile due to this duplicate  
float normal\_map\_normal\_scale and vec4 normal\_map\_normal\_scale

The fix is to make them unique, for example Storm could add a _hdst_ prefix to make it normal\_map\_normal\_hdst\_scale which is suitable workaround. It also is clearer wrt to storm added uniforms v/s materialx uniforms. We could also check for duplicates in storm which might be a performance overhead.

I think we be to use node namespaces in uniform names  
i.e. adsk:normal\_map/normal\_scale becomes adsk\_normal\_map\_normal\_scale  
I’m not sure if embedding the namespace in the uniform will cause any issues.

I’m wondering what folks think about this approach. This would be change to MaterialX shader generation and parameter reflection which is used in Storm.

Thanks  
Ashwin Bhat

---

<div class="post-metadata">

**Author:** ![bernardkwok](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/bernardkwok/32/172_2.png) [@bernardkwok](https://forum.aousd.org/u/bernardkwok)\
**Post date:** [August 28, 2023, 12:00am UTC](https://forum.aousd.org/t/name-collision-from-materialx-generated-shaders-in-storm/393/2 "2023-08-28T00:00:11Z")

</div>

Hi Ashwin,

Could you provide how this looks with an example mtlx and code generated?

By Storm, I assume this means the custom code generator used there? If its injecting additional uniforms then should it not just check for existing ones to avoid a name clash regardless of whether a namespace is involved?

This is my supposition, but maybe need some more info.

Thanks,  
Bernard

---

<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:** [September 5, 2023, 6:48pm UTC](https://forum.aousd.org/t/name-collision-from-materialx-generated-shaders-in-storm/393/3 "2023-09-05T18:48:10Z")

</div>

Hey Ashwin,

I like the idea of preserving the namespace in the name we give to the shader, and would be supportive of that change (even aside from the related bug). It sounds like that may fix the issue, but if you’d like us to do anything on the storm shader gen side as well let us know! We’re exploring adding the “hydra:” namespace for primvars we generate in usdImaging, and could do something similar for things we add in hdSt material generation as well.

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![ashwin.bhat](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ashwin.bhat](https://forum.aousd.org/u/ashwin.bhat)\
**Post date:** [September 5, 2023, 11:31pm UTC](https://forum.aousd.org/t/name-collision-from-materialx-generated-shaders-in-storm/393/4 "2023-09-05T23:31:47Z")

</div>

Hey Tom,  
That’s great to hear, getting namespace embedded via MaterialX will need some additional discussion with MaterialX folks.

For now, in hdSt, I’m adding a token: `((stormGenerated, "hdSt"))` and using this to address conflicts.  
I can prepare a PR with this change if required.  
Thanks  
Ashwin
