diff options
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_materials.c | 16 | ||||
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 9 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 4 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 26 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 14 |
5 files changed, 52 insertions, 17 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index 2b57c93202b..38c2fb50f81 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -1080,23 +1080,23 @@ void EEVEE_materials_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) } } -#define ADD_SHGROUP_CALL(shgrp, ob, geom, oedata) do { \ +#define ADD_SHGROUP_CALL(shgrp, ob, ma, geom, oedata) do { \ if (is_sculpt_mode_draw) { \ DRW_shgroup_call_sculpt_add(shgrp, ob, ob->obmat); \ } \ else { \ if (oedata) { \ - DRW_shgroup_call_object_add_with_callback(shgrp, geom, ob, EEVEE_lightprobes_obj_visibility_cb, oedata); \ + DRW_shgroup_call_object_add_with_callback(shgrp, geom, ob, ma, EEVEE_lightprobes_obj_visibility_cb, oedata); \ } \ else { \ - DRW_shgroup_call_object_add(shgrp, geom, ob); \ + DRW_shgroup_call_object_add_ex(shgrp, geom, ob, ma, false); \ } \ } \ } while (0) -#define ADD_SHGROUP_CALL_SAFE(shgrp, ob, geom, oedata) do { \ +#define ADD_SHGROUP_CALL_SAFE(shgrp, ob, ma, geom, oedata) do { \ if (shgrp) { \ - ADD_SHGROUP_CALL(shgrp, ob, geom, oedata); \ + ADD_SHGROUP_CALL(shgrp, ob, ma, geom, oedata); \ } \ } while (0) @@ -1536,11 +1536,11 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sld } /* Shading pass */ - ADD_SHGROUP_CALL(shgrp_array[i], ob, mat_geom[i], oedata); + ADD_SHGROUP_CALL(shgrp_array[i], ob, ma, mat_geom[i], oedata); /* Depth Prepass */ - ADD_SHGROUP_CALL_SAFE(shgrp_depth_array[i], ob, mat_geom[i], oedata); - ADD_SHGROUP_CALL_SAFE(shgrp_depth_clip_array[i], ob, mat_geom[i], oedata); + ADD_SHGROUP_CALL_SAFE(shgrp_depth_array[i], ob, ma, mat_geom[i], oedata); + ADD_SHGROUP_CALL_SAFE(shgrp_depth_clip_array[i], ob, ma, mat_geom[i], oedata); char *name = auto_layer_names; for (int j = 0; j < auto_layer_count; ++j) { diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 2e91c8fd62d..77b8cdacb47 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -363,11 +363,12 @@ void DRW_shgroup_call_procedural_points_add(DRWShadingGroup *shgroup, uint point void DRW_shgroup_call_procedural_lines_add(DRWShadingGroup *shgroup, uint line_count, float (*obmat)[4]); void DRW_shgroup_call_procedural_triangles_add(DRWShadingGroup *shgroup, uint tria_count, float (*obmat)[4]); void DRW_shgroup_call_object_procedural_triangles_culled_add(DRWShadingGroup *shgroup, uint tria_count, struct Object *ob); -void DRW_shgroup_call_object_add_ex(DRWShadingGroup *shgroup, struct GPUBatch *geom, struct Object *ob, bool bypass_culling); -#define DRW_shgroup_call_object_add(shgroup, geom, ob) DRW_shgroup_call_object_add_ex(shgroup, geom, ob, false) -#define DRW_shgroup_call_object_add_no_cull(shgroup, geom, ob) DRW_shgroup_call_object_add_ex(shgroup, geom, ob, true) +void DRW_shgroup_call_object_add_ex( + DRWShadingGroup *shgroup, struct GPUBatch *geom, struct Object *ob, struct Material *ma, bool bypass_culling); +#define DRW_shgroup_call_object_add(shgroup, geom, ob) DRW_shgroup_call_object_add_ex(shgroup, geom, ob, NULL, false) +#define DRW_shgroup_call_object_add_no_cull(shgroup, geom, ob) DRW_shgroup_call_object_add_ex(shgroup, geom, ob, NULL, true) void DRW_shgroup_call_object_add_with_callback( - DRWShadingGroup *shgroup, struct GPUBatch *geom, struct Object *ob, + DRWShadingGroup *shgroup, struct GPUBatch *geom, struct Object *ob, struct Material *ma, DRWCallVisibilityFn *callback, void *user_data); /* Used for drawing a batch with instancing without instance attribs. */ void DRW_shgroup_call_instances_add( diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 5916b45aa27..bba98f5e102 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -101,6 +101,7 @@ enum { DRW_CALL_NORMALWORLD = (1 << 5), DRW_CALL_ORCOTEXFAC = (1 << 6), DRW_CALL_EYEVEC = (1 << 7), + DRW_CALL_OBJECTINFO = (1 << 8), }; typedef struct DRWCallState { @@ -122,6 +123,7 @@ typedef struct DRWCallState { float normalview[3][3]; float normalworld[3][3]; /* Not view dependent */ float orcotexfac[2][3]; /* Not view dependent */ + float objectinfo[2]; float eyevec[3]; } DRWCallState; @@ -140,6 +142,7 @@ typedef struct DRWCall { union { struct { /* type == DRW_CALL_SINGLE */ GPUBatch *geometry; + short ma_index; } single; struct { /* type == DRW_CALL_RANGE */ GPUBatch *geometry; @@ -257,6 +260,7 @@ struct DRWShadingGroup { int orcotexfac; int eye; int callid; + int objectinfo; uint16_t matflag; /* Matrices needed, same as DRWCall.flag */ #ifndef NDEBUG diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index 371bd9dd189..0bed4e3f4b3 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -36,6 +36,7 @@ #include "DNA_mesh_types.h" #include "DNA_meta_types.h" +#include "BLI_hash.h" #include "BLI_link_utils.h" #include "BLI_mempool.h" @@ -344,6 +345,22 @@ static DRWCallState *drw_call_state_create(DRWShadingGroup *shgroup, float (*obm state->matflag &= ~DRW_CALL_ORCOTEXFAC; } + if ((state->matflag & DRW_CALL_OBJECTINFO) != 0) { + state->objectinfo[0] = ob ? ob->index : 0; + unsigned int random; + #if 0 /* TODO(fclem) handle dupli objects */ + if (GMS.dob) { + random = GMS.dob->random_id; + } + else + #endif + { + random = BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0); + } + state->objectinfo[2] = random * (1.0f / (float)0xFFFFFFFF); + state->matflag &= ~DRW_CALL_OBJECTINFO; + } + return state; } @@ -440,7 +457,7 @@ void DRW_shgroup_call_object_procedural_triangles_culled_add(DRWShadingGroup *sh } /* These calls can be culled and are optimized for redraw */ -void DRW_shgroup_call_object_add_ex(DRWShadingGroup *shgroup, GPUBatch *geom, Object *ob, bool bypass_culling) +void DRW_shgroup_call_object_add_ex(DRWShadingGroup *shgroup, GPUBatch *geom, Object *ob, Material *ma, bool bypass_culling) { BLI_assert(geom != NULL); BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM)); @@ -449,6 +466,7 @@ void DRW_shgroup_call_object_add_ex(DRWShadingGroup *shgroup, GPUBatch *geom, Ob call->state = drw_call_state_object(shgroup, ob->obmat, ob); call->type = DRW_CALL_SINGLE; call->single.geometry = geom; + call->single.ma_index = ma ? ma->index : 0; #ifdef USE_GPU_SELECT call->select_id = DST.select_id; #endif @@ -460,7 +478,7 @@ void DRW_shgroup_call_object_add_ex(DRWShadingGroup *shgroup, GPUBatch *geom, Ob } void DRW_shgroup_call_object_add_with_callback( - DRWShadingGroup *shgroup, GPUBatch *geom, Object *ob, + DRWShadingGroup *shgroup, GPUBatch *geom, Object *ob, Material *ma, DRWCallVisibilityFn *callback, void *user_data) { BLI_assert(geom != NULL); @@ -472,6 +490,7 @@ void DRW_shgroup_call_object_add_with_callback( call->state->user_data = user_data; call->type = DRW_CALL_SINGLE; call->single.geometry = geom; + call->single.ma_index = ma ? ma->index : 0; #ifdef USE_GPU_SELECT call->select_id = DST.select_id; #endif @@ -635,6 +654,7 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) shgroup->normalview = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_NORMAL); shgroup->normalworld = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_WORLDNORMAL); shgroup->orcotexfac = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_ORCO); + shgroup->objectinfo = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_OBJECT_INFO); shgroup->eye = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_EYE); shgroup->callid = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_CALLID); @@ -653,6 +673,8 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) shgroup->matflag |= DRW_CALL_NORMALWORLD; if (shgroup->orcotexfac > -1) shgroup->matflag |= DRW_CALL_ORCOTEXFAC; + if (shgroup->objectinfo > -1) + shgroup->matflag |= DRW_CALL_OBJECTINFO; if (shgroup->eye > -1) shgroup->matflag |= DRW_CALL_EYEVEC; } diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 938dda2eec9..7a4edc4e7fe 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -801,10 +801,16 @@ static void draw_matrices_model_prepare(DRWCallState *st) } } -static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCallState *state) +static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call) { /* step 1 : bind object dependent matrices */ - if (state != NULL) { + if (call != NULL) { + DRWCallState *state = call->state; + float objectinfo[3]; + objectinfo[0] = state->objectinfo[0]; + objectinfo[1] = call->single.ma_index; /* WATCH this is only valid for single drawcalls. */ + objectinfo[2] = state->objectinfo[1]; + GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)state->model); GPU_shader_uniform_vector(shgroup->shader, shgroup->modelinverse, 16, 1, (float *)state->modelinverse); GPU_shader_uniform_vector(shgroup->shader, shgroup->modelview, 16, 1, (float *)state->modelview); @@ -812,6 +818,7 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCallState *state) GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)state->modelviewprojection); GPU_shader_uniform_vector(shgroup->shader, shgroup->normalview, 9, 1, (float *)state->normalview); GPU_shader_uniform_vector(shgroup->shader, shgroup->normalworld, 9, 1, (float *)state->normalworld); + GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 3, 1, (float *)objectinfo); GPU_shader_uniform_vector(shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)state->orcotexfac); GPU_shader_uniform_vector(shgroup->shader, shgroup->eye, 3, 1, (float *)state->eyevec); } @@ -825,6 +832,7 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCallState *state) GPU_shader_uniform_vector(shgroup->shader, shgroup->modelview, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_VIEW]); GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewinverse, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_VIEWINV]); GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_PERS]); + GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 3, 1, (float *)unitmat); GPU_shader_uniform_vector(shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)shgroup->instance_orcofac); } } @@ -1205,7 +1213,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) } GPU_SELECT_LOAD_IF_PICKSEL_CALL(call); - draw_geometry_prepare(shgroup, call->state); + draw_geometry_prepare(shgroup, call); switch (call->type) { case DRW_CALL_SINGLE: |