Overlay Engine: Make thickwires (linesize > 1.0) using the Wire AA pass

This fixes the limitation of OSX not allowing glLineWidth with size > 1.0.
This however only fix the viewport wire drawing.
This commit is contained in:
2019-12-02 14:35:43 +01:00
parent 3e241af3ae
commit 014eb69cf8
4 changed files with 27 additions and 20 deletions

View File

@@ -80,8 +80,9 @@ void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
return;
}
bool need_wire_expansion = (G_draw.block.sizePixel > 1.0f);
/* TODO Get real userpref option and remove MSAA buffer. */
pd->antialiasing.enabled = dtxl->multisample_color != NULL;
pd->antialiasing.enabled = (dtxl->multisample_color != NULL) || need_wire_expansion;
/* Use default view */
pd->view_default = (DRWView *)DRW_view_default_get();
@@ -124,11 +125,15 @@ void OVERLAY_antialiasing_cache_init(OVERLAY_Data *vedata)
DRWShadingGroup *grp;
if (pd->antialiasing.enabled) {
/* TODO Get real userpref option and remove MSAA buffer. */
const bool do_smooth_lines = (dtxl->multisample_color != NULL);
DRW_PASS_CREATE(psl->antialiasing_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA_PREMUL);
sh = OVERLAY_shader_antialiasing();
grp = DRW_shgroup_create(sh, psl->antialiasing_ps);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_bool_copy(grp, "doSmoothLines", do_smooth_lines);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", &dtxl->depth);
DRW_shgroup_uniform_texture_ref(grp, "colorTex", &txl->overlay_color_tx);
DRW_shgroup_uniform_texture_ref(grp, "lineTex", &txl->overlay_line_tx);

View File

@@ -2,6 +2,7 @@
uniform sampler2D colorTex;
uniform sampler2D depthTex;
uniform sampler2D lineTex;
uniform bool doSmoothLines;
in vec2 uvs;
@@ -26,11 +27,23 @@ out vec4 fragColor;
*/
float line_coverage(float distance_to_line, float line_kernel_size)
{
return smoothstep(LINE_SMOOTH_END, LINE_SMOOTH_START, abs(distance_to_line) - line_kernel_size);
if (doSmoothLines) {
return smoothstep(
LINE_SMOOTH_END, LINE_SMOOTH_START, abs(distance_to_line) - line_kernel_size);
}
else {
return step(-0.5, line_kernel_size - abs(distance_to_line));
}
}
vec4 line_coverage(vec4 distance_to_line, float line_kernel_size)
{
return smoothstep(LINE_SMOOTH_END, LINE_SMOOTH_START, abs(distance_to_line) - line_kernel_size);
if (doSmoothLines) {
return smoothstep(
LINE_SMOOTH_END, LINE_SMOOTH_START, abs(distance_to_line) - line_kernel_size);
}
else {
return step(-0.5, line_kernel_size - abs(distance_to_line));
}
}
vec2 decode_line_dir(vec2 dir)
@@ -79,7 +92,7 @@ void neighbor_blend(
void main()
{
ivec2 center_texel = ivec2(gl_FragCoord.xy);
const float line_kernel = 0.0;
float line_kernel = sizePixel * 0.5 - 0.5;
fragColor = texelFetch(colorTex, center_texel, 0);

View File

@@ -350,7 +350,7 @@ typedef enum {
DRW_STATE_LOGIC_INVERT = (1 << 26),
DRW_STATE_SHADOW_OFFSET = (1 << 27),
DRW_STATE_CLIP_PLANES = (1 << 28),
DRW_STATE_WIRE_SMOOTH = (1 << 29),
// DRW_STATE_WIRE_SMOOTH = (1 << 29), /* UNUSED */
DRW_STATE_FIRST_VERTEX_CONVENTION = (1 << 30),
/** DO NOT USE. Assumed always enabled. Only used internally. */
DRW_STATE_PROGRAM_POINT_SIZE = (1u << 31),

View File

@@ -230,21 +230,6 @@ void drw_state_set(DRWState state)
}
}
/* Wire Width */
{
int test;
if ((test = CHANGED_TO(DRW_STATE_WIRE_SMOOTH))) {
if (test == 1) {
GPU_line_width(2.0f);
GPU_line_smooth(true);
}
else {
GPU_line_width(1.0f);
GPU_line_smooth(false);
}
}
}
/* Blending (all buffer) */
{
int test;
@@ -453,7 +438,11 @@ void DRW_state_reset(void)
{
DRW_state_reset_ex(DRW_STATE_DEFAULT);
/* Should stay constant during the whole rendering. */
GPU_point_size(5);
GPU_line_smooth(false);
/* Bypass U.pixelsize factor. */
glLineWidth(1.0f);
/* Reset blending function */
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);