Description
It is possible to use one material for multiple models this way:
Model
{
...
materials: [
material1
]
}
Model
{
...
materials: [
material1
]
}
Model
{
...
materials: [
material1
]
}
CustomMaterial
{
id: material1
baseColor: "red"
}
It works, but if the CustomMaterial should work in a slightly different way for each model, then a separate instance of CustomMaterial has to be created for each model. If there are hundreds of models and the CustomMaterial is complicated it leads to huge overhead.
I would suggest 3 ways to solve this problem:
1) add MODEL_INDEX property to CustomMaterial shader. The index should be set in each Model instance and it will be possible to distinguish the models in the attached shader.
2) add "materialProperties" property to Model:
Model { materialProperties: MaterialPropertues { property var baseColor: "red" } }
The property value will be available in the attached shader.
3) Add "currentModel" property to CustomMaterial:
CustomMaterial
{
property var baseColor: currentModel.color
}
This way it will be possible to set different color for each Model with using only one CustomMaterial instance.