Skip to content

Commit

Permalink
Renderer: Tries to support alpha channel (currently for RGBA) by blen…
Browse files Browse the repository at this point in the history
…ding [Related #332]
  • Loading branch information
SuRGeoNix committed Feb 1, 2024
1 parent c970e91 commit 1b3f7a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 14 additions & 3 deletions FlyleafLib/MediaFramework/MediaRenderer/Renderer.Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Vortice;
using Vortice.Direct3D;
using Vortice.Direct3D11;
using Vortice.DirectComposition;
using Vortice.DXGI;
using Vortice.DXGI.Debug;

Expand Down Expand Up @@ -50,6 +49,7 @@ public unsafe partial class Renderer
ID3D11Buffer vertexBuffer;
ID3D11InputLayout vertexLayout;
ID3D11RasterizerState rasterizerState;
ID3D11BlendState blendStateAlpha;

ID3D11VertexShader ShaderVS;
ID3D11PixelShader ShaderPS;
Expand All @@ -63,7 +63,6 @@ public unsafe partial class Renderer
internal object lockDevice = new();
bool isFlushing;


public void Initialize(bool swapChain = true)
{
lock (lockDevice)
Expand Down Expand Up @@ -213,7 +212,18 @@ public void Initialize(bool swapChain = true)
context.VSSetConstantBuffer(0, vsBuffer);
vsBufferData.mat = Matrix4x4.Identity;
context.UpdateSubresource(vsBufferData, vsBuffer);


var blendDesc = new BlendDescription();
blendDesc.RenderTarget[0].BlendEnable = true;
blendDesc.RenderTarget[0].SourceBlend = Blend.SourceAlpha;
blendDesc.RenderTarget[0].DestinationBlend = Blend.Zero;
blendDesc.RenderTarget[0].BlendOperation = BlendOperation.Add;
blendDesc.RenderTarget[0].SourceBlendAlpha = Blend.One;
blendDesc.RenderTarget[0].DestinationBlendAlpha = Blend.Zero;
blendDesc.RenderTarget[0].BlendOperationAlpha = BlendOperation.Add;
blendDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteEnable.All;
blendStateAlpha = Device.CreateBlendState(blendDesc);

InitializeVideoProcessor();
// TBR: Device Removal Event
//ID3D11Device4 device4 = Device.QueryInterface<ID3D11Device4>(); device4.RegisterDeviceRemovedEvent(..);
Expand Down Expand Up @@ -304,6 +314,7 @@ public void Dispose()
vertexLayout?.Dispose();
vertexBuffer?.Dispose();
rasterizerState?.Dispose();
blendStateAlpha?.Dispose();
DisposeSwapChain();

singleGpu?.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ internal bool ConfigPlanes() //bool isNewInput = true) // currently not used
textDesc[0].Format = srvDesc[0].Format = Format.R8G8B8A8_UNorm; // B8G8R8X8_UNorm for 0[rgb]?

string offsets = "";
for (int i=0; i<3; i++)
for (int i=0; i<4; i++)
offsets += pixelOffsets[(int) (VideoStream.PixelComps[i].offset / Math.Ceiling(VideoStream.PixelComp0Depth / 8.0))];

curPSUniqueId += offsets;

SetPS(curPSUniqueId, $"color = float4(Texture1.Sample(Sampler, input.Texture).{offsets}, 1.0);");
SetPS(curPSUniqueId, $"color = Texture1.Sample(Sampler, input.Texture).{offsets};");
}

// [BGR/RGB]16
Expand Down Expand Up @@ -357,6 +357,7 @@ internal bool ConfigPlanes() //bool isNewInput = true) // currently not used
textDesc[i].Format = srvDesc[i].Format = Format.R8_UNorm;
}

if (VideoStream.PixelPlanes != 4)
SetPS(curPSUniqueId, shader + @"
color.a = 1;
", defines);
Expand Down Expand Up @@ -555,6 +556,9 @@ internal bool ConfigPlanes() //bool isNewInput = true) // currently not used
color = float4(Texture1.Sample(Sampler, input.Texture).rgb, 1.0);
");
}

//AV_PIX_FMT_FLAG_ALPHA (currently used only for RGBA?)
context.OMSetBlendState(curPSCase == PSCase.RGBPacked || (curPSCase == PSCase.RGBPlanar && VideoStream.PixelPlanes == 4) ? blendStateAlpha : null);

Log.Debug($"Prepared planes for {VideoStream.PixelFormatStr} with {videoProcessor} [{curPSCase}]");

Expand Down

0 comments on commit 1b3f7a9

Please sign in to comment.