[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30111] branches/soc-2010-jwilkins: * overlay now works in FIXED mapping mode
Jason Wilkins
Jason.A.Wilkins at gmail.com
Thu Jul 8 14:41:00 CEST 2010
Revision: 30111
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30111
Author: jwilkins
Date: 2010-07-08 14:41:00 +0200 (Thu, 08 Jul 2010)
Log Message:
-----------
* overlay now works in FIXED mapping mode
* overlay now just loads alpha and purely uses transparency to show strength (this eliminate dark borders on the overlay)
* overlay now shows when cursor is in viewport, not just when it is over the model (full time display operator is coming soon)
* when in fixed mapping mode, the curve fall off is included in the overlay (I'll give option to do that with tiled mode later, but requires multitexture)
* rake and pressure resizing are taken into account
* in fixed mode an attempt is made to only allocate as big a texture as needed for the brush size, and it doesn't resample if the brush shrinks
* rotation and offset are baked into the texture because emulating everything blender can do with textures in opengl would require a lot of code (same will eventually be done with texcache, which will make it even faster)
Modified Paths:
--------------
branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
branches/soc-2010-jwilkins/source/blender/blenkernel/intern/colortools.c
branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c
branches/soc-2010-jwilkins/source/blender/makesdna/DNA_color_types.h
Modified: branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py 2010-07-08 11:19:55 UTC (rev 30110)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py 2010-07-08 12:41:00 UTC (rev 30111)
@@ -827,10 +827,10 @@
row = col.row(align=True)
row.label(text="Overlay:")
- row.active = tex_slot.map_mode in ('TILED')
+ row.active = tex_slot.map_mode in ('FIXED', 'TILED')
row = col.row(align=True)
-
+
col = row.column()
if brush.use_texture_overlay:
@@ -838,11 +838,11 @@
else:
col.prop(brush, "use_texture_overlay", toggle=True, text="", icon='MUTE_IPO_ON')
- col.active = tex_slot.map_mode in ('TILED')
+ col.active = tex_slot.map_mode in ('FIXED', 'TILED')
col = row.column()
col.prop(brush, "texture_overlay_alpha", text="Alpha")
- col.active = tex_slot.map_mode in ('TILED') and brush.use_texture_overlay
+ col.active = tex_slot.map_mode in ('FIXED', 'TILED') and brush.use_texture_overlay
class VIEW3D_PT_tools_brush_tool(PaintPanel):
Modified: branches/soc-2010-jwilkins/source/blender/blenkernel/intern/colortools.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenkernel/intern/colortools.c 2010-07-08 11:19:55 UTC (rev 30110)
+++ branches/soc-2010-jwilkins/source/blender/blenkernel/intern/colortools.c 2010-07-08 12:41:00 UTC (rev 30111)
@@ -126,6 +126,9 @@
cumap->cm[a].curve[1].x= maxx;
cumap->cm[a].curve[1].y= maxy;
}
+
+ cumap->changed_timestamp = 0;
+
return cumap;
}
@@ -644,7 +647,9 @@
float thresh= 0.01f*(clipr->xmax - clipr->xmin);
float dx= 0.0f, dy= 0.0f;
int a;
-
+
+ cumap->changed_timestamp++;
+
/* clamp with clip */
if(cumap->flag & CUMA_DO_CLIP) {
for(a=0; a<cuma->totpoint; a++) {
Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c 2010-07-08 11:19:55 UTC (rev 30110)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c 2010-07-08 12:41:00 UTC (rev 30111)
@@ -35,6 +35,7 @@
#include "BKE_context.h"
#include "BKE_paint.h"
+#include "BKE_brush.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -205,6 +206,8 @@
int brush_size;
int winx;
int winy;
+ int brush_map_mode;
+ int curve_changed_timestamp;
} Snapshot;
static int same_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
@@ -219,9 +222,10 @@
mtex->size[1] == snap->size[1] &&
mtex->size[2] == snap->size[2] &&
mtex->rot == snap->rot &&
- brush->size == snap->brush_size &&
+ brush->size <= snap->brush_size && // make brush smaller shouldn't cause a resample
vc->ar->winx == snap->winx &&
- vc->ar->winy == snap->winy;
+ vc->ar->winy == snap->winy &&
+ mtex->brush_map_mode == snap->brush_map_mode;
}
static void make_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
@@ -232,80 +236,132 @@
snap->brush_size = brush->size;
snap->winx = vc->ar->winx;
snap->winy = vc->ar->winy;
+ snap->brush_map_mode = brush->mtex.brush_map_mode;
}
-static int load_tex(Sculpt *sd, Brush* brush, ViewContext* vc)
+static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
{
static GLint overlay_texture = 0;
static int init = 0;
- static int changed_timestamp = -1;
+ static int tex_changed_timestamp = -1;
+ static int curve_changed_timestamp = -1;
static Snapshot snap;
+ static int old_size = -1;
GLubyte* buffer = 0;
- int width, height;
+ int size;
int j;
int refresh;
- if (!brush->mtex.tex) return 0;
+ if (!br->mtex.tex) return 0;
refresh =
!overlay_texture ||
- !brush->mtex.tex->preview ||
- brush->mtex.tex->preview->changed_timestamp[0] != changed_timestamp ||
- !same_snap(&snap, brush, vc);
+ !br->mtex.tex->preview ||
+ br->mtex.tex->preview->changed_timestamp[0] != tex_changed_timestamp ||
+ !br->curve ||
+ br->curve->changed_timestamp != curve_changed_timestamp ||
+ !same_snap(&snap, br, vc);
if (refresh) {
- if (brush->mtex.tex->preview)
- changed_timestamp = brush->mtex.tex->preview->changed_timestamp[0];
+ if (br->mtex.tex->preview)
+ tex_changed_timestamp = br->mtex.tex->preview->changed_timestamp[0];
- make_snap(&snap, brush, vc);
+ if (br->curve)
+ curve_changed_timestamp = br->curve->changed_timestamp;
- width = height = 512;
+ make_snap(&snap, br, vc);
- buffer = MEM_mallocN(2*sizeof(unsigned char)*width*height, "load_tex");
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
+ int s = br->size;
+ int r = 1;
+ for (s >>= 1; s > 0; s >>= 1)
+ r++;
+
+ size = (1<<r);
+
+ if (size < old_size)
+ size = old_size;
+ }
+ else
+ size = size = 512;
+
+ if (old_size != size) {
+ if (overlay_texture) {
+ glDeleteTextures(1, &overlay_texture);
+ overlay_texture = 0;
+ }
+
+ init = 0;
+
+ old_size = size;
+ }
+
+ buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "load_tex");
+
#pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP)
- for (j= 0; j < height; j++) {
+ for (j= 0; j < size; j++) {
int i;
float y;
+ float len;
- for (i= 0; i < width; i++) {
+ for (i= 0; i < size; i++) {
// largely duplicated from tex_strength
- const float rotation = -brush->mtex.rot;
- float diameter = brush->size;
- int index = 2*(j*width + i);
+ const float rotation = -br->mtex.rot;
+ float diameter = br->size;
+ int index = j*size + i;
float x;
+ float avg;
- x = (float)i/width;
- y = (float)j/height;
+ x = (float)i/size;
+ y = (float)j/size;
x -= 0.5f;
y -= 0.5f;
-
- x *= vc->ar->winx / diameter;
- y *= vc->ar->winy / diameter;
- /* it is probably worth optimizing for those cases where
- the texture is not rotated by skipping the calls to
- atan2, sqrtf, sin, and cos. */
- if (rotation > 0.001 || rotation < -0.001) {
- const float angle = atan2(y, x) + rotation;
- const float flen = sqrtf(x*x + y*y);
-
- x = flen * cos(angle);
- y = flen * sin(angle);
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) {
+ x *= vc->ar->winx / diameter;
+ y *= vc->ar->winy / diameter;
}
+ else {
+ x *= 2;
+ y *= 2;
+ }
- x *= brush->mtex.size[0];
- y *= brush->mtex.size[1];
+ len = sqrtf(x*x + y*y);
- x += brush->mtex.ofs[0];
- y += brush->mtex.ofs[1];
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED || len <= 1) {
+ /* it is probably worth optimizing for those cases where
+ the texture is not rotated by skipping the calls to
+ atan2, sqrtf, sin, and cos. */
+ if (rotation > 0.001 || rotation < -0.001) {
+ const float angle = atan2(y, x) + rotation;
- buffer[index] = buffer[index+1] = (GLubyte)(get_tex_pixel(brush, x, y) * 255);
+ x = len * cos(angle);
+ y = len * sin(angle);
+ }
+
+ x *= br->mtex.size[0];
+ y *= br->mtex.size[1];
+
+ x += br->mtex.ofs[0];
+ y += br->mtex.ofs[1];
+
+ avg = get_tex_pixel(br, x, y);
+
+ avg += br->texture_sample_bias;
+
+ avg *= brush_curve_strength(br, len, 1); /* Falloff curve */
+
+ buffer[index] = (GLubyte)(255*avg);
+ }
+ else {
+ buffer[index] = 0;
+ }
}
}
@@ -317,11 +373,11 @@
if (refresh) {
if (!init) {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, buffer);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
init = 1;
}
else {
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, buffer);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
}
if (buffer)
@@ -334,6 +390,11 @@
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ }
+
return 1;
}
@@ -549,7 +610,7 @@
// XXX duplicated from brush_strength & paint_stroke_add_step, refactor later
//wmEvent* event = CTX_wm_window(C)->eventstate;
- if ( brush->draw_pressure && brush->flag & BRUSH_ALPHA_PRESSURE)
+ if (brush->draw_pressure && (brush->flag & BRUSH_ALPHA_PRESSURE))
visual_strength *= brush->pressure_value;
// remove effect of strength multiplier
@@ -568,7 +629,7 @@
unprojected_radius = unproject_brush_radius(CTX_data_active_object(C), &vc, location, brush->size);
}
- if (brush->draw_pressure && brush->flag & BRUSH_SIZE_PRESSURE)
+ if (brush->draw_pressure && (brush->flag & BRUSH_SIZE_PRESSURE))
unprojected_radius *= brush->pressure_value;
if (!(brush->flag & BRUSH_LOCK_SIZE))
@@ -666,52 +727,6 @@
glPopAttrib();
}
-
- if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && brush->flag & BRUSH_TEXTURE_OVERLAY) {
- const float diameter = 2*brush->size;
-
- glPushAttrib(
- GL_COLOR_BUFFER_BIT|
- GL_CURRENT_BIT|
- GL_DEPTH_BUFFER_BIT|
- GL_ENABLE_BIT|
- GL_LINE_BIT|
- GL_POLYGON_BIT|
- GL_STENCIL_BUFFER_BIT|
- GL_TRANSFORM_BIT|
- GL_VIEWPORT_BIT|
- GL_TEXTURE_BIT);
-
- if (load_tex(sd, brush, &vc)) {
- glColor4f(col[0], col[1], col[2], alpha);
-
- glEnable(GL_BLEND);
-
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glDepthMask(GL_FALSE);
- glDepthFunc(GL_ALWAYS);
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
-
- glColor4f(1.0f, 1.0f, 1.0f, brush->texture_overlay_alpha / 100.0f);
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(0, 0);
-
- glTexCoord2f(1, 0);
- glVertex2f(viewport[2], 0);
-
- glTexCoord2f(1, 1);
- glVertex2f(viewport[2], viewport[3]);
-
- glTexCoord2f(0, 1);
- glVertex2f(0, viewport[3]);
- glEnd();
- }
-
- glPopAttrib();
- }
}
if (!hit || !(paint->flags & PAINT_SHOW_BRUSH_ON_SURFACE)) {
@@ -746,6 +761,97 @@
glPopAttrib();
}
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list