using SharpDX.Direct3D; using SharpDX.Direct3D11; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; namespace CustomResolution.Shaders; public class ExampleShader : MiniShader { public ExampleShader() : base("Example") { Constants = new(this); } public MiniShaderConstants Constants { get; private set; } public override void Dispose() { Constants.Dispose(); base.Dispose(); } public void Draw() { using MiniShaderState state = new(); state.SetShader(Ctx.VertexShader, VS); state.SetShader(Ctx.PixelShader, PS); state.SetShader(Ctx.GeometryShader, null); state.Set(Ctx.InputAssembler, nameof(Ctx.InputAssembler.PrimitiveTopology), PrimitiveTopology.TriangleList); state.SetConstantBuffer(Ctx.PixelShader, 0, Constants.Buffer); Ctx.PixelShader.SetConstantBuffer(0, Constants.Buffer); var blendDesc = Ctx.OutputMerger.BlendState.Description; blendDesc.RenderTarget[0].IsBlendEnabled = true; blendDesc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; blendDesc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; blendDesc.RenderTarget[0].BlendOperation = BlendOperation.Add; blendDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha; blendDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; blendDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Maximum; blendDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; using var blendState = new BlendState(Device, blendDesc); state.Set(Ctx.OutputMerger, nameof(Ctx.OutputMerger.BlendState), blendState); Ctx.Draw(3, 0); } [StructLayout(LayoutKind.Sequential)] public struct TConstants { public float Time; } }