# InstancedMesh with instances having different polygonOffsetFactors?

**URL:** <https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056>\
**Category:** Questions\
**Tags:** instanced-mesh, materials\
**Created:** [November 15, 2024, 8:21am UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056 "2024-11-15T08:21:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaurav\_D\_Kale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gaurav_d_kale/32/10377_2.png) [@Gaurav\_D\_Kale](https://discourse.threejs.org/u/Gaurav_D_Kale)\
**Post date:** [November 15, 2024, 8:21am UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/1 "2024-11-15T08:21:30Z")

</div>

I’m wondering if it’s possible to create a material for an InstancedMesh that has an additional buffer attribute to allow different `polygonOffsetFactor`s and `polygonOffsetUnit`s? I’m not at all familiar with how materials for instanced mesh’s support setting different colors, but figure if that’s possible I might just be able to pull off supporting this other material attribute. If it’s not possible I’m hoping someone wiser than me can help me prevent spending too much time diving into it to figure out that answer on my own

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [November 15, 2024, 4:59pm UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/2 "2024-11-15T16:59:52Z")

</div>

It is not, unless you implement this yourself in the shader somehow.

---

<div class="post-metadata">

**Author:** ![Gaurav\_D\_Kale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gaurav_d_kale/32/10377_2.png) [@Gaurav\_D\_Kale](https://discourse.threejs.org/u/Gaurav_D_Kale)\
**Post date:** [November 18, 2024, 8:20pm UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/3 "2024-11-18T20:20:15Z")

</div>

Thanks! Yea I figured it would likely involve making my own shader. Hopefully this doesn’t turn out to be too time consuming to figure out

---

<div class="post-metadata">

**Author:** ![manthrax](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/manthrax/32/2596_2.png) [@manthrax](https://discourse.threejs.org/u/manthrax)\
**Post date:** [November 18, 2024, 10:28pm UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/4 "2024-11-18T22:28:44Z")

</div>

Are you sure you need that?  
notice the polygonOffsetUnits and polygonOffsetFactor…

I think the ratios of those values control how the offset is distributed over distance.

---

<div class="post-metadata">

**Author:** ![Gaurav\_D\_Kale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gaurav_d_kale/32/10377_2.png) [@Gaurav\_D\_Kale](https://discourse.threejs.org/u/Gaurav_D_Kale)\
**Post date:** [November 19, 2024, 2:50am UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/5 "2024-11-19T02:50:20Z")

</div>

I use them to layer 2D UI within the same plane for [digitalbacon-ui](https://github.com/kalegd/DigitalBacon-UI/tree/main)

I’m open to suggestions that avoid the polygonOffset attributes if it still lets me do things like the below example

![](https://github.com/kalegd/DigitalBacon-UI/raw/main/images/readme-spotify.gif "text input demo")

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [November 19, 2024, 3:40am UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/6 "2024-11-19T03:40:03Z")

</div>

What about rendering one thing first, then another thing on top of it?

---

<div class="post-metadata">

**Author:** ![Gaurav\_D\_Kale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gaurav_d_kale/32/10377_2.png) [@Gaurav\_D\_Kale](https://discourse.threejs.org/u/Gaurav_D_Kale)\
**Post date:** [November 20, 2024, 12:21am UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/7 "2024-11-20T00:21:58Z")

</div>

Do you mean using renderOrder? I think there’s still be z-fighting happening for that?

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [November 20, 2024, 2:50am UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/8 "2024-11-20T02:50:31Z")

</div>

Well, you can turn off ordering altogether and order them any way you want. You can also turn off depth testing.

---

<div class="post-metadata">

**Author:** ![manthrax](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/manthrax/32/2596_2.png) [@manthrax](https://discourse.threejs.org/u/manthrax)\
**Post date:** [November 20, 2024, 4:05am UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/9 "2024-11-20T04:05:23Z")

</div>

You can try renderer.logarithmicDepthBuffer

---

<div class="post-metadata">

**Author:** ![Gaurav\_D\_Kale](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gaurav_d_kale/32/10377_2.png) [@Gaurav\_D\_Kale](https://discourse.threejs.org/u/Gaurav_D_Kale)\
**Post date:** [November 21, 2024, 1:50am UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/10 "2024-11-21T01:50:09Z")

</div>

@dubois I’ll play around with that and see if I can apply that to the shader for instanced meshes. I do want depth testing for the rest of the scene, but there might be a way to get that all sorted out  
@manthrax Will see if that helps thanks for the rec

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [November 21, 2024, 3:33am UTC](https://discourse.threejs.org/t/instancedmesh-with-instances-having-different-polygonoffsetfactors/74056/11 "2024-11-21T03:33:20Z")

</div>

You can render the background of the plate and write to stencil and depth, then you can render the contents and clip them inside the stencil without depth testing, then render the rest of the scene.
