diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-12-01 21:49:31 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-12-01 22:38:52 +0300 |
commit | d55c269dd197288c30ca2881136330931bf05f98 (patch) | |
tree | 62ca84ecfa630e10154092a5157613caa069478e | |
parent | 6a80a786f88c7b09c451e3c585224a392c3cd95c (diff) |
UI: Simplify the area border drawing
Instead of doing a lot of alpha blended drawing with jittering, use the
fragment shader to do the masking using a circle mask.
This is much simpler and requires much less resources.
Hopefully this may solve the issue we have with the Intels UHD Graphics 620
on linux.
-rw-r--r-- | source/blender/editors/screen/screen_draw.c | 27 | ||||
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader.c | 3 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl | 16 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl | 31 |
5 files changed, 39 insertions, 39 deletions
diff --git a/source/blender/editors/screen/screen_draw.c b/source/blender/editors/screen/screen_draw.c index af6f9acfa47..51301b0f022 100644 --- a/source/blender/editors/screen/screen_draw.c +++ b/source/blender/editors/screen/screen_draw.c @@ -216,7 +216,7 @@ static void draw_join_shape(ScrArea *sa, char dir, unsigned int pos) } } -#define CORNER_RESOLUTION 9 +#define CORNER_RESOLUTION 3 static void do_vert_pair(GPUVertBuf *vbo, uint pos, uint *vidx, int corner, int i) { @@ -235,7 +235,7 @@ static void do_vert_pair(GPUVertBuf *vbo, uint pos, uint *vidx, int corner, int } /* Line width is 20% of the entire corner size. */ - const float line_width = 0.2f; + const float line_width = 0.2f; /* Keep in sync with shader */ mul_v2_fl(inter, 1.0f - line_width); mul_v2_fl(exter, 1.0f + line_width); @@ -271,15 +271,12 @@ static GPUBatch *batch_screen_edges_get(int *corner_len) uint pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format); - GPU_vertbuf_data_alloc(vbo, CORNER_RESOLUTION * 2 * 4 * 8 + 2); + GPU_vertbuf_data_alloc(vbo, CORNER_RESOLUTION * 2 * 4 + 2); uint vidx = 0; - /* Note jitter is applied in the shader. */ - for (int jit = 0; jit < 8; ++jit) { - for (int corner = 0; corner < 4; ++corner) { - for (int c = 0; c < CORNER_RESOLUTION; ++c) { - do_vert_pair(vbo, pos, &vidx, corner, c); - } + for (int corner = 0; corner < 4; ++corner) { + for (int c = 0; c < CORNER_RESOLUTION; ++c) { + do_vert_pair(vbo, pos, &vidx, corner, c); } } /* close the loop */ @@ -398,13 +395,12 @@ void ED_screen_draw_edges(wmWindow *win) glEnable(GL_SCISSOR_TEST); UI_GetThemeColor4fv(TH_EDITOR_OUTLINE, col); - col[3] = 1.0f / 8.0f; + col[3] = 1.0f; corner_scale = U.pixelsize * 8.0f; edge_thickness = corner_scale * 0.21f; GPU_blend(true); - /* Transparent pass (for AA). */ GPUBatch *batch = batch_screen_edges_get(&verts_per_corner); GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_AREA_EDGES); GPU_batch_uniform_1i(batch, "cornerLen", verts_per_corner); @@ -417,15 +413,6 @@ void ED_screen_draw_edges(wmWindow *win) GPU_blend(false); - /* Opaque pass. */ - corner_scale -= 2.0f; - edge_thickness = corner_scale * 0.2f; - GPU_batch_uniform_1f(batch, "scale", corner_scale); - - for (sa = screen->areabase.first; sa; sa = sa->next) { - drawscredge_area(sa, winsize_x, winsize_y, edge_thickness); - } - glDisable(GL_SCISSOR_TEST); } diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 2eb24f08227..02e5d4ac479 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -140,6 +140,7 @@ data_to_c_simple(shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_flat_id_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_area_borders_vert.glsl SRC) +data_to_c_simple(shaders/gpu_shader_2D_area_borders_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_widget_base_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_widget_base_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_widget_shadow_vert.glsl SRC) diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c index d428e2f9bd9..bae7520803d 100644 --- a/source/blender/gpu/intern/gpu_shader.c +++ b/source/blender/gpu/intern/gpu_shader.c @@ -68,6 +68,7 @@ extern char datatoc_gpu_shader_flat_color_frag_glsl[]; extern char datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl[]; extern char datatoc_gpu_shader_flat_id_frag_glsl[]; extern char datatoc_gpu_shader_2D_area_borders_vert_glsl[]; +extern char datatoc_gpu_shader_2D_area_borders_frag_glsl[]; extern char datatoc_gpu_shader_2D_vert_glsl[]; extern char datatoc_gpu_shader_2D_flat_color_vert_glsl[]; extern char datatoc_gpu_shader_2D_smooth_color_uniform_alpha_vert_glsl[]; @@ -900,7 +901,7 @@ static const GPUShaderStages builtin_shader_stages[GPU_NUM_BUILTIN_SHADERS] = { [GPU_SHADER_2D_AREA_EDGES] = { datatoc_gpu_shader_2D_area_borders_vert_glsl, - datatoc_gpu_shader_uniform_color_frag_glsl}, + datatoc_gpu_shader_2D_area_borders_frag_glsl}, [GPU_SHADER_2D_WIDGET_BASE] = { datatoc_gpu_shader_2D_widget_base_vert_glsl, datatoc_gpu_shader_2D_widget_base_frag_glsl}, diff --git a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl new file mode 100644 index 00000000000..620568db500 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_frag.glsl @@ -0,0 +1,16 @@ + +uniform vec4 color; +uniform float scale; + +in vec2 uv; + +out vec4 fragColor; + +void main() +{ + /* Should be 0.8 but minimize the AA on the edges. */ + float dist = (length(uv) - 0.78) * scale; + + fragColor = color; + fragColor.a *= smoothstep(-0.09, 1.09, dist); +} diff --git a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl index 5326076e269..816e12342a1 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_area_borders_vert.glsl @@ -7,35 +7,30 @@ uniform float scale; in vec2 pos; -const vec2 jitter_ofs[8] = vec2[8]( - vec2( 0.468813, -0.481430), vec2(-0.155755, -0.352820), - vec2( 0.219306, -0.238501), vec2(-0.393286, -0.110949), - vec2(-0.024699, 0.013908), vec2( 0.343805, 0.147431), - vec2(-0.272855, 0.269918), vec2( 0.095909, 0.388710) -); +out vec2 uv; + void main() { int corner_id = (gl_VertexID / cornerLen) % 4; - int jitter_id = gl_VertexID / (cornerLen * 4) % 8; vec2 final_pos = pos * scale; - if (corner_id == 0) + if (corner_id == 0) { + uv = pos + vec2(1.0, 1.0); final_pos += rect.yw; /* top right */ - else if (corner_id == 1) + } + else if (corner_id == 1) { + uv = pos + vec2(-1.0, 1.0); final_pos += rect.xw; /* top left */ - else if (corner_id == 2) + } + else if (corner_id == 2) { + uv = pos + vec2(-1.0, -1.0); final_pos += rect.xz; /* bottom left */ - else + } + else { + uv = pos + vec2(1.0, -1.0); final_pos += rect.yz; /* bottom right */ - - /* Only jitter verts inside the corner (not the one shared with the edges). */ - if ((gl_VertexID % cornerLen) % (cornerLen - 2) != 0) { - /* Only jitter intern verts not boundaries. */ - if ((gl_VertexID % 2) == 0) { - final_pos += jitter_ofs[jitter_id]; - } } gl_Position = (ModelViewProjectionMatrix * vec4(final_pos, 0.0, 1.0)); |