# Mixing a shared buffer and unique ones? Instance like deployment?

**URL:** <https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068>\
**Category:** Questions\
**Tags:** lighting\
**Created:** [September 24, 2021, 6:58pm UTC](https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068 "2021-09-24T18:58:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [September 24, 2021, 6:58pm UTC](https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068/1 "2021-09-24T18:58:17Z")

</div>

So how what would be the best way to have lets say 1000 nodes all with the same geometry buffer, all using the same material, all have different transform matrices, and a different uv2 buffer.

I have a couple ideas I want to try, but figured the greater good might have a better idea then me. Was thinking I might have to make my own shader that has the uv2 buffer just stacked on itself for all the nodes and then have an id and a stride offset for each mesh so I can associate the correct uv2.

Basically we are trying to solve this:

> [@Mesh Instances & Lightmaps](https://forum.babylonjs.com/t/mesh-instances-lightmaps/1857):
>
> Hi, I know that only the position, rotation and scaling properties can vary between instances and the root mesh. However, I was wondering if there is a way to also change the lightmaps for each instance. Let say in the case of each instances having different rotation, scaling and position they will be affected differently by light sources as such it will be good to provide a different lightmap for each instance. Thanks for your help.

Another thing I was thinking was that the SPS could handle it, or perhaps a extension of thin instances.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 24, 2021, 8:22pm UTC](https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068/2 "2021-09-24T20:22:45Z")

</div>

I do not think there is a nicely working way to do that.

Are the UVs more like an atlas so only scale and offset is changing or are they completely different ?

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [September 24, 2021, 8:25pm UTC](https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068/3 "2021-09-24T20:25:12Z")

</div>

Its for a lightmap so I think its like an atlas, are you saying use a custom shader that offset and scales the uv on the vertex the passes that as the uv2 to the fragement? Oooo dude I think you nailed it.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 24, 2021, 8:26pm UTC](https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068/4 "2021-09-24T20:26:24Z")

</div>

so basically you ll only need one more instance buffer to specify the texture offset scale matrix for each of the model

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [September 24, 2021, 8:31pm UTC](https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068/5 "2021-09-24T20:31:22Z")

</div>

👉 👈 😅 could you pretty please show me a small example of how I would go about that? I think I know but honestly am drawing a blank on if I should do it as a custom material or use thin instances or SPS.

Normally Id dive in on my own with this but I’m running mental blanks at the moment. So even a pointer to the right docs would help.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 24, 2021, 8:53pm UTC](https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068/6 "2021-09-24T20:53:02Z")

</div>

I d go with thin instances [Thin Instances | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/mesh/copies/thinInstances#faster-thin-instances) and a NME material.

I think @Evgeni_Popov as an example of such case ?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 24, 2021, 10:12pm UTC](https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068/7 "2021-09-24T22:12:06Z")

</div>

I’m not sure I understand correctly…

If your uv2 are completely different from one instance to the other you will have to put all the uv2s of all the instances in a texture and use an attribute to indicate the offset in this texture to start reading the uv for each instance.

This may help: [Separate value for each vertex for instances? - #2 by Evgeni\_Popov](https://forum.babylonjs.com/t/separate-value-for-each-vertex-for-instances/23274/2)

If your uv2 can be deduced from the uv by a simple offset + scale you can just pass this offset + scale as two instance attributes, but I doubt you are in this case.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [September 24, 2021, 10:19pm UTC](https://forum.babylonjs.com/t/mixing-a-shared-buffer-and-unique-ones-instance-like-deployment/24068/8 "2021-09-24T22:19:12Z")

</div>

So off reading that thread I think there is all the info needed.
