The attribute node already allows accessing attributes associated with objects and meshes, which allows changing the behavior of the same material between different objects or instances. The same idea can be extended to an even more global level of layers and scenes. Currently view layers provide an option to replace all materials with a different one. However, since the same material will be applied to all objects in the layer, varying the behavior between layers while preserving distinct materials requires duplicating objects. Providing access to properties of layers and scenes via the attribute node enables making materials with built-in switches or settings that can be controlled globally at the view layer level. This is probably most useful for complex NPR shading and compositing. Like with objects, the node can also access built-in scene properties, like render resolution or FOV of the active camera. Lookup is also attempted in World, similar to how the Object mode checks the Mesh datablock. In Cycles this mode is implemented by replacing the attribute node with the attribute value during sync, allowing constant folding to take the values into account. This means however that materials that use this feature have to be re-synced upon any changes to scene, world or camera. The Eevee version uses a new uniform buffer containing a sorted array mapping name hashes to values, with binary search lookup. The array is limited to 512 entries, which is effectively limitless even considering it is shared by all materials in the scene; it is also just 16KB of memory so no point trying to optimize further. The buffer has to be rebuilt when new attributes are detected in a material, so the draw engine keeps a table of recently seen attribute names to minimize the chance of extra rebuilds mid-draw. Differential Revision: https://developer.blender.org/D15941
65 lines
1.4 KiB
GLSL
65 lines
1.4 KiB
GLSL
|
|
void node_attribute_color(vec4 attr, out vec4 out_attr)
|
|
{
|
|
out_attr = attr_load_color_post(attr);
|
|
}
|
|
|
|
void node_attribute_temperature(vec4 attr, out vec4 out_attr)
|
|
{
|
|
out_attr.x = attr_load_temperature_post(attr.x);
|
|
out_attr.y = 0.0;
|
|
out_attr.z = 0.0;
|
|
out_attr.w = 1.0;
|
|
}
|
|
|
|
void node_attribute_density(vec4 attr, out float out_attr)
|
|
{
|
|
out_attr = attr.x;
|
|
}
|
|
|
|
void node_attribute_flame(vec4 attr, out float out_attr)
|
|
{
|
|
out_attr = attr.x;
|
|
}
|
|
|
|
void node_attribute_uniform(vec4 attr, const float attr_hash, out vec4 out_attr)
|
|
{
|
|
/* Temporary solution to support both old UBO attribs and new SSBO loading.
|
|
* Old UBO load is already done through `attr` and will just be passed through. */
|
|
out_attr = attr_load_uniform(attr, floatBitsToUint(attr_hash));
|
|
}
|
|
|
|
vec4 attr_load_layer(const uint attr_hash)
|
|
{
|
|
#ifdef VLATTR_LIB
|
|
/* The first record of the buffer stores the length. */
|
|
uint left = 0, right = drw_layer_attrs[0].buffer_length;
|
|
|
|
while (left < right) {
|
|
uint mid = (left + right) / 2;
|
|
uint hash = drw_layer_attrs[mid].hash_code;
|
|
|
|
if (hash < attr_hash) {
|
|
left = mid + 1;
|
|
}
|
|
else if (hash > attr_hash) {
|
|
right = mid;
|
|
}
|
|
else {
|
|
return drw_layer_attrs[mid].data;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return vec4(0.0);
|
|
}
|
|
|
|
void node_attribute(
|
|
vec4 attr, out vec4 outcol, out vec3 outvec, out float outf, out float outalpha)
|
|
{
|
|
outcol = vec4(attr.xyz, 1.0);
|
|
outvec = attr.xyz;
|
|
outf = avg(attr.xyz);
|
|
outalpha = attr.w;
|
|
}
|