[Bf-blender-cvs] [71bac9a99f7] greasepencil-object: WIP: Fix alpha channel and replace by weights

Antonio Vazquez noreply at git.blender.org
Thu Mar 29 17:58:24 CEST 2018


Commit: 71bac9a99f72af613ee53093047b48bea5e5f02a
Author: Antonio Vazquez
Date:   Thu Mar 29 10:23:25 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB71bac9a99f72af613ee53093047b48bea5e5f02a

WIP: Fix alpha channel and replace by weights

Still there is a problem with the external border.

Thanks Clément for the help.

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

M	source/blender/draw/engines/gpencil/gpencil_depth_of_field.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_depth_of_field.c b/source/blender/draw/engines/gpencil/gpencil_depth_of_field.c
index 7f42e697679..478d03241a7 100644
--- a/source/blender/draw/engines/gpencil/gpencil_depth_of_field.c
+++ b/source/blender/draw/engines/gpencil/gpencil_depth_of_field.c
@@ -79,21 +79,20 @@ int GPENCIL_depth_of_field_init(DrawEngineType *draw_engine_gpencil_type, GPENCI
 		int buffer_size[2] = { (int)viewport_size[0] / 2, (int)viewport_size[1] / 2 };
 
 		/* Setup buffers */
-		e_data->gpencil_dof_down_near = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGB_11_11_10,
+		e_data->gpencil_dof_down_near = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGBA_16,
 														   draw_engine_gpencil_type);
-		e_data->gpencil_dof_down_far = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGB_11_11_10,
+		e_data->gpencil_dof_down_far = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGBA_16,
 														   draw_engine_gpencil_type);
 		e_data->gpencil_dof_coc = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RG_16,
 														   draw_engine_gpencil_type);
-		e_data->gpencil_dof_alpha = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_R_16,
+		e_data->gpencil_dof_weight = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_R_16,
 														   draw_engine_gpencil_type);
 
 		GPU_framebuffer_ensure_config(&fbl->dof_down_fb, {
 			GPU_ATTACHMENT_NONE,
 			GPU_ATTACHMENT_TEXTURE(e_data->gpencil_dof_down_near),
 			GPU_ATTACHMENT_TEXTURE(e_data->gpencil_dof_down_far),
-			GPU_ATTACHMENT_TEXTURE(e_data->gpencil_dof_coc),
-			GPU_ATTACHMENT_TEXTURE(e_data->gpencil_dof_alpha)
+			GPU_ATTACHMENT_TEXTURE(e_data->gpencil_dof_coc)
 		});
 			
 		/* Go full 32bits for rendering and reduce the color artifacts. */
@@ -104,6 +103,7 @@ int GPENCIL_depth_of_field_init(DrawEngineType *draw_engine_gpencil_type, GPENCI
 		GPU_framebuffer_ensure_config(&fbl->dof_scatter_far_fb, {
 			GPU_ATTACHMENT_NONE,
 			GPU_ATTACHMENT_TEXTURE(e_data->gpencil_dof_far_blur),
+			GPU_ATTACHMENT_TEXTURE(e_data->gpencil_dof_weight)
 		});
 
 		e_data->gpencil_dof_near_blur = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], fb_format,
@@ -111,7 +111,8 @@ int GPENCIL_depth_of_field_init(DrawEngineType *draw_engine_gpencil_type, GPENCI
 		GPU_framebuffer_ensure_config(&fbl->dof_scatter_near_fb, {
 			GPU_ATTACHMENT_NONE,
 			GPU_ATTACHMENT_TEXTURE(e_data->gpencil_dof_near_blur),
-			});
+			GPU_ATTACHMENT_TEXTURE(e_data->gpencil_dof_weight)
+		});
 
 		/* Parameters */
 		/* TODO UI Options */
@@ -202,7 +203,7 @@ void GPENCIL_depth_of_field_cache_init(GPENCIL_e_data *e_data, GPENCIL_Data *ved
 		DRW_shgroup_uniform_texture_ref(grp, "nearBuffer", &e_data->gpencil_dof_near_blur);
 		DRW_shgroup_uniform_texture_ref(grp, "farBuffer", &e_data->gpencil_dof_far_blur);
 		DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &e_data->input_depth_tx);
-		DRW_shgroup_uniform_texture_ref(grp, "alphaBuffer", &e_data->gpencil_dof_alpha);
+		DRW_shgroup_uniform_texture_ref(grp, "weightBuffer", &e_data->gpencil_dof_weight);
 		DRW_shgroup_uniform_vec2(grp, "nearFar", stl->storage->dof_near_far, 1);
 		DRW_shgroup_uniform_vec3(grp, "dofParams", stl->storage->dof_params, 1);
 		DRW_shgroup_call_add(grp, quad, NULL);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index eea00cbfa6c..4881392ba97 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -333,7 +333,7 @@ typedef struct GPENCIL_e_data {
 	struct GPUTexture *gpencil_dof_coc; /* R16_G16 */
 	struct GPUTexture *gpencil_dof_near_blur; /* R16_G16_B16_A16 */
 	struct GPUTexture *gpencil_dof_far_blur; /* R16_G16_B16_A16 */
-	struct GPUTexture *gpencil_dof_alpha; 
+	struct GPUTexture *gpencil_dof_weight; 
 
 } GPENCIL_e_data; /* Engine data */
 
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl
index ed5b3db3455..e5c9a810023 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl
@@ -178,7 +178,7 @@ void step_scatter(void)
 
 uniform sampler2D farBuffer;
 uniform sampler2D nearBuffer;
-uniform sampler2D alphaBuffer;
+uniform sampler2D weightBuffer;
 
 vec4 upsample_filter_high(sampler2D tex, vec2 uv, vec2 texelSize)
 {
@@ -220,7 +220,7 @@ void step_resolve(void)
 {
 	/* Recompute Near / Far CoC */
 	float depth = textureLod(depthBuffer, uvcoord, 0.0).r;
-	float alpha = textureLod(alphaBuffer, uvcoord, 0.0).r;
+	float alpha = textureLod(weightBuffer, uvcoord, 0.0).r;
 
 	float zdepth = linear_depth(depth);
 	float coc_signed = calculate_coc(zdepth);
@@ -256,9 +256,6 @@ void step_resolve(void)
 		fragData0 = mix(finalcolor, nearcolor, nearweight / totalweight);
 	}
 	
-	/* apply alpha TODO */
-	fragData0.a = alpha;
-	
 	gl_FragDepth = depth;
 }
 
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl
index 656f937815c..aec36b19534 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl
@@ -41,14 +41,12 @@ void step_scatter()
 	if (coc >= 1.0) {
 		color = texelFetch(colorBuffer, texelco, 0);
 		/* find the area the pixel will cover and divide the color by it */
-		float alpha = 1.0 / (coc * coc * M_PI);
-		weight = alpha;
-		color *= alpha;
-		color.a = alpha;
+		weight = 1.0 / (coc * coc * M_PI);
+		color *= weight; /* apply weight to all components */
 	}
 	else {
 		color = vec4(0.0);
-		weight = texelFetch(colorBuffer, texelco, 0).a;
+		weight = 0.0;
 	}
 
 	/* Generate Triangle : less memory fetches from a VBO */



More information about the Bf-blender-cvs mailing list