[Bf-blender-cvs] [477b4559ece] blender2.8: Paint Overlay: Fix blending of the brush overlay

Clément Foucault noreply at git.blender.org
Wed Aug 22 19:49:38 CEST 2018


Commit: 477b4559ece0d12ec0bab88d317b9fe2e1832417
Author: Clément Foucault
Date:   Wed Aug 22 16:38:42 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB477b4559ece0d12ec0bab88d317b9fe2e1832417

Paint Overlay: Fix blending of the brush overlay

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

M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl

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

diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index 36568632ffa..5cca61d4c78 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -685,6 +685,7 @@ static void paint_draw_tex_overlay(
 			immUniformColor4f(1.0f, 1.0f, 1.0f, overlay_alpha * 0.01f);
 		}
 		else {
+			GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
 			immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_ALPHA_COLOR);
 			immUniformColor3fvAlpha(U.sculpt_paint_overlay_col, overlay_alpha * 0.01f);
 		}
@@ -704,6 +705,7 @@ static void paint_draw_tex_overlay(
 		immEnd();
 
 		immUnbindProgram();
+		GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
 
 		if (ELEM(mtex->brush_map_mode, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_VIEW)) {
 			GPU_matrix_pop();
@@ -764,7 +766,8 @@ static void paint_draw_cursor_overlay(
 		uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
 		uint texCoord = GPU_vertformat_attr_add(format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
 
-		immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
+		GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
+		immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_ALPHA_COLOR);
 
 		immUniformColor3fvAlpha(U.sculpt_paint_overlay_col, brush->cursor_overlay_alpha * 0.01f);
 
@@ -786,6 +789,8 @@ static void paint_draw_cursor_overlay(
 
 		immUnbindProgram();
 
+		GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
+
 		if (do_pop)
 			GPU_matrix_pop();
 	}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl
index 727c3c0a832..fc0c8609069 100644
--- a/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl
@@ -7,5 +7,8 @@ uniform sampler2D image;
 
 void main()
 {
-	fragColor = texture(image, texCoord_interp).r * color;
+	fragColor = texture(image, texCoord_interp).r * color.rgba;
+	/* Premul by alpha (not texture alpha)
+	* Use blending function GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); */
+	fragColor.rgb *= color.a;
 }



More information about the Bf-blender-cvs mailing list