From 218317b8b9bc0b4ebf73bcfd5d71a36fbcd15e86 Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Mon, 13 Oct 2025 08:52:33 +0200 Subject: [PATCH] Fix #147381: VSE preview shows incorrect transparency for masks Since VSE HDR preview was implemented (18110744a26), the preview image is put into RGBA 16F format "color texture", and the overlay (checkerboard, grids etc.) is put into RGBA 8U format "overlay texture". This was rendering the color image as NON premultiplied alpha in the viewport color texture, which is not what happens in other places (e.g. image space). Later commit (c279d894db70) fixed transparency of the overlay texture, in order to make pure emissive (color non zero, alpha zero) colors from EXR files show up in VSE preview. However that exposed the issue that underlying color texture is not premultiplied. Fix this by premultiplying the output color in gpu_shader_display_transform that is used by VSE preview. This is done at the end of the shader isntead of using fixed function blending, since premultiplication needs to happen in a way that preserves pure-emissive colors. Comparison images in the PR. Pull Request: https://projects.blender.org/blender/blender/pulls/147892 --- .../intern/fallback/fallback_gpu_shader_binder.cc | 5 ++++- .../opencolorio/intern/libocio/libocio_gpu_shader_binder.cc | 5 ++++- .../shaders/gpu_shader_display_transform_frag.glsl | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/source/blender/imbuf/opencolorio/intern/fallback/fallback_gpu_shader_binder.cc b/source/blender/imbuf/opencolorio/intern/fallback/fallback_gpu_shader_binder.cc index f0665e3f86e..f8a3566f1ae 100644 --- a/source/blender/imbuf/opencolorio/intern/fallback/fallback_gpu_shader_binder.cc +++ b/source/blender/imbuf/opencolorio/intern/fallback/fallback_gpu_shader_binder.cc @@ -93,7 +93,10 @@ void FallbackGPUShaderBinder::construct_scene_linear_shader( const std::string fragment_source = generate_scene_linear_fragment_source(display_shader); - if (!create_gpu_shader(display_shader, fragment_source, {{"USE_TO_SCENE_LINEAR_ONLY", ""}})) { + if (!create_gpu_shader(display_shader, + fragment_source, + {{"USE_TO_SCENE_LINEAR_ONLY", ""}, {"OUTPUT_PREMULTIPLIED", ""}})) + { display_shader.is_valid = false; } } diff --git a/source/blender/imbuf/opencolorio/intern/libocio/libocio_gpu_shader_binder.cc b/source/blender/imbuf/opencolorio/intern/libocio/libocio_gpu_shader_binder.cc index 55d4791307e..aeda6c58c67 100644 --- a/source/blender/imbuf/opencolorio/intern/libocio/libocio_gpu_shader_binder.cc +++ b/source/blender/imbuf/opencolorio/intern/libocio/libocio_gpu_shader_binder.cc @@ -261,7 +261,10 @@ void LibOCIOGPUShaderBinder::construct_scene_linear_shader( } construct_shader_for_processors( - display_shader, processor_to_scene_linear, nullptr, {{"USE_TO_SCENE_LINEAR_ONLY", ""}}); + display_shader, + processor_to_scene_linear, + nullptr, + {{"USE_TO_SCENE_LINEAR_ONLY", ""}, {"OUTPUT_PREMULTIPLIED", ""}}); } } // namespace blender::ocio diff --git a/source/blender/imbuf/opencolorio/shaders/gpu_shader_display_transform_frag.glsl b/source/blender/imbuf/opencolorio/shaders/gpu_shader_display_transform_frag.glsl index 9977d851f58..999a4a9b0dc 100644 --- a/source/blender/imbuf/opencolorio/shaders/gpu_shader_display_transform_frag.glsl +++ b/source/blender/imbuf/opencolorio/shaders/gpu_shader_display_transform_frag.glsl @@ -243,6 +243,12 @@ float4 OCIO_ProcessColor(float4 col, float4 col_overlay) } #endif +#ifdef OUTPUT_PREMULTIPLIED + if (col.a > 0.0 && col.a < 1.0) { + col.rgb *= col.a; + } +#endif + return col; }