diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-07-14 17:49:44 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-08-14 20:05:26 +0300 |
commit | 9c010c44f4201ab114b3facc69d0343525a1779f (patch) | |
tree | 744271becd24cead6c900e4f023d8c0bfa6138b6 /source/blender/draw/modes | |
parent | 45a45f7d66211e82a3a3288782ad9523e8fdc516 (diff) |
Mesh Batch Cache: Refactor + Multithread
For clarity sake, the batch cache now uses exclusively per Loop attributes.
While this is a bit of a waste of VRAM (for the few case where per vert
attribs are enough) it reduces the complexity and amount of overall VBO
to update in general situations.
This patch also makes the VertexBuffers filling multithreaded. This make
the update of dense meshes a bit faster. The main bottleneck is the
IndexBuffers update which cannot be multithreaded efficiently (have to
increment a counter and/or do a final sorting pass).
We introduce the concept of "extract" functions/step.
All extract functions are executed in one thread each and if possible,
using multiple thread for looping over all elements.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D5424
Diffstat (limited to 'source/blender/draw/modes')
3 files changed, 28 insertions, 38 deletions
diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c index f0e35e47a66..f8247d7929e 100644 --- a/source/blender/draw/modes/edit_mesh_mode.c +++ b/source/blender/draw/modes/edit_mesh_mode.c @@ -128,8 +128,7 @@ typedef struct EDIT_MESH_Shaders { GPUShader *depth; /* Mesh analysis shader */ - GPUShader *mesh_analysis_face; - GPUShader *mesh_analysis_vertex; + GPUShader *mesh_analysis; } EDIT_MESH_Shaders; /* *********** STATIC *********** */ @@ -307,15 +306,9 @@ static void EDIT_MESH_engine_init(void *vedata) }); /* Mesh Analysis */ - sh_data->mesh_analysis_face = GPU_shader_create_from_arrays({ + sh_data->mesh_analysis = GPU_shader_create_from_arrays({ .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl, NULL}, .frag = (const char *[]){datatoc_edit_mesh_overlay_mesh_analysis_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg_data->def, "#define FACE_COLOR\n", NULL}, - }); - sh_data->mesh_analysis_vertex = GPU_shader_create_from_arrays({ - .vert = (const char *[]){lib, datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl, NULL}, - .frag = (const char *[]){datatoc_edit_mesh_overlay_mesh_analysis_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg_data->def, "#define VERTEX_COLOR\n", NULL}, }); MEM_freeN(lib); @@ -548,10 +541,9 @@ static void EDIT_MESH_cache_init(void *vedata) /* Mesh Analysis Pass */ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND_ALPHA; psl->mesh_analysis_pass = DRW_pass_create("Mesh Analysis", state); - const bool is_vertex_color = scene->toolsettings->statvis.type == SCE_STATVIS_SHARP; - g_data->mesh_analysis_shgrp = DRW_shgroup_create( - is_vertex_color ? sh_data->mesh_analysis_vertex : sh_data->mesh_analysis_face, - psl->mesh_analysis_pass); + g_data->mesh_analysis_shgrp = DRW_shgroup_create(sh_data->mesh_analysis, + psl->mesh_analysis_pass); + DRW_shgroup_uniform_texture(g_data->mesh_analysis_shgrp, "weightTex", G_draw.weight_ramp); if (rv3d->rflag & RV3D_CLIPPING) { DRW_shgroup_state_enable(g_data->mesh_analysis_shgrp, DRW_STATE_CLIP_PLANES); } @@ -704,17 +696,10 @@ static void EDIT_MESH_cache_populate(void *vedata, Object *ob) geom = DRW_cache_mesh_surface_weights_get(ob); DRW_shgroup_call_no_cull(g_data->fweights_shgrp, geom, ob); } - - if (do_show_mesh_analysis && !XRAY_ACTIVE(v3d)) { - Mesh *me = (Mesh *)ob->data; - BMEditMesh *embm = me->edit_mesh; - const bool is_original = embm->mesh_eval_final && - (embm->mesh_eval_final->runtime.is_original == true); - if (is_original) { - geom = DRW_cache_mesh_surface_mesh_analysis_get(ob); - if (geom) { - DRW_shgroup_call_no_cull(g_data->mesh_analysis_shgrp, geom, ob); - } + else if (do_show_mesh_analysis && !XRAY_ACTIVE(v3d)) { + geom = DRW_cache_mesh_surface_mesh_analysis_get(ob); + if (geom) { + DRW_shgroup_call_no_cull(g_data->mesh_analysis_shgrp, geom, ob); } } @@ -727,7 +712,7 @@ static void EDIT_MESH_cache_populate(void *vedata, Object *ob) } if (vnormals_do) { - geom = DRW_mesh_batch_cache_get_edit_vertices(ob->data); + geom = DRW_mesh_batch_cache_get_edit_vnors(ob->data); DRW_shgroup_call_no_cull(g_data->vnormals_shgrp, geom, ob); } if (lnormals_do) { diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_frag.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_frag.glsl index 8581453e810..8d96c0e418f 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_frag.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_frag.glsl @@ -1,12 +1,6 @@ out vec4 fragColor; -#ifdef FACE_COLOR -flat in vec4 weightColor; -#endif - -#ifdef VERTEX_COLOR in vec4 weightColor; -#endif void main() { diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl index 7065ce3df7c..b89a3f407f9 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl @@ -1,14 +1,25 @@ in vec3 pos; -in vec4 weight_color; +in float weight; -#ifdef FACE_COLOR -flat out vec4 weightColor; -#endif +uniform sampler1D weightTex; -#ifdef VERTEX_COLOR out vec4 weightColor; -#endif + +vec3 weight_to_rgb(float t) +{ + if (t < 0.0) { + /* Minimum color, grey */ + return vec3(0.25, 0.25, 0.25); + } + else if (t > 1.0) { + /* Error color */ + return vec3(1.0, 0.0, 1.0); + } + else { + return texture(weightTex, t).rgb; + } +} void main() { @@ -16,7 +27,7 @@ void main() vec3 world_pos = point_object_to_world(pos); gl_Position = point_world_to_ndc(world_pos); - weightColor = vec4(weight_color.rgb, 1.0); + weightColor = vec4(weight_to_rgb(weight), 1.0); #ifdef USE_WORLD_CLIP_PLANES world_clip_planes_calc_clip_distance(world_pos); |