Multimaterial for instant meshes

Hello!
I want to know if here is any way to create material simmilar to CoronaMultiMap?
The main task is to give controllable variety (frequency) of colours with random distribution to instant meshes or particles.
Later aim is to make a widget to see realtime blending of colours.
Sorry for my 0 Level.


The blueprint that spawns the meshes ( or sets their material ), can have an array of colors. It also has an array to sort out the frequencies.

Basically, you can use the frequency array ( which just holds integers ) to fill a third array, which contains the colors in the proportion you want. All you have to do then is shuffle it and run.

( just say if you want an example, that description was a bit crap… )

If you have, say, a hundred meshes, then the easiest way is to create Material Instance Dynamic for each of the objects, and set a “color” parameter on each instance to a random value. You can have an array of colors, and pick one randomly for each material instance. If you want some colors to be more frequent, just add multiple elements with the same color to the array.

If you have a thousand or more meshes, you need to be fancier, because 1000 MIDs aren’t going to perform well. Easiest is probably to generate a noise texture, set it to “nearest neighbor” sampling, and stretch it across all the objects, such that there’s one texel per object (if they’re on a regular grid.) The object would then sample this texture, in world space, to get the output color.

A final option is to use mesh instancing, and use some hash function (or 1D texture look-up table) in the material instance that’s based on instance id (instance index/number) to derive the color.

I guess there would be several millions of mesh instances. And I need to mix about 10 colours in specified percentage to see the final color of this mix in big area
Example:
111

I realy want example :pray:
Guess it could be a solution.

Like @jwatte says, for millions, doing it programatically is no good. Nobody’s going to know anyway.

So you might as well do something with a noise map, and apply the same material to everything.

Create a large (1024x1024 or 4096x4096) noise texture.

In your shader, get a per-instance random, which is either PerInstanceRandom, or it’s the X/Y world space coordinates of the instance, multiply by world stretch scale, which will be something like 0.0001 (depending on texel resolution and actual size of the mesh instances.)
Sample color texture in nearest-neighbor mode at the origin/center of the instance, for each vertex/pixel.
It’s important MIP maps are off in this sampling, else they’ll all get the average color.

To make certain colors more common, make those colors more common in your noise texture.