Naming:

Change pressure to size_pressure, it notes correctly that this value is
updated and expected to be used for size updating only.
Change name of cursor function and since it is used for uv sculpting
only now move to the relevant file. Also cleanup unneeded functionality
from function.

Stroke:

Separate updating of stroke variables to invariants (updated when
stroke->init = false) and variants.
This commit is contained in:
Antonis Ryakiotakis 2014-04-13 18:14:45 +03:00
parent 301d7d2f63
commit 5d79c2662e
Notes: blender-bot 2023-02-14 10:48:34 +01:00
Referenced by issue #39707, Color Picker Values are wrong in Gamma Corrected properties and profiled displays
Referenced by issue #39704, Texture painting fails with different float image working space
7 changed files with 62 additions and 93 deletions

View File

@ -597,7 +597,7 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, Brush *brush,
/* scale based on tablet pressure */
if (primary && ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) {
glTranslatef(0.5f, 0.5f, 0);
glScalef(1.0f / ups->pressure_value, 1.0f / ups->pressure_value, 1);
glScalef(1.0f / ups->size_pressure_value, 1.0f / ups->size_pressure_value, 1);
glTranslatef(-0.5f, -0.5f, 0);
}
@ -725,7 +725,7 @@ static void paint_draw_cursor_overlay(UnifiedPaintSettings *ups, Brush *brush,
glPushMatrix();
glLoadIdentity();
glTranslatef(center[0], center[1], 0);
glScalef(ups->pressure_value, ups->pressure_value, 1);
glScalef(ups->size_pressure_value, ups->size_pressure_value, 1);
glTranslatef(-center[0], -center[1], 0);
}
@ -815,7 +815,7 @@ static void paint_cursor_on_hit(UnifiedPaintSettings *ups, Brush *brush, ViewCon
/* scale 3D brush radius by pressure */
if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush))
unprojected_radius *= ups->pressure_value;
unprojected_radius *= ups->size_pressure_value;
/* set cached value in either Brush or UnifiedPaintSettings */
BKE_brush_unprojected_radius_set(vc->scene, brush, unprojected_radius);
@ -910,7 +910,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
/* draw an inner brush */
if (ups->stroke_active && BKE_brush_use_size_pressure(scene, brush)) {
/* inner at full alpha */
glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius * ups->pressure_value, 40);
glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius * ups->size_pressure_value, 40);
/* outer at half alpha */
glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha * 0.5f);
}

View File

@ -718,71 +718,6 @@ int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
/************************ cursor drawing *******************************/
void brush_drawcursor_texpaint_uvsculpt(bContext *C, int x, int y, void *UNUSED(customdata))
{
#define PX_SIZE_FADE_MAX 12.0f
#define PX_SIZE_FADE_MIN 4.0f
Scene *scene = CTX_data_scene(C);
//Brush *brush = image_paint_brush(C);
Paint *paint = BKE_paint_get_active_from_context(C);
Brush *brush = BKE_paint_brush(paint);
if (paint && brush && paint->flags & PAINT_SHOW_BRUSH) {
float zoomx, zoomy;
const float size = (float)BKE_brush_size_get(scene, brush);
short use_zoom;
float pixel_size;
float alpha = 0.5f;
use_zoom = get_imapaint_zoom(C, &zoomx, &zoomy);
if (use_zoom) {
pixel_size = size * max_ff(zoomx, zoomy);
}
else {
pixel_size = size;
}
/* fade out the brush (cheap trick to work around brush interfering with sampling [#])*/
if (pixel_size < PX_SIZE_FADE_MIN) {
return;
}
else if (pixel_size < PX_SIZE_FADE_MAX) {
alpha *= (pixel_size - PX_SIZE_FADE_MIN) / (PX_SIZE_FADE_MAX - PX_SIZE_FADE_MIN);
}
glPushMatrix();
glTranslatef((float)x, (float)y, 0.0f);
/* No need to scale for uv sculpting, on the contrary it might be useful to keep un-scaled */
if (use_zoom)
glScalef(zoomx, zoomy, 1.0f);
glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
{
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
/* hrmf, duplicate paint_draw_cursor logic here */
if (ups->stroke_active && BKE_brush_use_size_pressure(scene, brush)) {
/* inner at full alpha */
glutil_draw_lined_arc(0, (float)(M_PI * 2.0), size * ups->pressure_value, 40);
/* outer at half alpha */
glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha * 0.5f);
}
}
glutil_draw_lined_arc(0, (float)(M_PI * 2.0), size, 40);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
glPopMatrix();
}
#undef PX_SIZE_FADE_MAX
#undef PX_SIZE_FADE_MIN
}
static void toggle_paint_cursor(bContext *C, int enable)
{
wmWindowManager *wm = CTX_wm_manager(C);

View File

@ -201,7 +201,6 @@ void paint_calc_redraw_planes(float planes[4][4],
float paint_calc_object_space_radius(struct ViewContext *vc, const float center[3], float pixel_radius);
float paint_get_tex_pixel(struct MTex *mtex, float u, float v, struct ImagePool *pool, int thread);
void paint_get_tex_pixel_col(struct MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert, struct ImBuf *ibuf);
void brush_drawcursor_texpaint_uvsculpt(struct bContext *C, int x, int y, void *customdata);
void paint_sample_color(const struct bContext *C, struct ARegion *ar, int x, int y);
void BRUSH_OT_curve_preset(struct wmOperatorType *ot);

View File

@ -98,7 +98,7 @@ typedef struct PaintStroke {
bool brush_init;
float initial_mouse[2];
/* cached_pressure stores initial pressure for size pressure influence mainly */
float cached_pressure;
float cached_size_pressure;
/* last pressure will store last pressure value for use in interpolation for space strokes */
float last_pressure;
@ -166,22 +166,30 @@ static void paint_brush_update(bContext *C, Brush *brush, PaintMode mode,
* brush coord/pressure/etc.
* It's more an events design issue, which doesn't split coordinate/pressure/angle
* changing events. We should avoid this after events system re-design */
if (paint_supports_dynamic_size(brush, mode) || !stroke->brush_init) {
if(!stroke->brush_init) {
copy_v2_v2(stroke->initial_mouse, mouse);
copy_v2_v2(ups->last_rake, mouse);
copy_v2_v2(ups->tex_mouse, mouse);
copy_v2_v2(ups->mask_tex_mouse, mouse);
stroke->cached_pressure = pressure;
stroke->cached_size_pressure = pressure;
stroke->brush_init = true;
}
if (paint_supports_dynamic_size(brush, mode)) {
copy_v2_v2(ups->tex_mouse, mouse);
copy_v2_v2(ups->mask_tex_mouse, mouse);
stroke->cached_size_pressure = pressure;
}
/* Truly temporary data that isn't stored in properties */
ups->stroke_active = true;
ups->pressure_value = stroke->cached_pressure;
ups->size_pressure_value = stroke->cached_size_pressure;
ups->pixel_radius = BKE_brush_size_get(scene, brush);
if (BKE_brush_use_size_pressure(scene, brush) && paint_supports_dynamic_size(brush, mode)) {
ups->pixel_radius *= stroke->cached_pressure;
ups->pixel_radius *= stroke->cached_size_pressure;
}
if (paint_supports_dynamic_tex_coords(brush, mode)) {
@ -251,13 +259,8 @@ static void paint_brush_update(bContext *C, Brush *brush, PaintMode mode,
ups->draw_anchored = true;
}
else if (brush->flag & BRUSH_RAKE) {
if (!stroke->brush_init)
copy_v2_v2(ups->last_rake, mouse);
else
paint_calculate_rake_rotation(ups, mouse);
paint_calculate_rake_rotation(ups, mouse);
}
stroke->brush_init = true;
}

View File

@ -2496,11 +2496,6 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
swap_m4m4(vc->rv3d->persmat, mat);
{
UnifiedPaintSettings *ups = &ts->unified_paint_settings;
ups->pressure_value = pressure;
}
DAG_id_tag_update(ob->data, 0);
ED_region_tag_redraw(vc->ar);
}
@ -3017,11 +3012,6 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
do_shared_vertexcol(me, vpd->mlooptag, vpd->mfacetag, do_tessface);
}
{
UnifiedPaintSettings *ups = &ts->unified_paint_settings;
ups->pressure_value = pressure;
}
ED_region_tag_redraw(vc->ar);
if (vpd->use_fast_update == false) {

View File

@ -68,6 +68,9 @@
#include "paint_intern.h"
#include "uvedit_intern.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"
#include "UI_view2d.h"
#define MARK_BOUNDARY 1
@ -185,6 +188,45 @@ static int uv_sculpt_brush_poll(bContext *C)
return 0;
}
static void brush_drawcursor_uvsculpt(bContext *C, int x, int y, void *UNUSED(customdata))
{
#define PX_SIZE_FADE_MAX 12.0f
#define PX_SIZE_FADE_MIN 4.0f
Scene *scene = CTX_data_scene(C);
//Brush *brush = image_paint_brush(C);
Paint *paint = BKE_paint_get_active_from_context(C);
Brush *brush = BKE_paint_brush(paint);
if (paint && brush && paint->flags & PAINT_SHOW_BRUSH) {
const float size = (float)BKE_brush_size_get(scene, brush);
float alpha = 0.5f;
/* fade out the brush (cheap trick to work around brush interfering with sampling [#])*/
if (size < PX_SIZE_FADE_MIN) {
return;
}
else if (size < PX_SIZE_FADE_MAX) {
alpha *= (size - PX_SIZE_FADE_MIN) / (PX_SIZE_FADE_MAX - PX_SIZE_FADE_MIN);
}
glPushMatrix();
glTranslatef((float)x, (float)y, 0.0f);
glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glutil_draw_lined_arc(0, (float)(M_PI * 2.0), size, 40);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
glPopMatrix();
}
#undef PX_SIZE_FADE_MAX
#undef PX_SIZE_FADE_MIN
}
void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings)
{
@ -201,7 +243,7 @@ void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings
BKE_paint_init(&settings->uvsculpt->paint, PAINT_CURSOR_SCULPT);
WM_paint_cursor_activate(wm, uv_sculpt_brush_poll,
brush_drawcursor_texpaint_uvsculpt, NULL);
brush_drawcursor_uvsculpt, NULL);
}
else {
if (settings->uvsculpt)

View File

@ -941,7 +941,7 @@ typedef struct UnifiedPaintSettings {
int stroke_active;
/* drawing pressure */
float pressure_value;
float size_pressure_value;
/* position of mouse, used to sample the texture */
float tex_mouse[2];