diff options
3 files changed, 24 insertions, 9 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c index bf58f763746..3f702a00bcd 100644 --- a/source/blender/draw/engines/overlay/overlay_shader.c +++ b/source/blender/draw/engines/overlay/overlay_shader.c @@ -1215,7 +1215,7 @@ GPUShader *OVERLAY_shader_wireframe_select(void) datatoc_gpu_shader_common_obinfos_lib_glsl, datatoc_wireframe_vert_glsl, NULL}, - .frag = (const char *[]){datatoc_gpu_shader_depth_only_frag_glsl, NULL}, + .frag = (const char *[]){datatoc_wireframe_frag_glsl, NULL}, .defs = (const char *[]){sh_cfg->def, "#define SELECT_EDGES\n", NULL}, }); } diff --git a/source/blender/draw/engines/overlay/shaders/wireframe_frag.glsl b/source/blender/draw/engines/overlay/shaders/wireframe_frag.glsl index 0c6a3a651b9..edfe720da0c 100644 --- a/source/blender/draw/engines/overlay/shaders/wireframe_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/wireframe_frag.glsl @@ -1,14 +1,25 @@ -in vec3 finalColor; flat in vec2 edgeStart; + +#ifndef SELECT_EDGES +in vec3 finalColor; noperspective in vec2 edgePos; layout(location = 0) out vec4 fragColor; layout(location = 1) out vec4 lineOutput; +#endif void main() { + /* Needed only because of wireframe slider. + * If we could get rid of it would be nice because of performance drain of discard. */ + if (edgeStart.r == -1.0) { + discard; + } + +#ifndef SELECT_EDGES lineOutput = pack_line_data(gl_FragCoord.xy, edgeStart, edgePos); fragColor.rgb = finalColor; fragColor.a = 1.0; +#endif } diff --git a/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl b/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl index c627e912d6c..16fdf2687fa 100644 --- a/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl @@ -9,9 +9,10 @@ in vec3 pos; in vec3 nor; in float wd; /* wiredata */ +flat out vec2 edgeStart; + #ifndef SELECT_EDGES out vec3 finalColor; -flat out vec2 edgeStart; noperspective out vec2 edgePos; #endif @@ -103,14 +104,12 @@ void main() vec3 wpos = point_object_to_world(pos); gl_Position = point_world_to_ndc(wpos); - if (get_edge_sharpness(wd) < 0.0) { - /* Discard primitive by placing any of the verts at the camera origin. */ - gl_Position = vec4(0.0, 0.0, -3e36, 0.0); - } -#ifndef SELECT_EDGES /* Convert to screen position [0..sizeVp]. */ - edgePos = edgeStart = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy; + edgeStart = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy; + +#ifndef SELECT_EDGES + edgePos = edgeStart; vec3 rim_col, wire_col; if (isObjectColor || isRandomColor) { @@ -129,6 +128,11 @@ void main() finalColor = mix(final_rim_col, final_front_col, facing); #endif + /* Cull flat edges below threshold. */ + if (get_edge_sharpness(wd) < 0.0) { + edgeStart = vec2(-1.0); + } + #ifdef USE_WORLD_CLIP_PLANES world_clip_planes_calc_clip_distance(wpos); #endif |