[Bf-blender-cvs] [049eb49f9aa] greasepencil-object: Enable MSAA for strokes

Antonio Vazquez noreply at git.blender.org
Mon Oct 9 16:19:41 CEST 2017


Commit: 049eb49f9aaaf02c67197cfcef8ddba0340dcb99
Author: Antonio Vazquez
Date:   Mon Oct 9 16:19:17 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB049eb49f9aaaf02c67197cfcef8ddba0340dcb99

Enable MSAA for strokes

This AA is activated with Multisample parameter of user preferences screen.

===================================================================

M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl

===================================================================

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 9a42c624a94..35c47d0bf89 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -54,8 +54,6 @@ extern char datatoc_gpencil_wave_frag_glsl[];
 extern char datatoc_gpencil_pixel_frag_glsl[];
 extern char datatoc_gpencil_swirl_frag_glsl[];
 extern char datatoc_gpencil_painting_frag_glsl[];
-extern char datatoc_common_fxaa_lib_glsl[];
-extern char datatoc_gpu_shader_fullscreen_vert_glsl[];
 
 /* *********** STATIC *********** */
 static GPENCIL_e_data e_data = {NULL}; /* Engine data */
@@ -215,12 +213,7 @@ static void GPENCIL_cache_init(void *vedata)
 
 	/* full screen for mix zdepth*/
 	if (!e_data.gpencil_fullscreen_sh) {
-		e_data.gpencil_fullscreen_sh = DRW_shader_create_with_lib(
-			datatoc_gpu_shader_fullscreen_vert_glsl, NULL,
-			datatoc_gpencil_zdepth_mix_frag_glsl,
-			datatoc_common_fxaa_lib_glsl,
-			"#define FXAA_ALPHA\n"
-			"#define USE_FXAA\n");
+		e_data.gpencil_fullscreen_sh = DRW_shader_create_fullscreen(datatoc_gpencil_zdepth_mix_frag_glsl, NULL);
 	}
 	if (!e_data.gpencil_vfx_blur_sh) {
 		e_data.gpencil_vfx_blur_sh = DRW_shader_create_fullscreen(datatoc_gpencil_gaussian_blur_frag_glsl, NULL);
@@ -312,16 +305,12 @@ static void GPENCIL_cache_init(void *vedata)
 		}
 
 		/* we need a full screen pass to combine the result of zdepth */
-		copy_v2_v2(e_data.inv_viewport_size, DRW_viewport_size_get());
-		invert_v2(e_data.inv_viewport_size);
-
 		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);
-		DRW_shgroup_uniform_vec2(mix_shgrp, "rcpDimensions", e_data.inv_viewport_size, 1);
 
 		/* mix vfx pass */
 		struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get();
@@ -330,7 +319,6 @@ static void GPENCIL_cache_init(void *vedata)
 		DRW_shgroup_call_add(mix_vfx_shgrp, vfxquad, NULL);
 		DRW_shgroup_uniform_buffer(mix_vfx_shgrp, "strokeColor", &e_data.vfx_fbcolor_color_tx_a);
 		DRW_shgroup_uniform_buffer(mix_vfx_shgrp, "strokeDepth", &e_data.vfx_fbcolor_depth_tx_a);
-		DRW_shgroup_uniform_vec2(mix_vfx_shgrp, "rcpDimensions", e_data.inv_viewport_size, 1);
 
 		/* mix pass no blend */
 		struct Gwn_Batch *quad_noblend = DRW_cache_fullscreen_quad_get();
@@ -601,7 +589,9 @@ static void GPENCIL_draw_scene(void *vedata)
 	if (stl->g_data->session_flag & GP_DRW_PAINT_PAINTING) {
 		DRW_framebuffer_bind(dfbl->default_fb);
 		DRW_draw_pass(psl->painting_pass);
+		MULTISAMPLE_SYNC_ENABLE(dfbl);
 		DRW_draw_pass(psl->drawing_pass);
+		MULTISAMPLE_SYNC_DISABLE(dfbl);
 		/* free memory */
 		gpencil_free_obj_list(stl);
 		return;
@@ -645,9 +635,21 @@ static void GPENCIL_draw_scene(void *vedata)
 				}
 
 				if (end_grp >= init_grp) {
+					if (dfbl->multisample_fb != NULL) {
+						DRW_framebuffer_blit(fbl->temp_color_fb, dfbl->multisample_fb, false);
+						DRW_framebuffer_blit(fbl->temp_color_fb, dfbl->multisample_fb, true);
+						DRW_framebuffer_bind(dfbl->multisample_fb);
+					}
+
 					DRW_draw_pass_subset(psl->stroke_pass,
 						stl->shgroups[init_grp].shgrps_fill != NULL ? stl->shgroups[init_grp].shgrps_fill : stl->shgroups[init_grp].shgrps_stroke,
 						stl->shgroups[end_grp].shgrps_stroke);
+
+					if (dfbl->multisample_fb != NULL) {
+						DRW_framebuffer_blit(dfbl->multisample_fb, fbl->temp_color_fb, false);
+						DRW_framebuffer_blit(dfbl->multisample_fb, fbl->temp_color_fb, true);
+						DRW_framebuffer_bind(fbl->temp_color_fb);
+					}
 				}
 				/* Current buffer drawing */
 				if (ob->gpd->sbuffer_size > 0) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 75fb28c984c..d02a26c60cc 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -232,8 +232,6 @@ typedef struct GPENCIL_e_data {
 	struct GPUTexture *painting_color_tx;
 
 	struct GPUTexture *gpencil_blank_texture;
-
-	float inv_viewport_size[2];
 } GPENCIL_e_data; /* Engine data */
 
 /* Gwn_Batch Cache */
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
index ff1ac779ec7..4f6075d3bbf 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
@@ -4,26 +4,13 @@ out vec4 FragColor;
 
 uniform sampler2D strokeColor;
 uniform sampler2D strokeDepth;
-uniform vec2 rcpDimensions;
 
 void main()
 {
-    float aa_alpha = FxaaPixelShader(
-        uvcoordsvar.st,
-        strokeColor,
-        rcpDimensions,
-        1.0,
-        0.166,
-        0.0833
-    ).r;
-
 	ivec2 uv = ivec2(gl_FragCoord.xy);
 	float stroke_depth = texelFetch(strokeDepth, uv, 0).r;
 	vec4 stroke_color =  texelFetch(strokeColor, uv, 0).rgba;
 
 	FragColor = stroke_color;
-    //FragColor.a = aa_alpha;
-	// Test
-    //FragColor.r = aa_alpha;
 	gl_FragDepth = stroke_depth;
 }



More information about the Bf-blender-cvs mailing list