Up until now, materials only had access to constants stored in the material itself, or attributes associated with the mesh vertices. However, in certain cases it is convenient to provide parameters associated with individual objects that use that material. This patch addresses that use case by adding two connected features to the Attribute node.
Access to the Alpha Channel
A new 'Alpha' output socket is added to the Attribute node, which returns the fourth channel of the attribute if available.
Currently there already is a four channel attribute (vertex color), but the alpha channel is only accessible through the dedicated Vertex Color node. This extends the generic attribute node to handle that case. If the attribute has fewer than 4 channels, the 'alpha' value is not well specified, but generally seems to be 1.
Object and Instance Attributes
As the main feature, a new dropdown allows switching the node from accessing Geometry attributes to the Object or Instance mode. In those modes the attribute name is interpreted as the name of a custom property, or a generic RNA path like the one produced by Copy Data Path.
The Object mode searches for the property in the object and its data ID in that order. The Instance mode additionally looks first in the particle system settings and the instance parent object if the current object was instanced.
This feature supports properties that are integer, float, or a float array of up to 4 components. The values are appropriately padded to have 4 channels, and the alpha channel is guaranteed to default to 1 if the property exists, or 0 if it was not found.
The primary reason for introducing the Geometry/Object/Instance dropdown is that without a way to distingush varying and uniform attributes when the material is compiled it would be very difficult to implement this for Eevee. Eevee is also limited to only 8 such attributes per material because of hardware limitations on UBO size.
Cycles seems to be designed with a common namespace for all attributes in mind, so the cycles-blender interface translates attribute types by internally adding a name prefix.
The code is available as individual commits at: https://developer.blender.org/diffusion/BS/history/temp-angavrilov-material-uniforms/
Test file (updated):