[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60183] branches/soc-2013-paint/source/ blender/editors/sculpt_paint/paint_image_proj.c: Hook up custom kernel radius into projective texturing.
Antony Riakiotakis
kalast at gmail.com
Tue Sep 17 04:50:23 CEST 2013
Revision: 60183
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60183
Author: psy-fi
Date: 2013-09-17 02:50:23 +0000 (Tue, 17 Sep 2013)
Log Message:
-----------
Hook up custom kernel radius into projective texturing. Warning though,
in projective texturing bigger kernels are quite costly.
Modified Paths:
--------------
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c 2013-09-17 02:03:25 UTC (rev 60182)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c 2013-09-17 02:50:23 UTC (rev 60183)
@@ -285,6 +285,8 @@
/* redraw */
bool need_redraw;
+
+ BlurKernel *blurkernel;
} ProjPaintState;
typedef union pixelPointer {
@@ -326,18 +328,6 @@
PixelStore clonepx;
} ProjPixelClone;
-/* blur, store surrounding colors */
-#define PROJ_PIXEL_SOFTEN_TOT 4
-/* blur picking offset (in screenspace) */
-#define PROJ_PIXEL_SOFTEN_OFS_PX 1.0f
-
-static const float proj_pixel_soften_v2[PROJ_PIXEL_SOFTEN_TOT][2] = {
- {-PROJ_PIXEL_SOFTEN_OFS_PX, 0.0f},
- { 0.0f, -PROJ_PIXEL_SOFTEN_OFS_PX},
- { 0.0f, PROJ_PIXEL_SOFTEN_OFS_PX},
- { PROJ_PIXEL_SOFTEN_OFS_PX, 0.0f},
-};
-
/* Finish projection painting structs */
static Image *project_paint_face_image(const ProjPaintState *ps, int face_index)
@@ -3610,6 +3600,11 @@
}
#endif
+ if (ps->blurkernel) {
+ paint_delete_blur_kernel(ps->blurkernel);
+ MEM_freeN(ps->blurkernel);
+ }
+
if (ps->vertFlags) MEM_freeN(ps->vertFlags);
for (a = 0; a < ps->thread_tot; a++) {
@@ -3861,21 +3856,27 @@
static void do_projectpaint_soften_f(ProjPaintState *ps, ProjPixel *projPixel, float mask,
MemArena *softenArena, LinkNode **softenPixels)
{
- unsigned int accum_tot = 0;
- unsigned int i;
-
+ float accum_tot = 0.0;
+ int xk, yk;
+ BlurKernel *kernel = ps->blurkernel;
float *rgba = projPixel->newColor.f;
/* rather then painting, accumulate surrounding colors */
zero_v4(rgba);
- for (i = 0; i < PROJ_PIXEL_SOFTEN_TOT; i++) {
- float co_ofs[2];
- float rgba_tmp[4];
- sub_v2_v2v2(co_ofs, projPixel->projCoSS, proj_pixel_soften_v2[i]);
- if (project_paint_PickColor(ps, co_ofs, rgba_tmp, NULL, TRUE)) {
- add_v4_v4(rgba, rgba_tmp);
- accum_tot++;
+ 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};
+
+ add_v2_v2(co_ofs, projPixel->projCoSS);
+
+ if (project_paint_PickColor(ps, co_ofs, rgba_tmp, NULL, TRUE)) {
+ float weight = kernel->wdata[xk + yk * kernel->side];
+ mul_v4_fl(rgba_tmp, weight);
+ add_v4_v4(rgba, rgba_tmp);
+ accum_tot += weight;
+ }
}
}
@@ -3910,21 +3911,27 @@
static void do_projectpaint_soften(ProjPaintState *ps, ProjPixel *projPixel, float mask,
MemArena *softenArena, LinkNode **softenPixels)
{
- unsigned int accum_tot = 0;
- unsigned int i;
-
+ float accum_tot = 0;
+ int xk, yk;
+ BlurKernel *kernel = ps->blurkernel;
float rgba[4]; /* convert to byte after */
/* rather then painting, accumulate surrounding colors */
zero_v4(rgba);
- for (i = 0; i < PROJ_PIXEL_SOFTEN_TOT; i++) {
- float co_ofs[2];
- float rgba_tmp[4];
- sub_v2_v2v2(co_ofs, projPixel->projCoSS, proj_pixel_soften_v2[i]);
- if (project_paint_PickColor(ps, co_ofs, rgba_tmp, NULL, TRUE)) {
- add_v4_v4(rgba, rgba_tmp);
- accum_tot++;
+ 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};
+
+ add_v2_v2(co_ofs, projPixel->projCoSS);
+
+ if (project_paint_PickColor(ps, co_ofs, rgba_tmp, NULL, TRUE)) {
+ float weight = kernel->wdata[xk + yk * kernel->side];
+ mul_v4_fl(rgba_tmp, weight);
+ add_v4_v4(rgba, rgba_tmp);
+ accum_tot += weight;
+ }
}
}
@@ -4510,10 +4517,13 @@
ps->tool = brush->imagepaint_tool;
ps->blend = brush->blend;
/* only check for inversion for the soften tool, elsewhere, a resident brush inversion flag can cause issues */
- if (brush->imagepaint_tool == PAINT_TOOL_SOFTEN)
+ if (brush->imagepaint_tool == PAINT_TOOL_SOFTEN) {
ps->mode = ((ps->mode == BRUSH_STROKE_INVERT) ^ ((brush->flag & BRUSH_DIR_IN) != 0) ?
BRUSH_STROKE_INVERT : BRUSH_STROKE_NORMAL);
+ ps->blurkernel = paint_new_blur_kernel(brush);
+ }
+
/* disable for 3d mapping also because painting on mirrored mesh can create "stripes" */
ps->do_masking = paint_use_opacity_masking(brush);
ps->is_texbrush = (brush->mtex.tex && brush->imagepaint_tool == PAINT_TOOL_DRAW) ? true : false;
More information about the Bf-blender-cvs
mailing list