Could you tell me if my idea is viable? I intended to have a modular character and at runtime change the meshes if the player equipped some armor. But I have thought of using a master material with displacement applied to the full character body (so not modular, one mesh). This master material would have:
As many UVs as body parts. In each UV a body part would be unwrapped through seams (so still the same mesh). So, UV1 would be head, UV2 torso, etc. Each of these would be indexed.
A bunch of textures (skin color, leather, steel, etc.). These would be indexed. E.g.: skin would be texture index 1, leather 2, etc.
A bunch of normals for all the potential materials: skin, leather, steel, etc. Each of these would be indexed as above.
A bunch of displacement maps. Each of these would belong to a specific piece of armor and would have an index associated. This way I can give a different density to the clothes.
Imagine we have a cloth instance in our inventory, the index from the UV of this cloth instance would determine what it is (gloves, helmet, etc.) and therefore what body part should it affect. Upon equipping the only thing that would happen is that our body mesh (thorugh the UV channel that belongs) would change the value of the parameters for normals and displacement to the ones of the other clothing that we have equipped. If these are gloves, then our hands will have changed texture to brown, normals will be leather, displacement will make the texture thicker. This would mean that we never change meshes, only the parameters in the master material. This way I could modify color/normals/displacement with some parameters at runtime and having only one mesh. I could also use morph targets since I would not be using the skeletal mesh merger.
Generally this intent is fine, and is quite common - Aside from the displacement mapping bit. That should technically work, but unless your clothes are very simple, and displacement is minimal, it can cause lots of headaches.
When I say the intent is fine, there are minor things you’d want to change in execution. You do not need a unique UV map per part, since each one consumes memory. You can easily index the parts some other way that doesn’t require unique UVs. For example, you could use one of the vertex color channels, or a singular extra UV map, where a vertex position within the map identifies it’s index. For example, you could stack all torso verts on (1,1) and legs on (1,2) and then reading the texture coordinate node for that UV index will return those values in the shader, allowing you to distinguish the body parts without having a while channel per.
As for displacement I just thought the same. Maybe it will look bad or there will be clipping, etc.
With respect to the 2nd uv yeah it make smore sense.
Anyways, I think I’ll just sulpt the meshes instead of using displacement, make a modular charcter and just swap parts out in the skeletal mesh merger.
This should also make things easier as for UV.
With 1 UV I could just make an atlas and place each mesh in the tile that belongs to the texture it should have. Then it would still be 1 draw call.
So I should have 2 draw calls: 1 per merged mesh and 1 for the material.
Most likely, yes. Since you will probably only ever be sampling just one of the textures on any given pixel at a time, you can avoid texture switching costs in the material by using an array. Arrays can cause slightly higher memory usage though, since it might result in a texture being loaded that doesn’t get used. But I think it is worth it, since you can re-use these texture arrays so extensively in the scene that overall you save memory.
Not using tarrays would likely mean multiple unnecessary texture samplers within one draw call, or multiple unnecessary draw calls using material instances.