Fix T81026: Image Editor: Alpha (like Bloom) not showing properly
With the new image editor drawing there were was some mutual exclusive functionality. When rendering the alpha was shown correctly or the pure emissive colors were shown correctly, but never both. The cause of this is that the image_gpu did not used the correct alpha mode when generating gpu textures for non-images (render results, compositors viewer) The implementation always checked the alpha_mode. Alpha mode is an attribute for images, but aren't set for non images. This patch adds a more detailed check to ensure that the gpu texture is premultiplied. The issue has been tested using several bug report files and production files. Reviewed By: Brecht van Lommel Differential Revision: https://developer.blender.org/D8978
This commit is contained in:

committed by
Jeroen Bakker

parent
085329f114
commit
b17cca6966
Submodule release/datafiles/locale updated: 2b3c19f5f6...07106b5883
Submodule release/scripts/addons updated: 1f043682f9...1be0b3210d
Submodule release/scripts/addons_contrib updated: a52733b58d...f2f4a8b3bf
@@ -382,7 +382,7 @@ struct GPUTexture *BKE_image_get_gpu_tiles(struct Image *image,
|
|||||||
struct GPUTexture *BKE_image_get_gpu_tilemap(struct Image *image,
|
struct GPUTexture *BKE_image_get_gpu_tilemap(struct Image *image,
|
||||||
struct ImageUser *iuser,
|
struct ImageUser *iuser,
|
||||||
struct ImBuf *ibuf);
|
struct ImBuf *ibuf);
|
||||||
|
bool BKE_image_has_gpu_texture_premultiplied_alpha(struct Image *image, struct ImBuf *ibuf);
|
||||||
void BKE_image_update_gputexture(
|
void BKE_image_update_gputexture(
|
||||||
struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h);
|
struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h);
|
||||||
void BKE_image_paint_set_mipmap(struct Main *bmain, bool mipmap);
|
void BKE_image_paint_set_mipmap(struct Main *bmain, bool mipmap);
|
||||||
|
@@ -49,6 +49,21 @@
|
|||||||
static void gpu_free_unused_buffers(void);
|
static void gpu_free_unused_buffers(void);
|
||||||
static void image_free_gpu(Image *ima, const bool immediate);
|
static void image_free_gpu(Image *ima, const bool immediate);
|
||||||
|
|
||||||
|
/* Is the alpha of the `GPUTexture` for a given image/ibuf premultiplied. */
|
||||||
|
bool BKE_image_has_gpu_texture_premultiplied_alpha(Image *image, ImBuf *ibuf)
|
||||||
|
{
|
||||||
|
const bool type_is_premultiplied = (image == NULL) || ELEM(image->type,
|
||||||
|
IMA_TYPE_R_RESULT,
|
||||||
|
IMA_TYPE_COMPOSITE,
|
||||||
|
IMA_TYPE_UV_TEST);
|
||||||
|
const bool store_premultiplied =
|
||||||
|
type_is_premultiplied ||
|
||||||
|
((ibuf != NULL) &&
|
||||||
|
(ibuf->rect_float ? (image ? (image->alpha_mode != IMA_ALPHA_STRAIGHT) : false) :
|
||||||
|
(image ? (image->alpha_mode == IMA_ALPHA_PREMUL) : true)));
|
||||||
|
return store_premultiplied;
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/** \name UDIM gpu texture
|
/** \name UDIM gpu texture
|
||||||
* \{ */
|
* \{ */
|
||||||
@@ -198,8 +213,7 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
|
|||||||
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
|
||||||
|
|
||||||
if (ibuf) {
|
if (ibuf) {
|
||||||
const bool store_premultiplied = ibuf->rect_float ? (ima->alpha_mode != IMA_ALPHA_STRAIGHT) :
|
const bool store_premultiplied = BKE_image_has_gpu_texture_premultiplied_alpha(ima, ibuf);
|
||||||
(ima->alpha_mode == IMA_ALPHA_PREMUL);
|
|
||||||
IMB_update_gpu_texture_sub(tex,
|
IMB_update_gpu_texture_sub(tex,
|
||||||
ibuf,
|
ibuf,
|
||||||
UNPACK2(tileoffset),
|
UNPACK2(tileoffset),
|
||||||
@@ -330,9 +344,8 @@ static GPUTexture *image_get_gpu_texture(Image *ima,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const bool use_high_bitdepth = (ima->flag & IMA_HIGH_BITDEPTH);
|
const bool use_high_bitdepth = (ima->flag & IMA_HIGH_BITDEPTH);
|
||||||
const bool store_premultiplied = ibuf_intern->rect_float ?
|
const bool store_premultiplied = BKE_image_has_gpu_texture_premultiplied_alpha(ima,
|
||||||
(ima ? (ima->alpha_mode != IMA_ALPHA_STRAIGHT) : false) :
|
ibuf_intern);
|
||||||
(ima ? (ima->alpha_mode == IMA_ALPHA_PREMUL) : true);
|
|
||||||
|
|
||||||
*tex = IMB_create_gpu_texture(
|
*tex = IMB_create_gpu_texture(
|
||||||
ima->id.name + 2, ibuf_intern, use_high_bitdepth, store_premultiplied);
|
ima->id.name + 2, ibuf_intern, use_high_bitdepth, store_premultiplied);
|
||||||
@@ -642,6 +655,7 @@ static void gpu_texture_update_from_ibuf(
|
|||||||
int tex_stride = ibuf->x;
|
int tex_stride = ibuf->x;
|
||||||
int tex_offset = ibuf->channels * (y * ibuf->x + x);
|
int tex_offset = ibuf->channels * (y * ibuf->x + x);
|
||||||
|
|
||||||
|
const bool store_premultiplied = BKE_image_has_gpu_texture_premultiplied_alpha(ima, ibuf);
|
||||||
if (rect_float == NULL) {
|
if (rect_float == NULL) {
|
||||||
/* Byte pixels. */
|
/* Byte pixels. */
|
||||||
if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) {
|
if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) {
|
||||||
@@ -658,15 +672,12 @@ static void gpu_texture_update_from_ibuf(
|
|||||||
|
|
||||||
/* Convert to scene linear with sRGB compression, and premultiplied for
|
/* Convert to scene linear with sRGB compression, and premultiplied for
|
||||||
* correct texture interpolation. */
|
* correct texture interpolation. */
|
||||||
const bool store_premultiplied = (ima->alpha_mode == IMA_ALPHA_PREMUL);
|
|
||||||
IMB_colormanagement_imbuf_to_byte_texture(
|
IMB_colormanagement_imbuf_to_byte_texture(
|
||||||
rect, x, y, w, h, ibuf, compress_as_srgb, store_premultiplied);
|
rect, x, y, w, h, ibuf, compress_as_srgb, store_premultiplied);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Float pixels. */
|
/* Float pixels. */
|
||||||
const bool store_premultiplied = (ima->alpha_mode != IMA_ALPHA_STRAIGHT);
|
|
||||||
|
|
||||||
if (ibuf->channels != 4 || scaled || !store_premultiplied) {
|
if (ibuf->channels != 4 || scaled || !store_premultiplied) {
|
||||||
rect_float = (float *)MEM_mallocN(sizeof(float[4]) * w * h, __func__);
|
rect_float = (float *)MEM_mallocN(sizeof(float[4]) * w * h, __func__);
|
||||||
if (rect_float == NULL) {
|
if (rect_float == NULL) {
|
||||||
|
@@ -138,7 +138,7 @@ static void image_cache_image(IMAGE_Data *vedata, Image *image, ImageUser *iuser
|
|||||||
far_near[0] = ((Camera *)scene->camera->data)->clip_end;
|
far_near[0] = ((Camera *)scene->camera->data)->clip_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool use_premul_alpha = image->alpha_mode == IMA_ALPHA_PREMUL;
|
const bool use_premul_alpha = BKE_image_has_gpu_texture_premultiplied_alpha(image, ibuf);
|
||||||
const bool is_tiled_texture = tex_tile_data != NULL;
|
const bool is_tiled_texture = tex_tile_data != NULL;
|
||||||
const bool do_repeat = (!is_tiled_texture) && ((sima->flag & SI_DRAW_TILE) != 0);
|
const bool do_repeat = (!is_tiled_texture) && ((sima->flag & SI_DRAW_TILE) != 0);
|
||||||
|
|
||||||
|
Submodule source/tools updated: 4b309364f6...ff9928bc44
Reference in New Issue
Block a user