Fix #147381: VSE preview shows incorrect transparency for masks

Since VSE HDR preview was implemented (18110744a2), 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 (c279d894db) 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
This commit is contained in:
Aras Pranckevicius
2025-10-13 08:52:33 +02:00
committed by Aras Pranckevicius
parent 6691529dcc
commit 218317b8b9
3 changed files with 14 additions and 2 deletions

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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;
}