Using random values on each instance in Node Shader

Hi all, first post here :wave:

I’m trying to create a shader in Node Material Editor that will take a base texture image and adjust it randomly for each instance of a mesh (in my case, tweaking the green value to create nice varied trees).
I’m quite new to shaders, my method so far has been trying to adjust the Vector2 ‘seed’ value of a Random number block using a custom buffer. What I have so far is just changing the value for all on load, but not per instance.
I am a bit unsure about what attributes I can grab using registerInstancedBuffer (‘color’ is the main one I’ve seen in examples), I’ve seen other examples where they use the AddAttribute method but that isn’t with Node materials(?). I’ve also seen examples where a texture is combined with another colour from the instance buffer but it would be good for me to grab a value and do more stuff with it in the NME.
Finally, I can’t find much information on what the instanceID output of the Instances block does (but this is a bit of a bonus topic :slight_smile: )

heres my playground with some commented out code:
and my material:

Cheers :+1:

Only the Color attribute of the mesh is exposed in the Node Material Editor. Perhaps in the Node Material itself. You can use the Color attribute:

1 Like

Thank you, thats good to know so I’m not looking for other attributes, its not so clear in the documentation (or I missed it).
So, is there any reason not to just use those 4 (rgba) colour values to change other parts of the shader (instead of color)?
like here, changing the mesh position:

Here’s an example of your original version, simply changing your Vector2 to an attribute and rebuilding the material. That does the trick as well, and doesn’t waste buffer space.

Unless you have some plan for the remaining color channels, I would go with a Vector2. Position, rotation and scale are all handled in the transform, so I don’t see the idea of using a shader to manually change those. You could instead use the channels to add effects like random sway, wind-dependent sway and other tree-behavior.

1 Like

Great, this was the line i was looking for I guess:
Thats the key from getting values from an instance to a shader block :old_key:
Much appreciated :pray:

1 Like