TexturePaint: Missing Texture Depth Test
authorJeroen Bakker <j.bakker@atmind.nl>
Tue, 4 Jun 2019 09:28:21 +0000 (11:28 +0200)
committerJeroen Bakker <j.bakker@atmind.nl>
Wed, 5 Jun 2019 12:29:27 +0000 (14:29 +0200)
Depth testing was off as it used the precomputed ModelView matrix. As
draw engines currently use a different approach the depth was sometimes
a bit off making the color disappear.

This change will use a different vertex shader that will write the
correct depth. I expected the same change to be needed in the bone
selection overlay but was not able to reproduce it.

Reviewed By: fclem

Maniphest Tasks: T64615

Differential Revision: https://developer.blender.org/D5006

source/blender/draw/CMakeLists.txt
source/blender/draw/modes/paint_texture_mode.c
source/blender/draw/modes/paint_vertex_mode.c
source/blender/draw/modes/shaders/paint_face_selection_vert.glsl [new file with mode: 0644]
source/blender/draw/modes/shaders/paint_face_vert.glsl

index ade1ec5..44551a4 100644 (file)
@@ -318,6 +318,7 @@ data_to_c_simple(modes/shaders/paint_vertex_frag.glsl SRC)
 data_to_c_simple(modes/shaders/paint_vertex_vert.glsl SRC)
 data_to_c_simple(modes/shaders/paint_weight_frag.glsl SRC)
 data_to_c_simple(modes/shaders/paint_weight_vert.glsl SRC)
+data_to_c_simple(modes/shaders/paint_face_selection_vert.glsl SRC)
 data_to_c_simple(modes/shaders/paint_face_vert.glsl SRC)
 data_to_c_simple(modes/shaders/paint_wire_frag.glsl SRC)
 data_to_c_simple(modes/shaders/paint_wire_vert.glsl SRC)
index 66e2cf7..a31efcc 100644 (file)
@@ -47,6 +47,7 @@ extern char datatoc_paint_texture_frag_glsl[];
 extern char datatoc_paint_wire_vert_glsl[];
 extern char datatoc_paint_wire_frag_glsl[];
 extern char datatoc_paint_face_vert_glsl[];
+extern char datatoc_paint_face_selection_vert_glsl[];
 
 extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
 
@@ -144,8 +145,14 @@ static void PAINT_TEXTURE_engine_init(void *vedata)
 
   if (!sh_data->fallback) {
     const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
-    sh_data->fallback = GPU_shader_get_builtin_shader_with_config(GPU_SHADER_3D_UNIFORM_COLOR,
-                                                                  draw_ctx->sh_cfg);
+    sh_data->fallback = GPU_shader_create_from_arrays({
+        .vert = (const char *[]){sh_cfg_data->lib,
+                                 datatoc_common_view_lib_glsl,
+                                 datatoc_paint_face_vert_glsl,
+                                 NULL},
+        .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
+        .defs = (const char *[]){sh_cfg_data->def, NULL},
+    });
 
     sh_data->image = GPU_shader_create_from_arrays({
         .vert = (const char *[]){sh_cfg_data->lib,
@@ -180,7 +187,7 @@ static void PAINT_TEXTURE_engine_init(void *vedata)
     sh_data->face_select_overlay = GPU_shader_create_from_arrays({
         .vert = (const char *[]){sh_cfg_data->lib,
                                  datatoc_common_view_lib_glsl,
-                                 datatoc_paint_face_vert_glsl,
+                                 datatoc_paint_face_selection_vert_glsl,
                                  NULL},
         .frag = (const char *[]){datatoc_common_view_lib_glsl,
                                  datatoc_gpu_shader_uniform_color_frag_glsl,
@@ -433,8 +440,6 @@ static void PAINT_TEXTURE_engine_free(void)
 {
   for (int sh_data_index = 0; sh_data_index < ARRAY_SIZE(e_data.sh_data); sh_data_index++) {
     PAINT_TEXTURE_Shaders *sh_data = &e_data.sh_data[sh_data_index];
-    /* Don't free builtins. */
-    sh_data->fallback = NULL;
     GPUShader **sh_data_as_array = (GPUShader **)sh_data;
     for (int i = 0; i < (sizeof(PAINT_TEXTURE_Shaders) / sizeof(GPUShader *)); i++) {
       DRW_SHADER_FREE_SAFE(sh_data_as_array[i]);
index b4438b7..862fb92 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "DEG_depsgraph_query.h"
 
-extern char datatoc_paint_face_vert_glsl[];
+extern char datatoc_paint_face_selection_vert_glsl[];
 extern char datatoc_paint_weight_vert_glsl[];
 extern char datatoc_paint_weight_frag_glsl[];
 extern char datatoc_paint_vertex_vert_glsl[];
@@ -137,7 +137,7 @@ static void PAINT_VERTEX_engine_init(void *vedata)
     sh_data->face_select_overlay = GPU_shader_create_from_arrays({
         .vert = (const char *[]){sh_cfg_data->lib,
                                  datatoc_common_view_lib_glsl,
-                                 datatoc_paint_face_vert_glsl,
+                                 datatoc_paint_face_selection_vert_glsl,
                                  NULL},
         .frag = (const char *[]){datatoc_gpu_shader_uniform_color_frag_glsl, NULL},
         .defs = (const char *[]){sh_cfg_data->def, NULL},
diff --git a/source/blender/draw/modes/shaders/paint_face_selection_vert.glsl b/source/blender/draw/modes/shaders/paint_face_selection_vert.glsl
new file mode 100644 (file)
index 0000000..4b5191e
--- /dev/null
@@ -0,0 +1,19 @@
+
+in vec3 pos;
+in vec4 nor; /* select flag on the 4th component */
+
+void main()
+{
+  vec3 world_pos = point_object_to_world(pos);
+  gl_Position = point_world_to_ndc(world_pos);
+
+  /* Don't draw faces that are selected. */
+  if (nor.w > 0.0) {
+    gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
+  }
+  else {
+#ifdef USE_WORLD_CLIP_PLANES
+    world_clip_planes_calc_clip_distance(world_pos);
+#endif
+  }
+}
index 4b5191e..d135071 100644 (file)
@@ -1,19 +1,11 @@
-
 in vec3 pos;
-in vec4 nor; /* select flag on the 4th component */
 
 void main()
 {
   vec3 world_pos = point_object_to_world(pos);
   gl_Position = point_world_to_ndc(world_pos);
 
-  /* Don't draw faces that are selected. */
-  if (nor.w > 0.0) {
-    gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
-  }
-  else {
 #ifdef USE_WORLD_CLIP_PLANES
-    world_clip_planes_calc_clip_distance(world_pos);
+  world_clip_planes_calc_clip_distance(world_pos);
 #endif
-  }
-}
+}
\ No newline at end of file