Unique material (properties) per spawned instance

Problem:

I need to spawn various things but with separate materials because I need
to access the material links (value/rgb) on each object separately for
individual color modulation.

I get the color modulation going, no problem, but obviously they share the same
material, so all of them do the same thing.
I need to be able to apply color modulation individually per instance.

I think I need to clone/duplicate the material at runtime when the object spawns?
Or add a new one per instance? Not sure. Maybe I think too complicated.

Usually in other engines there is something like “unique per instance” or “local to scene” or stuff like that so that changing a value is unique to the instance and doesn’t affect all of them. But I guess we have to code this behaviour ourselves. Any ideas?

To set a new color on each instance of an object, you could use shader data node in the shader nodes as a uniform.

Have a look at the uniform _uid in Object uniforms.

Otherwise, you may have to manually create new martials for each instance beforehand and then apply them at runtime.

2 Likes

So it seems that custom material shaders have some problems.
For example: This looks (still) correct to me:

However when running this (or my own take on that), I get this:

    at Function.haxe_io_Bytes.ofData (<anonymous>:7671:13)
    at Function.kha_LoaderImpl.loadBlobFromDescription (<anonymous>:25712:48)
    at Function.kha_Assets.loadBlobFromPath (<anonymous>:24799:17)
    at Function.iron_data_Data.getBlob (<anonymous>:9821:13)
    at Function.iron_data_Data.getSceneRaw (<anonymous>:9657:17)
    at Function.iron_data_ShaderData.parse (<anonymous>:10868:17)
    at Function.iron_data_Data.getShader (<anonymous>:9627:23)
    at new iron_data_MaterialData (<anonymous>:10536:17)
    at <anonymous>:10567:3
    at Function.iron_data_Data.getSceneRaw (<anonymous>:9645:3) 

Did anything change in the definitions?
Would like to ping @BlackGoku36 here…