qt: go back using simpler approach for noise effect and achieve the desired blending with a trick
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
Activity
added MRStatus::Reviewable label
For the record, I have also realized that with premultiplied colors multiply blending can also be achieved (RGB set to 0, alpha set to (1-lightness), lightness being R or G or B where they are equal) with the default scene graph blending (source over: operation
GL_ADD
and factors(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
), but in that case it can only be grayscale. In the future, I might make use of that for the shadows.Edited by Fatih Uzunoğluadded Component::Interface: Qt label
changed milestone to %4.0
added MRStatus::Acceptable label and removed MRStatus::Reviewable label
added MRStatus::Accepted label and removed MRStatus::Acceptable label
MR Acceptance result
This MergeRequest has been Accepted! Congratulations.MR acceptance checks details:
-
MR should be considered mergeable by Gitlab -
Last pipeline should be successful -
MergeRequest should have at least one external review and/or vote -
All threads should be resolved, have votes and score > 0 -
MergeRequest should have no activity (threads/votes) for (72h/72h)
-
added 56 commits
-
b76d1848...b86023a8 - 49 commits from branch
videolan:master
- 5dfc7cb1 - Revert "qt: add `Noise.vert`"
- 8a0f5dd5 - Revert "qml: do not depend on dummy texture in Noise.frag"
- c68fb905 - Revert "qt: introduce `QSGRectangularNoiseNode`"
- bc4fc916 - Revert "qt: introduce `NoiseRectangle`"
- 928e55a2 - Revert "qt: register `NoiseRectangle`"
- 7684d674 - Revert "qml: use `NoiseRectangle` instead of `ShaderEffect` in `FrostedGlassEffect.qml`"
- af20e289 - qml: set alpha to zero in Noise.frag to use additive blending
Toggle commit list-
b76d1848...b86023a8 - 49 commits from branch
enabled an automatic merge when all merge checks for af20e289 pass
mentioned in merge request !6678 (merged)
mentioned in merge request !7054 (merged)