I'm trying to use an attribute generated from an instance position to affect the geometry of the instances. For example with the below setup, let's say I want to shift just the 4 top vertices of each cube, along the x-axis, by the amount given by the noise texture. Is it possible to use the noise texture value after realizing the geometry, or modifying the geometry in some other way?
This problem has come up in a variety of guises: 'How do we get a per-instance attribute into realized geometry?' If you want a per-instance color, deformation, or anything else, the route isn't obvious.
The hitch in Geometry Nodes at the moment is that there is nowhere on an unrealized instance to store an attribute. This looks as if it's going to change; there may be an 'Instance' domain coming to the Capture Attribute node in Blender 3.1.
At the time of writing, it doesn't yet work.
Edit: At 29 Dec 2021, in Blender 3.1 alpha, the 'Instance' domain is available and working. It makes the following hack unnecessary. See @qullenform's answer, instead.
If the instances are small enough, and don't overlap, you can often get away with direct transfer of an attribute to geometry by its vertex-proximity to the points on which the instances were generated, as shown in @Harisreedhar 's answer
If not, though, for now, you can employ some variation of this hack:
- Make a parallel branch of your tree, in which instances are scaled to 0 before being realized.
- Transfer the attribute to the scale-0 realized instances by proximity ('Nearest').
- Transfer the attribute back to the full-sized geometry by Index.
This makes the difference between the case on the left, below, (where the attribute is interpolated across vertices,) and the case on the right, (where the attribute is picked up per-instance).
In Blender 3.1+ there is the possibility to capture an attribute in the Instance domain, which makes various hacks superfluous.
Additionally, it is recommended to use a specific vertex group previously created as Group Input as Selection.
This selection is simply used as an input in the node
Of course, the vertex group can also be used directly during instantiation in the
Instance on Points node, depending on what result you want.
Why a vertex group instead of a mathematical solution?
If you want to instantiate different objects from a collection, you only need to create a vertex group in these objects with the identifier you chose before and define which points should be modified. This makes the selection easier to handle and less prone to errors.
To make a vertex group available in geometry nodes, simply create an Input of type Boolean, and specify the identifier of the vertex group.