How to apply material to 6 uv maps

Hi, I have a use case with a standardmaterial & diffuseTexture and a mesh with 6 different uv maps. I need to create thininstances that use the same material but with each instance using a different uv map. Is there any simple bjs built in method to hook up the desired uvkind VertexBuffer to the instanced’s material ? ie, each instance using a different coordinate index…

No, as all thin instances are using the same material than their master mesh.

If you want to use different texture parts depending on the thin instance, you will have to make a custom shader with a custom attribute to pass the u/v offset (and possibly width/height) of the texture part.

See for eg: thinInstance multiple materials for usage of a texture atlas with thin instances.

1 Like

Thanks for the quick reply. The PG is awesome!!
I want the thin instance to use the same material as master but using different uv maps. I don’t need atlasing or uv offsets since the mesh is alr unwrapped. If there is no built in method, I can create custom material. From source, it seems like node material allows for uv to uv6 variables. I presume,

thinInstanceRegisterAttribute("uv6", 2);

should work ?? If so, what should I pass to the attribute ?

thinInstanceSetAttributeAt("uv6", idx, whatToPassHere?);

If you want to use different textures for different thin instances, you will need to pass all the samplers to the shader and pass a data to the shader that will let you know which sampler to use for this instance. It’s startting to get complicated as thin instances are really meant to differ only by simple parameters (color, for eg).

In any case, you will need to create a custom material and create custom attribute(s) to pass data to the shader. See the tileOffset buffer from the linked PG above, which is a custom thin instance attribute.

1 Like

Guess I wasn’t clear enuff and looking back at the OP, I left out some details. In any case, due to time constraints and the fact that blender exporter limits uvmaps to 2, the title isn’t relevant anymore. I solved it the easy way with VAT+multi-materials+custom material. The issue is however fairly common, so I thought it might be best to share here.

The below pic illustrate what I’m trying to do. I have a low poly mesh and I want the spots on the body to vary (in a controllable fashion) on multiple thin instances.

For anyone also facing similar issue, these are the steps I took.

  1. Create 2 materials and assign 1 of them to the faces/UV island that needs variation. In my case, cow_body is a material that is assigned to the orange highlighted UVs only.

  2. export the mesh and importing into bjs will create a 2 subMeshes corresponding to the 2 materials. subMesh1 is the cow (head, tail, legs etc). subMesh2 refs the cow’s body.

  3. create your 1st material. For eg: a standard material with diffuse texture (top left of pic).

  4. create 2nd material. This 2nd material is essentially the 1st material with some custom shader codes (cf Popov’s linked PG above).

  5. create multi-material and push both materials into it, order is impt ! 1st material affects 1st subMesh. Refer to docs.

  6. create your thininstances and modify each instance’s attribute. The attribute should only affect the 2nd material’s UV (rot/scale/offset) and by doing so, only affect the 2nd submesh. You should see the texture on the mesh’s body transform but the rest of the mesh should not be affected.

My own thoughts:
This workflow is useful for texturing hordes of meshes that need some visual variation (think vegetation, people, animals etc). You don’t need much texture space or assets to work with. Exporting 2 materials doesn’t bloat up the babylon file size either. What I really wanted tho was not to use multi-material. Reason being that a single shader SHOULD be sufficient. I did not find simple way for the custom shader to decipher UV corrdinates based on submeshes. I guess this for someone better than me…=)

Major credit to @Evgeni_Popov, thank you very much!

Cheers! :slight_smile: