From 8f9150871c5f41df948d523c51ed04fc689eaf07 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 27 Apr 2013 12:51:23 +0000 Subject: Fix part of #34233: bad alpha blending for 2D image painting. This is a very old issue, the formulas here were never quite right, should all work ok now with byte and float images. Some differences: * Colors with zero alpha from the background will never have an influence, so you don't get alpha fringes when painting over such areas. This does give hard edges when looking at the RGB channels alone, but there's no way to avoid that and fringes at the same time, same behavior as other painting apps. * Add/Subtract/Multiply/Lighten/Darken now leave the alpha channel unchanged and work only the RGB channels, again same behavior as many other apps. * Erase/Add alpha now compensates for premultiplied float images to keep the straight RGB colors the same. Next: fix projection painting. --- source/blender/blenkernel/intern/brush.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel/intern/brush.c') diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index e3709143277..517180964a5 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -518,7 +518,9 @@ int BKE_brush_clone_image_delete(Brush *brush) } /* Generic texture sampler for 3D painting systems. point has to be either in - * region space mouse coordinates, or 3d world coordinates for 3D mapping */ + * region space mouse coordinates, or 3d world coordinates for 3D mapping. + * + * rgba outputs straight alpha. */ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br, const float point[3], float rgba[4], const int thread, @@ -755,7 +757,10 @@ float BKE_brush_sample_masktex(const Scene *scene, Brush *br, return intensity; } -/* Brush Sampling for 2D brushes. when we unify the brush systems this will be necessarily a separate function */ +/* Brush Sampling for 2D brushes. when we unify the brush systems this will be + * necessarily a separate function. + * + * rgba outputs straight alpha. */ float BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2], float rgba[4]) { UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; @@ -873,6 +878,11 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf copy_v3_v3(dstf, brush_rgb); dstf[3] = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius); } + + /* output premultiplied alpha image */ + dstf[0] *= dstf[3]; + dstf[1] *= dstf[3]; + dstf[2] *= dstf[3]; } } } -- cgit v1.2.3