private static void SetDefaults(ref BlendStateDescription blendDesc)
 {
     for (uint i = 0; i < 8; i++)
     {
         blendDesc.SetWriteMask(i, ColorWriteMaskFlags.All);
         blendDesc.SetBlendEnable(i, true);
     }
 }
Пример #2
0
        protected override void OnResourceLoad()
        {
            CreatePrimaryRenderTarget();
            CreateDepthBuffer();

            var dssd = new DepthStencilStateDescription {
                IsDepthEnabled   = true,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Less
            };

            var solidParentOp = new BlendStateDescription();

            solidParentOp.SetBlendEnable(0, false);
            solidParentOp.SetWriteMask(0, ColorWriteMaskFlags.All);

            var transParentOp = new BlendStateDescription {
                AlphaBlendOperation      = BlendOperation.Add,
                BlendOperation           = BlendOperation.Add,
                DestinationAlphaBlend    = BlendOption.Zero,
                DestinationBlend         = BlendOption.One,
                IsAlphaToCoverageEnabled = false,
                SourceAlphaBlend         = BlendOption.Zero,
                SourceBlend = BlendOption.One,
            };

            transParentOp.SetBlendEnable(0, true);
            transParentOp.SetWriteMask(0, ColorWriteMaskFlags.All);

            transBlendState = BlendState.FromDescription(Context10.Device, transParentOp);
            solidBlendState = BlendState.FromDescription(Context10.Device, solidParentOp);

            depthStencilState = DepthStencilState.FromDescription(Context10.Device, dssd);

            jupiterMesh = new SimpleModel(Context10.Device, "SimpleModel10.fx", "jupiter.SMD", "jupiter.jpg");

            view = Matrix.LookAtLH(new Vector3(0, 160, 0), new Vector3(0, -128.0f, 0), -Vector3.UnitZ);
            jupiterMesh.Effect.GetVariableByName("view").AsMatrix().SetMatrix(view);

            proj = Matrix.PerspectiveFovLH(45.0f, WindowWidth / (float)WindowHeight, 1.0f, 1000.0f);
            jupiterMesh.Effect.GetVariableByName("proj").AsMatrix().SetMatrix(proj);
        }
Пример #3
0
        private void InitBlending()
        {
            BlendStateDescription statedescr = new BlendStateDescription();


            statedescr.SetBlendEnable(0, true);
            statedescr.SetWriteMask(0, SlimDX.Direct3D10.ColorWriteMaskFlags.All);

            statedescr.BlendOperation   = BlendOperation.Add;
            statedescr.DestinationBlend = SlimDX.Direct3D10.BlendOption.InverseSourceAlpha;
            statedescr.SourceBlend      = SlimDX.Direct3D10.BlendOption.SourceAlpha;

            statedescr.AlphaBlendOperation   = BlendOperation.Add;
            statedescr.DestinationAlphaBlend = SlimDX.Direct3D10.BlendOption.Zero;
            statedescr.SourceAlphaBlend      = SlimDX.Direct3D10.BlendOption.Zero;

            BlendState newstate = BlendState.FromDescription(device, statedescr);

            device.OutputMerger.BlendState = newstate;
        }
Пример #4
0
        protected override void OnResourceLoad() {
            CreatePrimaryRenderTarget();
            CreateDepthBuffer();

            var dssd = new DepthStencilStateDescription {
                IsDepthEnabled = true,
                IsStencilEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less
            };

            var solidParentOp = new BlendStateDescription();
            solidParentOp.SetBlendEnable( 0, false );
            solidParentOp.SetWriteMask( 0, ColorWriteMaskFlags.All );

            var transParentOp = new BlendStateDescription {
                AlphaBlendOperation = BlendOperation.Add,
                BlendOperation = BlendOperation.Add,
                DestinationAlphaBlend = BlendOption.Zero,
                DestinationBlend = BlendOption.One,
                IsAlphaToCoverageEnabled = false,
                SourceAlphaBlend = BlendOption.Zero,
                SourceBlend = BlendOption.One,
            };

            transParentOp.SetBlendEnable( 0, true );
            transParentOp.SetWriteMask( 0, ColorWriteMaskFlags.All );

            transBlendState = BlendState.FromDescription( Context10.Device, transParentOp );
            solidBlendState = BlendState.FromDescription( Context10.Device, solidParentOp );

            depthStencilState = DepthStencilState.FromDescription( Context10.Device, dssd );

            jupiterMesh = new SimpleModel( Context10.Device, "SimpleModel10.fx", "jupiter.SMD", "jupiter.jpg" );

            view = Matrix.LookAtLH( new Vector3( 0, 160, 0 ), new Vector3( 0, -128.0f, 0 ), -Vector3.UnitZ );
            jupiterMesh.Effect.GetVariableByName( "view" ).AsMatrix().SetMatrix( view );

            proj = Matrix.PerspectiveFovLH( 45.0f, WindowWidth / (float)WindowHeight, 1.0f, 1000.0f );
            jupiterMesh.Effect.GetVariableByName( "proj" ).AsMatrix().SetMatrix( proj );
        }
Пример #5
0
        /// <summary>
        /// Initializes device dependant resources.
        /// </summary>
        private void Initialize()
        {
            var device = m_directCanvasFactory.DeviceContext.Device;

            /* Here we create a new sampler for sampling input within
             * our pixel shader */
            var sampDesc = new SamplerDescription();
            sampDesc.AddressU = TextureAddressMode.Clamp;
            sampDesc.AddressV = TextureAddressMode.Clamp;
            sampDesc.AddressW = TextureAddressMode.Clamp;
            sampDesc.BorderColor = new Color4(0, 0, 0, 0).InternalColor4;
            sampDesc.ComparisonFunction = Comparison.Never;
            sampDesc.Filter = Filter.MinMagMipLinear;
            sampDesc.MaximumAnisotropy = 10;
            sampDesc.MaximumLod = float.MaxValue;
            sampDesc.MinimumLod = 0;
            sampDesc.MipLodBias = 0;
            m_linearSamplerState = SamplerState.FromDescription(device, sampDesc);

            sampDesc.Filter = Filter.MinMagMipPoint;
            m_pointSamplerState = SamplerState.FromDescription(device, sampDesc);

            /* Here we have a hard coded blend state.  This should be configurable in
             * the future. Like the composer has */
            var blendDesc = new BlendStateDescription();
            blendDesc.IsAlphaToCoverageEnabled = false;
            blendDesc.BlendOperation = BlendOperation.Add;
            blendDesc.AlphaBlendOperation = BlendOperation.Add;
            blendDesc.DestinationBlend = BlendOption.InverseSourceAlpha;
            blendDesc.DestinationAlphaBlend = BlendOption.One;
            blendDesc.SourceBlend = BlendOption.One;
            blendDesc.SourceAlphaBlend = BlendOption.One;

            for (uint i = 0; i < 8; i++)
            {
                blendDesc.SetWriteMask(i, ColorWriteMaskFlags.All);
                blendDesc.SetBlendEnable(i, true);
            }

            m_alphaBlendState = BlendState.FromDescription(device, blendDesc);
        }
Пример #6
0
        private void LoadResources()
        {
            var imageLayer = m_presenter.Factory.CreateDrawingLayerFromFile(@".\Assets\Nature Mountains photo.jpg");
            m_brush = m_presenter.Factory.CreateDrawingLayerBrush(imageLayer);
            m_brushD3D = m_presenter.Factory.CreateDrawingLayerBrush(m_layer);
            lastStopwatchValue = Stopwatch.GetTimestamp();

            CreateDepthBuffer();

            var dssd = new DepthStencilStateDescription
            {
                IsDepthEnabled = true,
                IsStencilEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less
            };

            var solidParentOp = new BlendStateDescription();
            solidParentOp.SetBlendEnable(0, false);
            solidParentOp.SetWriteMask(0, ColorWriteMaskFlags.All);

            var transParentOp = new BlendStateDescription
            {
                AlphaBlendOperation = BlendOperation.Add,
                BlendOperation = BlendOperation.Add,
                DestinationAlphaBlend = BlendOption.Zero,
                DestinationBlend = BlendOption.One,
                IsAlphaToCoverageEnabled = false,
                SourceAlphaBlend = BlendOption.Zero,
                SourceBlend = BlendOption.One,
            };

            transParentOp.SetBlendEnable(0, true);
            transParentOp.SetWriteMask(0, ColorWriteMaskFlags.All);

            transBlendState = BlendState.FromDescription(m_device, transParentOp);
            solidBlendState = BlendState.FromDescription(m_device, solidParentOp);

            depthStencilState = DepthStencilState.FromDescription(m_device, dssd);
            
            textTex = Texture2D.FromPointer(m_layerText.Texture2DComPointer);
            jupiterTex = Texture2D.FromFile(m_device, "jupiter.jpg");

            jupiterMesh = new SimpleModel(m_device, "SimpleModel10.fx", "jupiter.SMD", jupiterTex);

            view = Matrix.LookAtLH(new Vector3(0, 160, 0), new Vector3(0, -128.0f, 0), -Vector3.UnitZ);
            jupiterMesh.Effect.GetVariableByName("view").AsMatrix().SetMatrix(view);

            proj = Matrix.PerspectiveFovLH(45.0f, m_presenter.Width / (float)m_presenter.Height, 1.0f, 1000.0f);
            jupiterMesh.Effect.GetVariableByName("proj").AsMatrix().SetMatrix(proj);
        }
Пример #7
0
        public void Reset()
        {
            Destroy();

            using (Factory factory = new Factory())
            {
                SlimDX.Direct3D10.Device.CreateWithSwapChain(factory.GetAdapter(0), DriverType.Hardware, DeviceCreationFlags.None, new SwapChainDescription
                {
                    BufferCount       = 2,
                    IsWindowed        = true,
                    OutputHandle      = renderTarget.Handle,
                    Usage             = Usage.RenderTargetOutput,
                    SampleDescription = new SampleDescription(1, 0),
                    ModeDescription   = new ModeDescription(renderTarget.Width, renderTarget.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm)
                }, out device, out swapChain);
            }

            using (Texture2D backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0))
            {
                renderTargetView = new RenderTargetView(device, backBuffer);
            }
            device.OutputMerger.SetTargets(renderTargetView);

            bsd = new BlendStateDescription();
            bsd.AlphaBlendOperation   = BlendOperation.Add;
            bsd.BlendOperation        = BlendOperation.Add;
            bsd.SourceBlend           = BlendOption.SourceAlpha;
            bsd.DestinationBlend      = BlendOption.InverseSourceAlpha;
            bsd.SourceAlphaBlend      = BlendOption.SourceAlpha;
            bsd.DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
            bsd.SetWriteMask(0, ColorWriteMaskFlags.All);
            bsd.IsAlphaToCoverageEnabled = true;
            bsd.SetBlendEnable(0, true);

            device.OutputMerger.BlendSampleMask = -1;
            device.OutputMerger.BlendFactor     = new Color4(0, 0, 0, 0);
            device.OutputMerger.BlendState      = BlendState.FromDescription(device, bsd);

            viewport = new Viewport(0, 0, renderTarget.Width, renderTarget.Height);
            device.Rasterizer.SetViewports(viewport);

            BufferDescription bd = new BufferDescription(4 * Marshal.SizeOf(typeof(Vertex)), ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None);

            vertexBuffer = new SlimDX.Direct3D10.Buffer(device, bd);

            Vertex[] vertexData = new Vertex[4];
            vertexData[0].pos      = new Vector3(-1, -1, 0);
            vertexData[0].texCoord = new Vector2(0, 1);
            vertexData[1].pos      = new Vector3(-1, 1, 0);
            vertexData[1].texCoord = new Vector2(0, 0);
            vertexData[2].pos      = new Vector3(1, -1, 0);
            vertexData[2].texCoord = new Vector2(1, 1);
            vertexData[3].pos      = new Vector3(1, 1, 0);
            vertexData[3].texCoord = new Vector2(1, 0);

            DataStream vbStream = vertexBuffer.Map(MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None);

            vbStream.WriteRange(vertexData);
            vertexBuffer.Unmap();

            System.Reflection.Assembly thisExe;
            thisExe = System.Reflection.Assembly.GetExecutingAssembly();
            Stream file = thisExe.GetManifestResourceStream("DirectXEmu.Video.Shaders.SimpleRender.fx");

            effect = Effect.FromStream(device, file, "fx_4_0");
            file.Close();

            EffectTechnique technique;

            if (smoothOutput)
            {
                technique = effect.GetTechniqueByName("RenderSmooth");
            }
            else
            {
                technique = effect.GetTechniqueByName("Render");
            }

            pass = technique.GetPassByIndex(0);

            ShaderSignature signature = pass.Description.Signature;

            inputLayout = new InputLayout(device, signature, new[] {
                new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32_Float, 12, 0)
            });

            texture = new Texture2D(device, new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.ShaderResource,
                CpuAccessFlags    = CpuAccessFlags.Write,
                Format            = Format.R8G8B8A8_UNorm,
                Height            = imageScaler.ResizedY,
                Width             = imageScaler.ResizedX,
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Dynamic
            });

            textureView = new ShaderResourceView(device, texture);
            effect.GetVariableByName("tex2d").AsResource().SetResource(textureView);


            LoadCharSheet();
        }
Пример #8
0
        private void EnableAlphaBlending()
        {
            BlendStateDescription blendState = new BlendStateDescription()
            {
                BlendOperation = BlendOperation.Add,
                SourceBlend = BlendOption.SourceAlpha,
                DestinationBlend = BlendOption.InverseSourceAlpha,
                IsAlphaToCoverageEnabled = false,
                AlphaBlendOperation = BlendOperation.Add,
                SourceAlphaBlend = BlendOption.Zero,
                DestinationAlphaBlend = BlendOption.Zero,

            };
            blendState.SetBlendEnable(0, true);
            blendState.SetWriteMask(0, ColorWriteMaskFlags.All);
            device.OutputMerger.BlendState = BlendState.FromDescription(device, blendState);
        }
        public override void Render(Device device,
                                    SlimDX.Matrix viewMatrix)
        {
            var globals = new VertexShaderGlobals();

            globals.WorldViewProj = viewMatrix;
            globals.World         = SlimDX.Matrix.Identity;
            this._VertexShaderConstantBuffer1.Update(globals);

            device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);

            device.VertexShader.Set(this._ShaderLoader.VertexShader);
            device.VertexShader.SetConstantBuffer(this._VertexShaderConstantBuffer1.Buffer, 1);

            var globalConsts = new PixelShaderGlobalConstants();

            globalConsts.Globals     = new ShaderNatives.float4[15];
            globalConsts.Globals[0]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[1]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[2]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[3]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[4]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[5]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[6]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[7]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[8]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[9]  = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[10] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[11] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[12] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[13] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);
            globalConsts.Globals[14] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f);

            this._PixelShaderConstantBuffer0.Update(globalConsts);

            var instanceConsts = new PixelShaderInstanceConstants();

            instanceConsts.InstanceConstants    = new ShaderNatives.float4[3];
            instanceConsts.InstanceConstants[0] = new ShaderNatives.float4(0.0f, 1.0f, 1.0f, 1.0f);
            instanceConsts.InstanceConstants[1] = new ShaderNatives.float4(1.0f, 1.0f, 0.0f, 0.8f);
            this._PixelShaderConstantBuffer1.Update(instanceConsts);

            var materialConsts = new PixelShaderMaterialConstants();

            materialConsts.MaterialConstants = new ShaderNatives.float4[3];
            for (int i = 0; i < 3; i++)
            {
                materialConsts.MaterialConstants[i] = new ShaderNatives.float4(1.0f, 1.0f, 0.0f, 1.0f);
            }
            this._PixelShaderConstantBuffer2.Update(materialConsts);

            var bs = new PixelShaderBooleans();

            bs.Bools      = new ShaderNatives.bool4[4];
            bs.Bools[3].X = true;
            bs.Bools[3].Y = true;
            bs.Bools[3].Z = false;
            this._PixelShaderConstantBuffer4.Update(bs);

            device.PixelShader.Set(this._ShaderLoader.PixelShader);
            device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer0.Buffer, 0);
            device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer1.Buffer, 1);
            device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer2.Buffer, 2);
            device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer4.Buffer, 4);

            this._MaterialLoader.SetShaderResource(device);

            device.InputAssembler.SetInputLayout(this._ShaderLoader.InputLayout);
            device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this._VertexData0Buffer, 48, 0));
            device.InputAssembler.SetIndexBuffer(this._IndexBuffer, DXGI.Format.R16_UInt, 0);

            var bsd = new BlendStateDescription()
            {
                IsAlphaToCoverageEnabled = true,

                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation   = BlendOperation.Add,

                SourceBlend      = BlendOption.SourceAlpha,
                DestinationBlend = BlendOption.Zero,
                BlendOperation   = BlendOperation.Add,
            };

            bsd.SetBlendEnable(0, true);
            bsd.SetWriteMask(0, ColorWriteMaskFlags.All);

            device.OutputMerger.BlendState = BlendState.FromDescription(device, bsd);

            device.DrawIndexed(this.Block.Faces.Count, 0, 0);
        }