Skip to content

qt: go back using simpler approach for noise effect and achieve the desired blending with a trick

Fatih Uzunoğlu requested to merge fuzun/vlc:qt/noiseuseshadereffectagain into master

For the noise effect, we desire to use additive blending (S + D) instead of the default "source-over" (S + D * (1 - S.a)). Qt does not offer a way for items to change the blend operation or factors without custom scene graph nodes.

In !6512 (merged), I created an independent node that adjusts the blending factors. Since ShaderEffect or other items do not offer adjusting the blending, I thought that this would be necessary.

However, after reading the Qt docs (https://doc.qt.io/qt-6/qml-qtquick-shadereffect.html#shader-inputs-and-resources) more carefully, I realized that with a trick due to pre-multiplied colors additive blending can be achieved in a simpler way:

The output from the fragmentShader should be premultiplied. If blending is enabled, source-over blending is used. However, additive blending can be achieved by outputting zero in the alpha channel.

This would not be possible if the color was not pre-multiplied, but since it is pre-multiplied, the alpha is already factored in the RGB channels so it is still considered and not totally dismissed by setting the alpha to 0.0.

The blending is still source over, so (S + D * (1 - S.a)). However, when the source alpha is set to 0.0, the operation becomes simply (S + D) which is essentially additive blending that we want.

Request review @chub.

Merge request reports

Loading