private static DirectXTransformerPlaneData CreatePlane(DirectXContext dx, int width, int height, DirectXDownloaderFormatPlane plane)
        {
            var config = new DirectXPipelineConfig
            {
                VertexShaderFile     = "format_conversion.hlsl",
                VertexShaderFunction = plane.VS,
                PixelShaderFile      = "format_conversion.hlsl",
                PixelShaderFunction  = plane.PS,
            };

            var pipeline = new DirectXPipeline <ConverterFilterConstantBuffer>(config, dx);

            pipeline.SetDebugColor(0, 0, 0, 1);
            pipeline.SetPosition(DirectXPipelineConfig.FullRectangle, new Viewport(0, 0, width / plane.WidthFactor, height / plane.HeightFactor));
            var colorMatrix = ColorMatrices.GetInverted(ColorMatrices.Full709);
            var cm          = colorMatrix.Values;
            var cb          = new ConverterFilterConstantBuffer
            {
                width      = width,
                height     = height,
                width_i    = 1.0f / width,
                width_d2   = width / 2,
                height_d2  = height / 2,
                width_x2_i = 0.5f / width,

                color_vec0      = new Vector4(cm[0], cm[1], cm[2], cm[3]),
                color_vec1      = new Vector4(cm[4], cm[5], cm[6], cm[7]),
                color_vec2      = new Vector4(cm[8], cm[9], cm[10], cm[11]),
                color_range_min = new Vector3(0.0f, 0.0f, 0.0f),
                color_range_max = new Vector3(1.0f, 1.0f, 1.0f),
            };

            pipeline.SetConstantBuffer(cb, false);

            return(new DirectXTransformerPlaneData {
                Pipeline = pipeline, Format = plane.Format
            });
        }
 public DirectXFilterStage(DirectXContext dx, DirectXPipelineConfig config)
 {
     Dx       = dx.AddRef();
     Pipeline = new DirectXPipeline <TConstantBuffer>(config, Dx);
 }
示例#3
0
        public DirectXFilterStageLUT(DirectXContext dx, SharpDX.Direct3D11.Resource texture1, SharpDX.Direct3D11.Resource texture3, double amount, int size, DirectXPipelineConfig dxConfig, Vector3 domainMin, Vector3 domainMax) :
            base(dx, dxConfig)
        {
            _lutTexture1 = texture1;
            _lutTexture3 = texture3;
            float sz = size - 1.0f;
            var   cb = new LutFilterConstantBuffer
            {
                ViewProj     = Matrix.Identity,
                clut_amount  = (float)amount,
                clut_scale   = new Vector3(sz, sz, sz), //64-1
                clut_offset  = new Vector3(0, 0, 0),
                cube_width_i = 1.0f / size,
                domain_min   = domainMin,
                domain_max   = domainMax,
            };

            Pipeline.SetConstantBuffer(cb);
            Pipeline.SetDebugColor(1, 0.5f, 0, 1);
        }
示例#4
0
        public DirectXPipeline(DirectXPipelineConfig config, DirectXContext dx)
        {
            try
            {
                _dx = dx.AddRef();

                _vertexShaderByteCode = CompileOrGet(config.VertexShaderFile, config.VertexShaderFunction, dx.VertexProfile);
                _vertexShader         = new VertexShader(dx.Device, _vertexShaderByteCode);
                _vertexLayout         = new InputLayout(dx.Device, _vertexShaderByteCode, new[]
                {
                    new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                    new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0, InputClassification.PerVertexData, 0),
                });


                _pixelShaderByteCode = CompileOrGet(config.PixelShaderFile, config.PixelShaderFunction, dx.PixelProfile);
                _pixelShader         = new PixelShader(dx.Device, _pixelShaderByteCode);

                //ShaderReflection refl = new ShaderReflection(_pixelShaderByteCode);
                //var s1 = refl.GetConstantBuffer(0);
                //var a1 = s1.GetVariable(0);
                //var a2 = s1.GetVariable(1);
                //var a3 = s1.GetVariable(2);
                //var a4 = s1.GetVariable(3);
                //var a5 = s1.GetVariable(4);
                //var a6 = s1.GetVariable(5);
                //var a7 = s1.GetVariable(6);


                var blendStateDescription = new BlendStateDescription();

                if (config.Blend)
                {
                    blendStateDescription.RenderTarget[0].IsBlendEnabled        = true;
                    blendStateDescription.RenderTarget[0].SourceBlend           = BlendOption.SourceAlpha;
                    blendStateDescription.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
                    blendStateDescription.RenderTarget[0].BlendOperation        = BlendOperation.Add;
                    blendStateDescription.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
                    blendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
                    blendStateDescription.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Maximum;
                    blendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                    blendStateDescription.AlphaToCoverageEnable = false;
                    //_immediateContext.OutputMerger.BlendSampleMask = ~0;
                    //_immediateContext.OutputMerger.BlendFactor = new Color4(0, 0, 0, 0);
                }
                else
                {
                    blendStateDescription.RenderTarget[0].IsBlendEnabled        = false;
                    blendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                }
                _blendState = new BlendState(dx.Device, blendStateDescription);

                if (typeof(TConstantBuffer) != typeof(int))
                {
                    int size = Marshal.SizeOf <TConstantBuffer>();
                    _dynamicConstantBuffer = new SharpDX.Direct3D11.Buffer(_dx.Device, size, ResourceUsage.Dynamic, BindFlags.ConstantBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
                }
            }
            catch (Exception e)
            {
                _dx.Broken(e);
            }
        }