TexturePaint: Missing Texture Depth Test

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
This commit is contained in:
Jeroen Bakker 2019-06-04 11:28:21 +02:00
parent 957c8f1305
commit eeda9369b6
5 changed files with 34 additions and 17 deletions

View 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)

View 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]);

View 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},

View File

@ -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
}
}

View 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
}
}
}