I am looking for a possibility to render any content on Alpha on top of other things with the low-level rendering pipeline. Also I want to be able to fade this content in and out… this seems to be possible when using AlphaBlend and setting the Alpha of the QuadRenderer’s color to 0.
With AlphaBlend you could use the same Clear Color for SceneTexture and RenderTexture.
When using AlphaBlendPremultiplied lerp the color from white to black at the same time as fading Alpha to 0. Behaves slightly differently though.
Other than that maybe check out the additional BlendStates that come with VL.Addons, especially the BlendStates node that allows to easily switch between them.
And last but not least have a look at the PorterDuff help patches (also in VL.Addons) by @motzi:
This is the approach that took me the furthest. I also managed to get the fade to a very similar curve as with the Blend, although I dont really know what I am doing. Any ideas how to polish this further?
Really nice, with that I could now finally get closer to a flexible node for everyday rendering tasks, which can also deal with alpha and be faded in and out (@sebl@Elias, we discussed about that at Link…)
Unluckily none of these brought the desired result, although its really cool to know now they are there. Is it possible to explain why there is this little border with AlphaBlend?
I guess the alphha channel of the SceneTexture is premultiplied.
Search for straight vs. premultitplied alpha and you’ll find lots of explanations.
Just remembered that there is also an UnPremultiply filter in VL.Addons. Put that inbetween the SceneTexture and the QuadRenderer with AlphaBlend and play with the Power value while watching the edges.
The border simply comes from the fact, that with AlphaBlending you always perform a blend between the new pixel (the source) and the pixel which is already there (the destination).
in your case, the background/clear color of the rotating cube SceneTexture is black (even though it is fully transparent and does not contribute anything). due to anti-aliasing the cube will have partly transparent pixels at the edge. since you are calculating the new color as a mix of source and destination color and weigh source by its alpha, you will get darker pixels, even at the bright edge. When blending the resulting texture again on top of a bright background in another AlphaBlend operation (what you are doing in the compositing), those darker pixels might become apparent.
You could try to be smart and choose a fully transparent white destination color. This would get rid of the darker pixels at the bright edge, but introduce brighter pixels at the darker edge of the cube when the new background is darker - so no win here.
The solution is indeed premultiplying. By premultiplying you actually diminish the color contribution proportional to the alpha (partly transparent pixels become darker (i.e. don’t add so much to the equation).
My personal favourite explanation is by Bartosz Ciechanowski and his interactive demos. Skip to the filtering and interpolation section to get an idea where the “bleeding” of darker/lighter pixels come from and understand why premultiplying makes sense here.
this is acutally a bit misleading, sorry. looking at the AlphaBlendPremultiplied formula, you will notice that the SourceColor will not be multiplied with SourceAlpha and therefore not become darker (because you assume that the color contribution was already premultiplied).