diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2020-08-05 19:14:40 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2020-11-03 16:35:44 +0300 |
commit | 6fdcca8de64cd70f237640b67ce2d0068b918d05 (patch) | |
tree | a894a557505bcd127d300edfb412ab57060ef2d2 /source/blender/gpu/intern/gpu_node_graph.h | |
parent | 91d320edc3cfb30443af4adbcb09bc3d7a609e1d (diff) |
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
Diffstat (limited to 'source/blender/gpu/intern/gpu_node_graph.h')
-rw-r--r-- | source/blender/gpu/intern/gpu_node_graph.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/gpu/intern/gpu_node_graph.h b/source/blender/gpu/intern/gpu_node_graph.h index 7265abf4d65..a0e6298cd92 100644 --- a/source/blender/gpu/intern/gpu_node_graph.h +++ b/source/blender/gpu/intern/gpu_node_graph.h @@ -42,6 +42,7 @@ typedef enum eGPUDataSource { GPU_SOURCE_CONSTANT, GPU_SOURCE_UNIFORM, GPU_SOURCE_ATTR, + GPU_SOURCE_UNIFORM_ATTR, GPU_SOURCE_BUILTIN, GPU_SOURCE_STRUCT, GPU_SOURCE_TEX, @@ -53,6 +54,7 @@ typedef enum eGPUDataSource { typedef enum { GPU_NODE_LINK_NONE = 0, GPU_NODE_LINK_ATTR, + GPU_NODE_LINK_UNIFORM_ATTR, GPU_NODE_LINK_BUILTIN, GPU_NODE_LINK_COLORBAND, GPU_NODE_LINK_CONSTANT, @@ -96,6 +98,8 @@ struct GPUNodeLink { struct GPUOutput *output; /* GPU_NODE_LINK_ATTR */ struct GPUMaterialAttribute *attr; + /* GPU_NODE_LINK_UNIFORM_ATTR */ + struct GPUUniformAttr *uniform_attr; /* GPU_NODE_LINK_IMAGE_BLENDER */ struct GPUMaterialTexture *texture; }; @@ -130,6 +134,8 @@ typedef struct GPUInput { struct GPUMaterialTexture *texture; /* GPU_SOURCE_ATTR */ struct GPUMaterialAttribute *attr; + /* GPU_SOURCE_UNIFORM_ATTR */ + struct GPUUniformAttr *uniform_attr; /* GPU_SOURCE_VOLUME_GRID | GPU_SOURCE_VOLUME_GRID_TRANSFORM */ struct GPUMaterialVolumeGrid *volume_grid; }; @@ -146,11 +152,15 @@ typedef struct GPUNodeGraph { ListBase attributes; ListBase textures; ListBase volume_grids; + + /* The list of uniform attributes. */ + GPUUniformAttrList uniform_attrs; } GPUNodeGraph; /* Node Graph */ void gpu_node_graph_prune_unused(GPUNodeGraph *graph); +void gpu_node_graph_finalize_uniform_attrs(GPUNodeGraph *graph); void gpu_node_graph_free_nodes(GPUNodeGraph *graph); void gpu_node_graph_free(GPUNodeGraph *graph); |