From eba735d7854bfcdd20d35418135b378d40102c0e Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 7 Apr 2022 11:47:57 +0200 Subject: [PATCH] Port of the changes made with 5e0590a93e852c532fb0ff59a72463c318c119e0 and 0995cfc658dfbfdbc61fde451d32d06a9195b9a7 to OpenGL ES --- resources/shaders/ES/gouraud.fs | 7 ------- resources/shaders/ES/mm_contour.fs | 5 ----- resources/shaders/ES/mm_contour.vs | 5 ++++- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/resources/shaders/ES/gouraud.fs b/resources/shaders/ES/gouraud.fs index 2abcf9d232..9cd4f64832 100644 --- a/resources/shaders/ES/gouraud.fs +++ b/resources/shaders/ES/gouraud.fs @@ -29,8 +29,6 @@ struct SlopeDetection uniform vec4 uniform_color; uniform SlopeDetection slope; -uniform bool offset_depth_buffer; - #ifdef ENABLE_ENVIRONMENT_MAP uniform sampler2D environment_tex; uniform bool use_environment_tex; @@ -81,9 +79,4 @@ void main() else #endif gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); - - // In the support painting gizmo and the seam painting gizmo are painted triangles rendered over the already - // rendered object. To resolved z-fighting between previously rendered object and painted triangles, values - // inside the depth buffer are offset by small epsilon for painted triangles inside those gizmos. - gl_FragDepth = gl_FragCoord.z - (offset_depth_buffer ? EPSILON : 0.0); } diff --git a/resources/shaders/ES/mm_contour.fs b/resources/shaders/ES/mm_contour.fs index 51cbcc5b46..c5cea3b642 100644 --- a/resources/shaders/ES/mm_contour.fs +++ b/resources/shaders/ES/mm_contour.fs @@ -3,14 +3,9 @@ precision highp float; -const float EPSILON = 0.0001; - uniform vec4 uniform_color; void main() { gl_FragColor = uniform_color; - // Values inside depth buffer for fragments of the contour of a selected area are offset - // by small epsilon to solve z-fighting between painted triangles and contour lines. - gl_FragDepth = gl_FragCoord.z - EPSILON; } diff --git a/resources/shaders/ES/mm_contour.vs b/resources/shaders/ES/mm_contour.vs index a835872392..c84d186723 100644 --- a/resources/shaders/ES/mm_contour.vs +++ b/resources/shaders/ES/mm_contour.vs @@ -7,5 +7,8 @@ attribute vec3 v_position; void main() { - gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0); + // Add small epsilon to z to solve z-fighting between painted triangles and contour lines. + vec4 clip_position = projection_matrix * view_model_matrix * vec4(v_position, 1.0); + clip_position.z -= 0.00001 * abs(clip_position.w); + gl_Position = clip_position; }