[Bf-blender-cvs] [c803ed9b806] greasepencil-object: Fix zdepth order with 3D objects
Antonio Vazquez
noreply at git.blender.org
Thu Oct 12 12:34:06 CEST 2017
Commit: c803ed9b8063288fb33938da2fe657943af0940f
Author: Antonio Vazquez
Date: Thu Oct 12 12:33:35 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBc803ed9b8063288fb33938da2fe657943af0940f
Fix zdepth order with 3D objects
When draw a new stroke, the stroke must be visible over all 3D objects and not in back of them.
A new mix pass has been created to make a mix with default framebuffer using a gl_FragDepth = 0.0 to force to be in front .
===================================================================
M source/blender/draw/CMakeLists.txt
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
A source/blender/draw/engines/gpencil/shaders/gpencil_front_depth_mix_frag.glsl
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index aec82ab8c5a..0454ce13b26 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -217,6 +217,7 @@ data_to_c_simple(engines/gpencil/shaders/gpencil_stroke_vert.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_stroke_geom.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_stroke_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/gpencil_front_depth_mix_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_point_vert.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_point_geom.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_point_frag.glsl SRC)
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 12a6bc217b1..ed7f2db6c50 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -46,6 +46,7 @@ extern char datatoc_gpencil_stroke_vert_glsl[];
extern char datatoc_gpencil_stroke_geom_glsl[];
extern char datatoc_gpencil_stroke_frag_glsl[];
extern char datatoc_gpencil_zdepth_mix_frag_glsl[];
+extern char datatoc_gpencil_front_depth_mix_frag_glsl[];
extern char datatoc_gpencil_point_vert_glsl[];
extern char datatoc_gpencil_point_geom_glsl[];
extern char datatoc_gpencil_point_frag_glsl[];
@@ -168,6 +169,7 @@ static void GPENCIL_engine_free(void)
DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_pixel_sh);
DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_swirl_sh);
DRW_SHADER_FREE_SAFE(e_data.gpencil_painting_sh);
+ DRW_SHADER_FREE_SAFE(e_data.gpencil_front_depth_sh);
DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture);
}
@@ -230,6 +232,9 @@ static void GPENCIL_cache_init(void *vedata)
if (!e_data.gpencil_painting_sh) {
e_data.gpencil_painting_sh = DRW_shader_create_fullscreen(datatoc_gpencil_painting_frag_glsl, NULL);
}
+ if (!e_data.gpencil_front_depth_sh) {
+ e_data.gpencil_front_depth_sh = DRW_shader_create_fullscreen(datatoc_gpencil_front_depth_mix_frag_glsl, NULL);
+ }
{
/* Stroke pass */
@@ -358,11 +363,18 @@ static void GPENCIL_cache_init(void *vedata)
/* Painting session pass (used only to speedup while the user is drawing ) */
struct Gwn_Batch *paintquad = DRW_cache_fullscreen_quad_get();
- psl->painting_pass = DRW_pass_create("GPencil Painting Session Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+ psl->painting_pass = DRW_pass_create("GPencil Painting Session Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
DRWShadingGroup *painting_shgrp = DRW_shgroup_create(e_data.gpencil_painting_sh, psl->painting_pass);
DRW_shgroup_call_add(painting_shgrp, paintquad, NULL);
DRW_shgroup_uniform_buffer(painting_shgrp, "strokeColor", &e_data.painting_color_tx);
DRW_shgroup_uniform_buffer(painting_shgrp, "strokeDepth", &e_data.painting_depth_tx);
+
+ /* pass for current stroke drawing in front of all */
+ struct Gwn_Batch *frontquad = DRW_cache_fullscreen_quad_get();
+ psl->mix_pass_front = DRW_pass_create("GPencil Mix Front Depth Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+ DRWShadingGroup *mix_front_shgrp = DRW_shgroup_create(e_data.gpencil_front_depth_sh, psl->mix_pass_front);
+ DRW_shgroup_call_add(mix_front_shgrp, frontquad, NULL);
+ DRW_shgroup_uniform_buffer(mix_front_shgrp, "strokeColor", &e_data.temp_fbcolor_color_tx);
}
}
@@ -587,14 +599,15 @@ static void GPENCIL_draw_scene(void *vedata)
/* if we have a painting session, we use fast viewport drawing method */
if (stl->g_data->session_flag & GP_DRW_PAINT_PAINTING) {
+ DRW_framebuffer_bind(dfbl->default_fb);
+ DRW_draw_pass(psl->painting_pass);
+
+ /* Current stroke must pass through the temp framebuffer to get same alpha values in blend */
DRW_framebuffer_texture_attach(fbl->temp_color_fb, e_data.temp_fbcolor_depth_tx, 0, 0);
DRW_framebuffer_texture_attach(fbl->temp_color_fb, e_data.temp_fbcolor_color_tx, 0, 0);
- /* It must pass through the temp framebuffer to get same alpha values in blend */
DRW_framebuffer_bind(fbl->temp_color_fb);
DRW_framebuffer_clear(true, true, false, clearcol, 1.0f);
- DRW_draw_pass(psl->painting_pass);
-
MULTISAMPLE_GP_SYNC_ENABLE(dfbl, fbl);
DRW_draw_pass(psl->drawing_pass);
@@ -603,7 +616,7 @@ static void GPENCIL_draw_scene(void *vedata)
/* send to default framebuffer */
DRW_framebuffer_bind(dfbl->default_fb);
- DRW_draw_pass(psl->mix_pass);
+ DRW_draw_pass(psl->mix_pass_front);
DRW_framebuffer_texture_detach(e_data.temp_fbcolor_depth_tx);
DRW_framebuffer_texture_detach(e_data.temp_fbcolor_color_tx);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index bf0a3e1eca9..0c078a7e51e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -170,6 +170,7 @@ typedef struct GPENCIL_PassList {
struct DRWPass *mix_vfx_pass;
struct DRWPass *mix_pass_noblend;
struct DRWPass *mix_vfx_pass_noblend;
+ struct DRWPass *mix_pass_front;
struct DRWPass *vfx_copy_pass;
struct DRWPass *vfx_wave_pass;
struct DRWPass *vfx_blur_pass_1;
@@ -240,6 +241,7 @@ typedef struct GPENCIL_e_data {
struct GPUShader *gpencil_vfx_pixel_sh;
struct GPUShader *gpencil_vfx_swirl_sh;
struct GPUShader *gpencil_painting_sh;
+ struct GPUShader *gpencil_front_depth_sh;
/* temp depth texture */
struct GPUTexture *temp_fbcolor_depth_tx;
struct GPUTexture *temp_fbcolor_color_tx;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_front_depth_mix_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_front_depth_mix_frag.glsl
new file mode 100644
index 00000000000..caf49b9e450
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_front_depth_mix_frag.glsl
@@ -0,0 +1,14 @@
+in vec4 uvcoordsvar;
+
+out vec4 FragColor;
+
+uniform sampler2D strokeColor;
+
+void main()
+{
+ ivec2 uv = ivec2(gl_FragCoord.xy);
+ vec4 stroke_color = texelFetch(strokeColor, uv, 0).rgba;
+
+ FragColor = stroke_color;
+ gl_FragDepth = 0.0; /* always on front */
+}
More information about the Bf-blender-cvs
mailing list