Open Sash0check opened 1 year ago
Hi @Sash0check, currently flyleaf does not support transparency.
I have started experimenting with this, since I want to make the entire video semi transparent with something else sitting behind it, and that isn't possible currently either. It involves tinkering with things deep down in the rendering level though, including (probably) setting up a BlendState on the DirectX device context.
I think I've done it in the past, by settings the color.a to transparent in the pixel shader https://github.com/SuRGeoNix/Flyleaf/blob/master/FlyleafLib/MediaFramework/MediaRenderer/ShaderCompiler.cs#L367 and using the composition swap chain. I will need to review it and might added in the future.
In terms of making the video play with an overall opacity of <100% this turned out to be quite simple in the end, and did not involve changing the pixel shader or renderer code. All it needed was two things inside FlyleafHost:
The app level window that holds the FlyleafHost also needs to have Transparency enabled and Opacity=0 to get a fully translucent effect to desktop level.
Turning this from a PoC to a feature should make it possible to achieve fade-up/fade-down and cross-fade effects between overlapping players.
I don't know yet if the same thing will work with the WinFormsHost, that may still be subject to the classic WPF/WinForms airspace issue.
One thing it doesn't quite do is allow for the non-active portion of the player window to be totally transparent, as in when the video aspect doesn't fit the window shape. (Even though you can specify an alpha in the Player.Config.Video.BackgroundColour the renderer does not currently honour this, it just comes out solid but is subject to the alpha of the Surface behind it in the same way that the video itself is handled). As for videos that themselves contain an alpha channel, this doesn't currently work either for the same reason - may just need a bit more work on the pixel shader to handle the alpha plane.
@SuRGeoNix this commit[1b3f7a9] work with [Config.Video.BackgroundColor],but hope to set Transparent and mix with the host window background.i try to do everything(baidu、bing 、stackoverflow……),but come to nothing. however,can add "SoftwareHost"? like [ffmediaelement.ImageHost],it use “WriteableBitmap” for rendering.It works well with videos that have transparent channel. as a developer,you know,the designer,they are so stupid and think we create animation so easy.but sadly,most scene can not do as like as two peas.we have to got some shortcut.use the mov is the way.now i use ffmediaelement,but i find your project ,liked immediately when tried it.
oh,i got a way! #492
Hello! I can't cahnge opacity of player element in WPF. It works on child elements but video not. And second question: my transparent video in dxv format showing with black background can i fix this? Thanks