diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-19 03:56:12 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-19 15:36:42 +0300 |
commit | 3b23b5c638feae0ad6319440771b83a64a1f9ebe (patch) | |
tree | 16fbedd83ffa6a02904d3f93576c1de1674a0584 /source/blender | |
parent | 7c78c20b6bf6f7dd00397c456fb9e2116febfca7 (diff) |
Images: don't (un)premultipy non-color data
The previous behavior here was wrong for some specific combinations of
settings, non-color RGB channels should never be affected by the alpha
channel.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/imbuf/intern/readimage.c | 10 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_tex_image.c | 3 |
2 files changed, 10 insertions, 3 deletions
diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c index e1df5c63093..9297227bc87 100644 --- a/source/blender/imbuf/intern/readimage.c +++ b/source/blender/imbuf/intern/readimage.c @@ -49,8 +49,6 @@ static void imb_handle_alpha(ImBuf *ibuf, char colorspace[IM_MAX_SPACE], char effective_colorspace[IM_MAX_SPACE]) { - int alpha_flags; - if (colorspace) { if (ibuf->rect != NULL && ibuf->rect_float == NULL) { /* byte buffer is never internally converted to some standard space, @@ -62,6 +60,9 @@ static void imb_handle_alpha(ImBuf *ibuf, BLI_strncpy(colorspace, effective_colorspace, IM_MAX_SPACE); } + bool is_data = (colorspace && IMB_colormanagement_space_name_is_data(colorspace)); + int alpha_flags; + if (flags & IB_alphamode_detect) { alpha_flags = ibuf->flags & IB_alphamode_premul; } @@ -69,7 +70,10 @@ static void imb_handle_alpha(ImBuf *ibuf, alpha_flags = flags & IB_alphamode_premul; } - if (flags & IB_ignore_alpha) { + if (is_data) { + /* Don't touch alpha. */ + } + else if (flags & IB_ignore_alpha) { IMB_rectfill_alpha(ibuf, 1.0f); } else { diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c index a9183cd10ef..8086bb2e15d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -180,6 +180,9 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, } if (out[0].hasoutput) { + /* When the alpha socket is used, unpremultiply alpha. This makes it so + * that if we blend the color with a transparent shader using alpha as + * a factor, we don't multiply alpha into the color twice. */ if (out[1].hasoutput && !IMB_colormanagement_space_name_is_data(ima->colorspace_settings.name)) { GPU_link(mat, "tex_color_alpha_unpremultiply", out[0].link, &out[0].link); |