I have a book shelf full of books. Each book is instanced static mesh. Using vector parameter I can change book color, can I make it so each instance will have random color?
You cannot change material parameters on a per-instance basis because all of the instances are rendered in a single draw call with no material setting in between (which is part of what makes them faster to render).
But there is a PerInstanceRandom material node that will give you a consistent random number assigned to each instance. You could use that number to generate a color or as a texture coordinate to look up a value from a 1xn texture that you create with a different color in each pixel. That will give each book a consistent but different color.
Any chance we could pass some data to instanced static mesh so we can use PerInstanceData for example? Random isn’t much a win if you want to change color for specific instances.
Are you looking to change the color of a specific single instance, for example when the user interacts with it? If so the recommended workflow is to remove or hide the instance and replace it with a real actor while it’s being interacted with.
There is no other room in the per-instance data to store a per-instance color value or other data if you want to use instancing but have some specific parameter overridden per instance.
except that’s literally how PerInstanceRandom
works, so what’s stopping us from making an “override per instance random value(int idx, bool customOrRandom, float customValue)” node?
I’m gonna look into that and probably just extend a new HISMC child class (looks like it’s just some few changes that can easily be made by overriding/wrapping the right functions) and will report back with what i find.
This is fun) I don’t even remember why and where did I need this functionality!
common thing would be: using instanced cubes for minecraft-esque voxel rendering and then having a parameter for the texture etc
so i finally managed to make a plugin for that: https://gitlab.com/worstconcept/DerandomizeISMCs
it overrides the CreateSceneProxy functions of the 2 components (which internally would generate the random values) and resets their random values to their instance IDs. in hindsight that even looks easy but let’s just say i had to crawl through about 20 engine-private files with about 30k lines each till i figured out those functions i’m calling even exist
EDIT: my hack only seems to work half the time, soo i’m working on it but don’t yet rely on it please