Commit: a9a37ac46c7c4ed0853b062852986affd766ed85 Author: Antonio Vazquez Date: Mon Aug 7 10:52:00 2017 +0200 Branches: greasepencil-object https://developer.blender.org/rBa9a37ac46c7c4ed0853b062852986affd766ed85
Fix problem of VFX double drawing The vfx pass needs a separate framebuffer to avoid double drawing of the strokes. If necessary, a full copy of the initial texture is done to be used by all vfx modifiers. =================================================================== M source/blender/draw/engines/gpencil/gpencil_engine.c M source/blender/draw/engines/gpencil/gpencil_engine.h M source/blender/draw/engines/gpencil/gpencil_vfx.c =================================================================== diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c index a6d22ee8446..9044549a702 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.c +++ b/source/blender/draw/engines/gpencil/gpencil_engine.c @@ -70,6 +70,16 @@ static void GPENCIL_engine_init(void *vedata) (int)viewport_size[0], (int)viewport_size[1], tex_color, ARRAY_SIZE(tex_color)); + /* vfx */ + DRWFboTexture vfx_color[2] = { { + &e_data.vfx_fbcolor_depth_tx, DRW_TEX_DEPTH_24, DRW_TEX_TEMP }, + { &e_data.vfx_fbcolor_color_tx, DRW_TEX_RGBA_16, DRW_TEX_TEMP } + }; + DRW_framebuffer_init( + &fbl->vfx_color_fb, &draw_engine_gpencil_type, + (int)viewport_size[0], (int)viewport_size[1], + vfx_color, ARRAY_SIZE(vfx_color)); + /* normal fill shader */ if (!e_data.gpencil_fill_sh) { e_data.gpencil_fill_sh = DRW_shader_create(datatoc_gpencil_fill_vert_glsl, NULL, @@ -222,13 +232,20 @@ static void GPENCIL_cache_init(void *vedata) /* we need a full screen pass to combine the result of zdepth */ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get(); - psl->mix_pass = DRW_pass_create("GPencil Mix Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); DRWShadingGroup *mix_shgrp = DRW_shgroup_create(e_data.gpencil_fullscreen_sh, psl->mix_pass); DRW_shgroup_call_add(mix_shgrp, quad, NULL); DRW_shgroup_uniform_buffer(mix_shgrp, "strokeColor", &e_data.temp_fbcolor_color_tx); DRW_shgroup_uniform_buffer(mix_shgrp, "strokeDepth", &e_data.temp_fbcolor_depth_tx); + /* mix vfx pass */ + struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get(); + psl->mix_vfx_pass = DRW_pass_create("GPencil Mix VFX Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); + DRWShadingGroup *mix_vfx_shgrp = DRW_shgroup_create(e_data.gpencil_fullscreen_sh, psl->mix_vfx_pass); + DRW_shgroup_call_add(mix_vfx_shgrp, vfxquad, NULL); + DRW_shgroup_uniform_buffer(mix_vfx_shgrp, "strokeColor", &e_data.vfx_fbcolor_color_tx); + DRW_shgroup_uniform_buffer(mix_vfx_shgrp, "strokeDepth", &e_data.vfx_fbcolor_depth_tx); + /* VFX pass */ psl->vfx_pass = DRW_pass_create("GPencil VFX Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); } @@ -284,8 +301,7 @@ static void GPENCIL_cache_finish(void *vedata) } /* VFX pass */ cache = &stl->g_data->gp_object_cache[i]; - DRW_gpencil_vfx_blur(i, &e_data, vedata, ob, cache); - DRW_gpencil_vfx_wave(i, &e_data, vedata, ob, cache); + DRW_gpencil_vfx_modifiers(i, &e_data, vedata, ob, cache); } } } @@ -316,6 +332,9 @@ static void GPENCIL_draw_scene(void *vedata) 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); + DRW_framebuffer_texture_attach(fbl->vfx_color_fb, e_data.vfx_fbcolor_depth_tx, 0, 0); + DRW_framebuffer_texture_attach(fbl->vfx_color_fb, e_data.vfx_fbcolor_color_tx, 0, 0); + /* Draw all pending objects */ if (stl->g_data->gp_cache_used > 0) { @@ -351,15 +370,23 @@ static void GPENCIL_draw_scene(void *vedata) /* vfx pass */ if ((cache->init_vfx_sh) && (cache->init_vfx_sh)) { + DRW_framebuffer_bind(fbl->vfx_color_fb); + DRW_framebuffer_clear(true, true, false, clearcol, 1.0f); + DRW_draw_pass_subset(psl->vfx_pass, cache->init_vfx_sh, cache->end_vfx_sh); + /* Combine with scene buffer */ + DRW_framebuffer_bind(dfbl->default_fb); + /* Mix VFX Pass */ + DRW_draw_pass(psl->mix_vfx_pass); + } + else { + /* Combine with scene buffer */ + DRW_framebuffer_bind(dfbl->default_fb); + /* Mix Pass: DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS */ + DRW_draw_pass(psl->mix_pass); } - /* Combine with scene buffer */ - DRW_framebuffer_bind(dfbl->default_fb); - - /* Mix Pass: DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS */ - DRW_draw_pass(psl->mix_pass); } /* edit points */ DRW_draw_pass(psl->edit_pass); @@ -379,6 +406,9 @@ static void GPENCIL_draw_scene(void *vedata) DRW_framebuffer_texture_detach(e_data.temp_fbcolor_depth_tx); DRW_framebuffer_texture_detach(e_data.temp_fbcolor_color_tx); + DRW_framebuffer_texture_detach(e_data.vfx_fbcolor_depth_tx); + DRW_framebuffer_texture_detach(e_data.vfx_fbcolor_color_tx); + /* attach again default framebuffer */ DRW_framebuffer_bind(dfbl->default_fb); } diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h index 1d84ce7ceb0..c22b32b447a 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.h +++ b/source/blender/draw/engines/gpencil/gpencil_engine.h @@ -108,12 +108,14 @@ typedef struct GPENCIL_PassList { struct DRWPass *edit_pass; struct DRWPass *drawing_pass; struct DRWPass *mix_pass; + struct DRWPass *mix_vfx_pass; struct DRWPass *vfx_pass; } GPENCIL_PassList; typedef struct GPENCIL_FramebufferList { struct GPUFrameBuffer *fb; struct GPUFrameBuffer *temp_color_fb; + struct GPUFrameBuffer *vfx_color_fb; } GPENCIL_FramebufferList; typedef struct GPENCIL_TextureList { @@ -157,6 +159,10 @@ typedef struct GPENCIL_e_data { /* temp depth texture */ struct GPUTexture *temp_fbcolor_depth_tx; struct GPUTexture *temp_fbcolor_color_tx; + + struct GPUTexture *vfx_fbcolor_depth_tx; + struct GPUTexture *vfx_fbcolor_color_tx; + struct GPUTexture *gpencil_blank_texture; } GPENCIL_e_data; /* Engine data */ @@ -212,7 +218,6 @@ void gpencil_object_cache_add(struct tGPencilObjectCache *cache, struct Object * void gpencil_array_modifiers(struct GPENCIL_StorageList *stl, struct Object *ob); -void DRW_gpencil_vfx_blur(int ob_idx, struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct Object *ob, struct tGPencilObjectCache *cache); -void DRW_gpencil_vfx_wave(int ob_idx, struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct Object *ob, struct tGPencilObjectCache *cache); +void DRW_gpencil_vfx_modifiers(int ob_idx, struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct Object *ob, struct tGPencilObjectCache *cache); #endif /* __GPENCIL_ENGINE_H__ */ diff --git a/source/blender/draw/engines/gpencil/gpencil_vfx.c b/source/blender/draw/engines/gpencil/gpencil_vfx.c index f0bc3c5c2bc..b974c5afb2d 100644 --- a/source/blender/draw/engines/gpencil/gpencil_vfx.c +++ b/source/blender/draw/engines/gpencil/gpencil_vfx.c @@ -37,7 +37,7 @@ /* verify if this modifier is available in the context, return NULL if not available */ static ModifierData *modifier_available(Object *ob, ModifierType type) { - ModifierData *md = modifiers_findByType(ob, type); + ModifierData *md = modifiers_findByType(ob, type); if (md == NULL) { return NULL; } @@ -48,70 +48,39 @@ static ModifierData *modifier_available(Object *ob, ModifierType type) } bool is_edit = (bool)((gpd->flag & (GP_DATA_STROKE_EDITMODE | GP_DATA_STROKE_SCULPTMODE | GP_DATA_STROKE_WEIGHTMODE))); - if ((md->mode & eModifierMode_Realtime) && (G.f & G_RENDER_OGL)) { - return NULL; - } - - if (((md->mode & eModifierMode_Render) == 0) && (G.f & G_RENDER_OGL)) { - return NULL; + if (((md->mode & eModifierMode_Realtime) && ((G.f & G_RENDER_OGL) == 0)) || + ((md->mode & eModifierMode_Render) && (G.f & G_RENDER_OGL)) || + ((md->mode & eModifierMode_Editmode) && (is_edit))) + { + return md; } - if ((md->mode & eModifierMode_Editmode) && (!is_edit)) { - return NULL; - } - - return md; + return NULL; } -/* Gaussian Blur VFX - * The effect is done using two shading groups because is faster to apply horizontal - * and vertical in different operations. - */ -void DRW_gpencil_vfx_blur(int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata, Object *ob, tGPencilObjectCache *cache) +/* Copy image as is to fill vfx texture */ +static void DRW_gpencil_vfx_copy(int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata, Object *ob, tGPencilObjectCache *cache) { - ModifierData *md = modifier_available(ob, eModifierType_GpencilBlur); - if (md == NULL) { - return; - } - - GpencilBlurModifierData *mmd = (GpencilBlurModifierData *)md; - - GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl; GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl; - const float *viewport_size = DRW_viewport_size_get(); - stl->vfx[ob_idx].vfx_blur.x = mmd->radius[0]; - stl->vfx[ob_idx].vfx_blur.y = mmd->radius[1] * (viewport_size[1] / viewport_size[0]); struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get(); - /* horizontal blur */ - DRWShadingGroup *vfx_shgrp = DRW_shgroup_create(e_data->gpencil_vfx_blur_sh, psl->vfx_pass); + DRWShadingGroup *vfx_shgrp = DRW_shgroup_create(e_data->gpencil_fullscreen_sh, psl->vfx_pass); DRW_shgroup_call_add(vfx_shgrp, vfxquad, NULL); DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeColor", &e_data->temp_fbcolor_color_tx); DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeDepth", &e_data->temp_fbcolor_depth_tx); - DRW_shgroup_uniform_vec2(vfx_shgrp, "dir", stl->storage->blur1, 1); - DRW_shgroup_uniform_float(vfx_shgrp, "blur", &stl->vfx[ob_idx].vfx_blur.x, 1); /* set first effect sh */ if (cache->init_vfx_sh == NULL) { cache->init_vfx_sh = vfx_shgrp; } - /* vertical blur */ - vfx_shgrp = DRW_shgroup_create(e_data->gpencil_vfx_blur_sh, psl->vfx_pass); - DRW_shgroup_call_add(vfx_shgrp, vfxquad, NULL); - DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeColor", &e_data->temp_fbcolor_color_tx); - DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeDepth", &e_data->temp_fbcolor_depth_tx); - DRW_shgroup_uniform_vec2(vfx_shgrp, "dir", stl->storage->blur2, 1); - DRW_shgroup_uniform_float(vfx_shgrp, "blur", &stl->vfx[ob_idx].vfx_blur.y, 1); - /* set last effect sh */ cache->end_vfx_sh = vfx_shgrp; } /* Wave Distorsion VFX */ -void DRW_gpencil_vfx_wave(int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata, Object *ob, tGPencilObjectCache *cache) +static void DRW_gpencil_vfx_wave(ModifierData *md, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata, Object *ob, tGPencilObjectCache *cach @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs