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/draw/intern/draw_manager.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/draw/intern/draw_manager.h')
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 8e505d5df71..dae204ad9f7 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -43,6 +43,9 @@ #include "draw_instance_data.h" +struct Object; +struct DupliObject; + /* Use draw manager to call GPU_select, see: DRW_draw_select_loop */ #define USE_GPU_SELECT @@ -286,6 +289,7 @@ typedef enum { /** Per drawcall uniforms/UBO */ DRW_UNIFORM_BLOCK_OBMATS, DRW_UNIFORM_BLOCK_OBINFOS, + DRW_UNIFORM_BLOCK_OBATTRS, DRW_UNIFORM_RESOURCE_CHUNK, DRW_UNIFORM_RESOURCE_ID, /** Legacy / Fallback */ @@ -317,6 +321,8 @@ struct DRWUniform { float fvalue[4]; /* DRW_UNIFORM_INT_COPY */ int ivalue[4]; + /* DRW_UNIFORM_BLOCK_OBATTRS */ + struct GPUUniformAttrList *uniform_attrs; }; int location; /* Uniform location or binding point for textures and ubos. */ uint8_t type; /* DRWUniformType */ @@ -340,6 +346,9 @@ struct DRWShadingGroup { struct { int objectinfo; /* Equal to 1 if the shader needs obinfos. */ DRWResourceHandle pass_handle; /* Memblock key to parent pass. */ + + /* Set of uniform attributes used by this shader. */ + struct GPUUniformAttrList *uniform_attrs; }; /* This struct is used after cache populate if using the Z sorting. * It will not conflict with the above struct. */ @@ -598,3 +607,10 @@ void drw_resource_buffer_finish(ViewportMemoryPool *vmempool); GPUBatch *drw_cache_procedural_points_get(void); GPUBatch *drw_cache_procedural_lines_get(void); GPUBatch *drw_cache_procedural_triangles_get(void); + +void drw_uniform_attrs_pool_update(struct GHash *table, + struct GPUUniformAttrList *key, + DRWResourceHandle *handle, + struct Object *ob, + struct Object *dupli_parent, + struct DupliObject *dupli_source); |