forked from bartvdbraak/blender
Support for rake in 2D image painting.
This commit is contained in:
parent
1ea16dcf9b
commit
99ee23aec5
@ -565,15 +565,37 @@ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br,
|
||||
/* Brush Sampling for 2D brushes. when we unify the brush systems this will be necessarily a separate function */
|
||||
float BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], struct ImagePool *pool)
|
||||
{
|
||||
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
||||
MTex *mtex = &brush->mtex;
|
||||
|
||||
if (mtex && mtex->tex) {
|
||||
float co[3], tin, tr, tg, tb, ta;
|
||||
float x = xy[0], y = xy[1];
|
||||
int hasrgb;
|
||||
const int radius = BKE_brush_size_get(scene, brush);
|
||||
int radius = BKE_brush_size_get(scene, brush);
|
||||
float rotation = -mtex->rot;
|
||||
|
||||
co[0] = xy[0] / radius;
|
||||
co[1] = xy[1] / radius;
|
||||
if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
|
||||
rotation += ups->brush_rotation;
|
||||
radius = ups->pixel_radius;
|
||||
}
|
||||
|
||||
x /= radius;
|
||||
y /= radius;
|
||||
|
||||
if (rotation > 0.001f || rotation < -0.001f) {
|
||||
const float angle = atan2f(y, x) + rotation;
|
||||
const float flen = sqrtf(x * x + y * y);
|
||||
|
||||
x = flen * cosf(angle);
|
||||
y = flen * sinf(angle);
|
||||
}
|
||||
|
||||
x *= brush->mtex.size[0];
|
||||
y *= brush->mtex.size[1];
|
||||
|
||||
co[0] = x + brush->mtex.ofs[0];
|
||||
co[1] = y + brush->mtex.ofs[1];
|
||||
co[2] = 0.0f;
|
||||
|
||||
hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, 0, pool);
|
||||
|
@ -96,6 +96,7 @@ typedef struct BrushPainterCache {
|
||||
int lastsize;
|
||||
float lastalpha;
|
||||
float lastjitter;
|
||||
float last_rotation;
|
||||
|
||||
ImBuf *ibuf;
|
||||
ImBuf *texibuf;
|
||||
@ -335,6 +336,7 @@ static void brush_painter_2d_tiled_tex_partial_update(BrushPainter *painter, con
|
||||
static void brush_painter_2d_refresh_cache(BrushPainter *painter, const float pos[2], int use_color_correction)
|
||||
{
|
||||
const Scene *scene = painter->scene;
|
||||
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
||||
Brush *brush = painter->brush;
|
||||
BrushPainterCache *cache = &painter->cache;
|
||||
MTex *mtex = &brush->mtex;
|
||||
@ -343,10 +345,16 @@ static void brush_painter_2d_refresh_cache(BrushPainter *painter, const float po
|
||||
const int diameter = 2 * BKE_brush_size_get(scene, brush);
|
||||
const float alpha = BKE_brush_alpha_get(scene, brush);
|
||||
const bool do_tiled = ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_3D);
|
||||
float rotation = -mtex->rot;
|
||||
|
||||
if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
|
||||
rotation += ups->brush_rotation;
|
||||
}
|
||||
|
||||
if (diameter != cache->lastsize ||
|
||||
alpha != cache->lastalpha ||
|
||||
brush->jitter != cache->lastjitter)
|
||||
brush->jitter != cache->lastjitter ||
|
||||
rotation != cache->last_rotation)
|
||||
{
|
||||
if (cache->ibuf) {
|
||||
IMB_freeImBuf(cache->ibuf);
|
||||
@ -370,6 +378,7 @@ static void brush_painter_2d_refresh_cache(BrushPainter *painter, const float po
|
||||
cache->lastsize = diameter;
|
||||
cache->lastalpha = alpha;
|
||||
cache->lastjitter = brush->jitter;
|
||||
cache->last_rotation = rotation;
|
||||
}
|
||||
else if (do_tiled && mtex && mtex->tex) {
|
||||
int dx = (int)painter->lastpaintpos[0] - (int)pos[0];
|
||||
|
Loading…
Reference in New Issue
Block a user