[Bf-blender-cvs] [7c7cb01] master: Fix part of T41406

Antony Riakiotakis noreply at git.blender.org
Tue Aug 12 19:47:14 CEST 2014


Commit: 7c7cb01aa5641414d9f0c39ab81df0f57205f362
Author: Antony Riakiotakis
Date:   Tue Aug 12 19:45:57 2014 +0200
Branches: master
https://developer.blender.org/rB7c7cb01aa5641414d9f0c39ab81df0f57205f362

Fix part of T41406

Attempt to make soften brush faster by allowing non-symmetric kernels.
Projective painting supports those naturally but for 2D painting there's
a small hack to avoid shifting of the texture. Not totally correct but
it works for now.

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

M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_image_2d.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_intern.h

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

diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index a556f22..85c76c2 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -515,10 +515,10 @@ BlurKernel *paint_new_blur_kernel(Brush *br)
 {
 	int i, j;
 	BlurKernel *kernel = MEM_mallocN(sizeof(BlurKernel), "blur kernel");
-	int pixel_len = br->blur_kernel_radius;
+	float pixel_len = br->blur_kernel_radius / 2.0f;
 	BlurKernelType type = br->blur_mode;
 
-	kernel->side = pixel_len * 2 + 1;
+	kernel->side = br->blur_kernel_radius + 1;
 	kernel->side_squared = kernel->side * kernel->side;
 	kernel->wdata = MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data");
 	kernel->pixel_len = pixel_len;
@@ -531,26 +531,19 @@ BlurKernel *paint_new_blur_kernel(Brush *br)
 
 		case KERNEL_GAUSSIAN:
 		{
-			float standard_dev = pixel_len / 3.0; /* at standard deviation of 3.0 kernel is at about zero */
-			int i_term = pixel_len + 1;
+			float standard_dev = pixel_len / 3.0f; /* at standard deviation of 3.0 kernel is at about zero */
 
 			/* make the necessary adjustment to the value for use in the normal distribution formula */
 			standard_dev = standard_dev * standard_dev * 2;
 
-			kernel->wdata[pixel_len + pixel_len * kernel->side] = 1.0;
-			/* fill in all four quadrants at once */
-			for (i = 0; i < i_term; i++) {
-				for (j = 0; j < pixel_len; j++) {
+			for (i = 0; i < kernel->side; i++) {
+				for (j = 0; j < kernel->side; j++) {
 					float idist = pixel_len - i;
 					float jdist = pixel_len - j;
 
 					float value = exp((idist * idist + jdist * jdist) / standard_dev);
 
-					kernel->wdata[i + j * kernel->side] =
-					kernel->wdata[(kernel->side - j - 1) + i * kernel->side] =
-					kernel->wdata[(kernel->side - i - 1) + (kernel->side - j - 1) * kernel->side] =
-					kernel->wdata[j + (kernel->side - i - 1) * kernel->side] =
-						value;
+					kernel->wdata[i + j * kernel->side] = value;
 				}
 			}
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 1cba8a2..14429eb 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -877,8 +877,10 @@ static void paint_2d_lift_soften(ImagePaintState *s, ImBuf *ibuf, ImBuf *ibufb,
 
 			for (yk = 0; yk < kernel->side; yk++) {
 				for (xk = 0; xk < kernel->side; xk++) {
-					count += paint_2d_ibuf_add_if(ibuf, xi + xk - kernel->pixel_len,
-					                               yi + yk - kernel->pixel_len, outrgb, is_torus,
+					float x_offs = xk - kernel->pixel_len;
+					float y_offs = yk - kernel->pixel_len;
+					count += paint_2d_ibuf_add_if(ibuf, xi + signf(x_offs) * fabs(x_offs + 0.51f),
+					                               yi + signf(y_offs) * fabs(y_offs + 0.51f), outrgb, is_torus,
 					                               kernel->wdata[xk + yk * kernel->side]);
 				}
 			}
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 1bad066..ba6b6ca 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -3763,7 +3763,9 @@ static void do_projectpaint_soften_f(ProjPaintState *ps, ProjPixel *projPixel, f
 	for (yk = 0; yk < kernel->side; yk++) {
 		for (xk = 0; xk < kernel->side; xk++) {
 			float rgba_tmp[4];
-			float co_ofs[2] = {xk - kernel->pixel_len, yk - kernel->pixel_len};
+			float x_offs = xk - kernel->pixel_len;
+			float y_offs = yk - kernel->pixel_len;
+			float co_ofs[2] = {x_offs, y_offs};
 
 			add_v2_v2(co_ofs, projPixel->projCoSS);
 
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 736e6d2..57285ad 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -287,7 +287,7 @@ typedef struct {
 	float *wdata; /* actual kernel */
 	int side; /* kernel side */
 	int side_squared; /* data side */
-	int pixel_len; /* pixels around center that kernel is wide */
+	float pixel_len; /* pixels around center that kernel is wide */
 } BlurKernel;
 
 enum BlurKernelType;




More information about the Bf-blender-cvs mailing list