From e000dcb8490880d6d49aa91588c457612685e9f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Thu, 26 Mar 2020 15:36:15 +0100 Subject: Overlay: Wireframe: New method to avoid zfighting with geometry This new method is only enabled if Overlay Smooth Wire is enabled. This method gives really nice results but has some downside: - Require a depth copy or loose the ability to write wire depth to the depth buffer and have correct depth ordering of wires. This patch use the former, with its associated cost. - Require some depth sampling and prevent early depth test (i.e: has some performance impact). - Has some relatively minor instability with geometry that are perpendicular to the view and intersecting with other geometry. Pros: - Compared to a fullpass approach this is surely going to have less performance impact and much higher quality. - Removes the additional vertex offset. (see T74961) - Fixes all half edges z-fighting. {F8428014} {F8428015} Reviewed By: brecht Differential Revision: https://developer.blender.org/D7233 --- source/blender/draw/engines/overlay/overlay_shader.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'source/blender/draw/engines/overlay/overlay_shader.c') diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c index 0b2f98294ec..8b70a0982af 100644 --- a/source/blender/draw/engines/overlay/overlay_shader.c +++ b/source/blender/draw/engines/overlay/overlay_shader.c @@ -192,7 +192,7 @@ typedef struct OVERLAY_Shaders { GPUShader *volume_velocity_needle_sh; GPUShader *volume_velocity_sh; GPUShader *wireframe_select; - GPUShader *wireframe; + GPUShader *wireframe[2]; GPUShader *xray_fade; } OVERLAY_Shaders; @@ -1372,24 +1372,29 @@ GPUShader *OVERLAY_shader_wireframe_select(void) return sh_data->wireframe_select; } -GPUShader *OVERLAY_shader_wireframe(void) +GPUShader *OVERLAY_shader_wireframe(bool custom_bias) { const DRWContextState *draw_ctx = DRW_context_state_get(); const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg]; OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; - if (!sh_data->wireframe) { - sh_data->wireframe = GPU_shader_create_from_arrays({ + if (!sh_data->wireframe[custom_bias]) { + sh_data->wireframe[custom_bias] = GPU_shader_create_from_arrays({ .vert = (const char *[]){sh_cfg->lib, datatoc_common_view_lib_glsl, datatoc_common_globals_lib_glsl, datatoc_gpu_shader_common_obinfos_lib_glsl, datatoc_wireframe_vert_glsl, NULL}, - .frag = (const char *[]){datatoc_common_view_lib_glsl, datatoc_wireframe_frag_glsl, NULL}, - .defs = (const char *[]){sh_cfg->def, NULL}, + .frag = (const char *[]){datatoc_common_view_lib_glsl, + datatoc_common_globals_lib_glsl, + datatoc_wireframe_frag_glsl, + NULL}, + .defs = (const char *[]){sh_cfg->def, + custom_bias ? "#define CUSTOM_DEPTH_BIAS\n" : NULL, + NULL}, }); } - return sh_data->wireframe; + return sh_data->wireframe[custom_bias]; } GPUShader *OVERLAY_shader_xray_fade(void) -- cgit v1.2.3