コード例 #1
0
        public static void Initialize()
        {
            spriteDrawer = new Sprite(Game.Device, 0);
            instances    = new Dictionary <string, CustomSpriteInstance>();
            coordiantes  = new Vector2(0.0f, 0.0f);
            dimensions   = new Vector2(1.0f, 1.0f);

            RasterizerStateDescription rsd = new RasterizerStateDescription();

            rsd.CullMode = CullMode.None;
            rsd.FillMode = FillMode.Solid;
            rs           = RasterizerState.FromDescription(Game.Device, rsd);

            BlendStateDescription bsd = new BlendStateDescription();

            bsd.SetBlendEnable(0, true);
            bsd.BlendOperation        = BlendOperation.Add;
            bsd.SourceBlend           = BlendOption.SourceAlpha;
            bsd.DestinationBlend      = BlendOption.InverseSourceAlpha;
            bsd.SourceAlphaBlend      = BlendOption.SourceAlpha;
            bsd.DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
            bsd.AlphaBlendOperation   = BlendOperation.Add;
            bsAlphaBlend = BlendState.FromDescription(Game.Device, bsd);

            bsd = new BlendStateDescription();
            bsd.SetBlendEnable(0, true);
            bsd.BlendOperation        = BlendOperation.Add;
            bsd.SourceBlend           = BlendOption.One;
            bsd.DestinationBlend      = BlendOption.One;
            bsd.SourceAlphaBlend      = BlendOption.One;
            bsd.DestinationAlphaBlend = BlendOption.One;
            bsd.AlphaBlendOperation   = BlendOperation.Add;
            bsAdditive = BlendState.FromDescription(Game.Device, bsd);
        }
コード例 #2
0
        private void CreateStates()
        {
            var blendStateDesc = new BlendStateDescription();

            blendStateDesc.BlendOperation           = BlendOperation.Add;
            blendStateDesc.AlphaBlendOperation      = BlendOperation.Add;
            blendStateDesc.SourceBlend              = BlendOption.One;
            blendStateDesc.DestinationBlend         = BlendOption.One;
            blendStateDesc.SourceAlphaBlend         = BlendOption.One;
            blendStateDesc.DestinationAlphaBlend    = BlendOption.Zero;
            blendStateDesc.IsAlphaToCoverageEnabled = false;
            blendStateDesc.SetBlendEnable(0, true);
            visualEffectsBlendState         = BlendState.FromDescription(renderer.Device, blendStateDesc);
            blendStateDesc.DestinationBlend = BlendOption.Zero;
            blenderBlendState = BlendState.FromDescription(renderer.Device, blendStateDesc);

            var rasterizerStateDesc = new RasterizerStateDescription();

            rasterizerStateDesc.CullMode = CullMode.None;
            rasterizerStateDesc.FillMode = FillMode.Solid;
            rasterizerStateDesc.IsAntialiasedLineEnabled = false;
            rasterizerStateDesc.IsMultisampleEnabled     = false;
            // TODO: probably use scissor test
            rasterizerStateDesc.IsScissorEnabled = false;
            rasterizerState = RasterizerState.FromDescription(renderer.Device, rasterizerStateDesc);

            var depthStencilStateDesc = new DepthStencilStateDescription();

            depthStencilStateDesc.IsDepthEnabled   = false;
            depthStencilStateDesc.IsStencilEnabled = false;
            depthStencilState = DepthStencilState.FromDescription(renderer.Device, depthStencilStateDesc);
        }
コード例 #3
0
 private static void SetDefaults(ref BlendStateDescription blendDesc)
 {
     for (uint i = 0; i < 8; i++)
     {
         blendDesc.SetWriteMask(i, ColorWriteMaskFlags.All);
         blendDesc.SetBlendEnable(i, true);
     }
 }
コード例 #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
        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;
        }
コード例 #6
0
ファイル: SimpleModel10Sample.cs プロジェクト: zhandb/slimdx
        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 );
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: Engine.cs プロジェクト: kpko/PhysX.Net
		private void InitalizeGraphics()
		{
			if (Window.RenderCanvasHandle == IntPtr.Zero)
				throw new InvalidOperationException();

			SwapChainDescription swapChainDesc = new SwapChainDescription()
			{
				BufferCount = 1,
				Flags = SwapChainFlags.None,
				IsWindowed = true,
				OutputHandle = Window.RenderCanvasHandle,
				SwapEffect = SwapEffect.Discard,
				Usage = Usage.RenderTargetOutput,
				ModeDescription = new ModeDescription()
				{
					Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
					//Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
					Width = (int)Window.RenderCanvasSize.Width,
					Height = (int)Window.RenderCanvasSize.Height,
					RefreshRate = new Rational(60, 1),
					Scaling = DisplayModeScaling.Unspecified,
					ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified
				},
				SampleDescription = new SampleDescription(1, 0)
			};

			var giFactory = new SlimDX.DXGI.Factory();
			var adapter = giFactory.GetAdapter(0);

			Device device;
			SwapChain swapChain;
			Device.CreateWithSwapChain(adapter, DriverType.Hardware, DeviceCreationFlags.Debug, swapChainDesc, out device, out swapChain);
			_swapChain = swapChain;
			GraphicsDevice = device;

			// create a view of our render target, which is the backbuffer of the swap chain we just created
			using (var resource = SlimDX.Direct3D10.Resource.FromSwapChain<Texture2D>(swapChain, 0))
			{
				_backBuffer = new RenderTargetView(device, resource);
			}

			// setting a viewport is required if you want to actually see anything
			var viewport = new Viewport(0, 0, (int)Window.RenderCanvasSize.Width, (int)Window.RenderCanvasSize.Height);
			device.OutputMerger.SetTargets(_backBuffer);
			device.Rasterizer.SetViewports(viewport);

			CreateDepthStencil();
			LoadVisualizationEffect();

			// Allocate a large buffer to write the PhysX visualization vertices into
			// There's more optimized ways of doing this, but for this sample a large buffer will do
			_userPrimitivesBuffer = new SlimDX.Direct3D10.Buffer(GraphicsDevice, VertexPositionColor.SizeInBytes * 50000, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None);

			var elements = new[]
			{
				new InputElement("Position", 0, Format.R32G32B32A32_Float, 0, 0),
				new InputElement("Color", 0, Format.R32G32B32A32_Float, 16, 0)
			};
			_inputLayout = new InputLayout(GraphicsDevice, _visualizationEffect.RenderScenePass0.Description.Signature, elements);

			// States
			var blendDesc = new BlendStateDescription()
			{
				SourceBlend = BlendOption.One,
				DestinationBlend = BlendOption.Zero,
				BlendOperation = BlendOperation.Add,
				SourceAlphaBlend = BlendOption.One,
				DestinationAlphaBlend = BlendOption.Zero,
				AlphaBlendOperation = BlendOperation.Add
			};
			blendDesc.SetBlendEnable(0, true);
			_blendState = BlendState.FromDescription(device, blendDesc);

			var rasterDesc = new RasterizerStateDescription()
			{
				IsAntialiasedLineEnabled = false,
				IsMultisampleEnabled = false,
				FillMode = FillMode.Solid,
				CullMode = CullMode.None
			};
			_rasterizerState = RasterizerState.FromDescription(device, rasterDesc);
		}
コード例 #9
0
ファイル: D3DScene.cs プロジェクト: treytomes/DirectCanvas
        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);
        }
コード例 #10
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();
        }
コード例 #11
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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        private void InitalizeGraphics()
        {
            if (Window.RenderCanvasHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException();
            }

            SwapChainDescription swapChainDesc = new SwapChainDescription()
            {
                BufferCount     = 1,
                Flags           = SwapChainFlags.None,
                IsWindowed      = true,
                OutputHandle    = Window.RenderCanvasHandle,
                SwapEffect      = SwapEffect.Discard,
                Usage           = Usage.RenderTargetOutput,
                ModeDescription = new ModeDescription()
                {
                    Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                    //Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
                    Width            = (int)Window.RenderCanvasSize.Width,
                    Height           = (int)Window.RenderCanvasSize.Height,
                    RefreshRate      = new Rational(60, 1),
                    Scaling          = DisplayModeScaling.Unspecified,
                    ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified
                },
                SampleDescription = new SampleDescription(1, 0)
            };

            var giFactory = new SlimDX.DXGI.Factory();
            var adapter   = giFactory.GetAdapter(0);

            Device    device;
            SwapChain swapChain;

            Device.CreateWithSwapChain(adapter, DriverType.Hardware, DeviceCreationFlags.Debug, swapChainDesc, out device, out swapChain);
            _swapChain     = swapChain;
            GraphicsDevice = device;

            // create a view of our render target, which is the backbuffer of the swap chain we just created
            using (var resource = SlimDX.Direct3D10.Resource.FromSwapChain <Texture2D>(swapChain, 0))
            {
                _backBuffer = new RenderTargetView(device, resource);
            }

            // setting a viewport is required if you want to actually see anything
            var viewport = new Viewport(0, 0, (int)Window.RenderCanvasSize.Width, (int)Window.RenderCanvasSize.Height);

            device.OutputMerger.SetTargets(_backBuffer);
            device.Rasterizer.SetViewports(viewport);

            CreateDepthStencil();
            LoadVisualizationEffect();

            // Allocate a large buffer to write the PhysX visualization vertices into
            // There's more optimized ways of doing this, but for this sample a large buffer will do
            _userPrimitivesBuffer = new SlimDX.Direct3D10.Buffer(GraphicsDevice, VertexPositionColor.SizeInBytes * 50000, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None);

            var elements = new[]
            {
                new InputElement("Position", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("Color", 0, Format.R32G32B32A32_Float, 16, 0)
            };

            _inputLayout = new InputLayout(GraphicsDevice, _visualizationEffect.RenderScenePass0.Description.Signature, elements);

            // States
            var blendDesc = new BlendStateDescription()
            {
                SourceBlend           = BlendOption.One,
                DestinationBlend      = BlendOption.Zero,
                BlendOperation        = BlendOperation.Add,
                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation   = BlendOperation.Add
            };

            blendDesc.SetBlendEnable(0, true);
            _blendState = BlendState.FromDescription(device, blendDesc);

            var rasterDesc = new RasterizerStateDescription()
            {
                IsAntialiasedLineEnabled = false,
                IsMultisampleEnabled     = false,
                FillMode = FillMode.Solid,
                CullMode = CullMode.None
            };

            _rasterizerState = RasterizerState.FromDescription(device, rasterDesc);
        }
コード例 #14
0
        private void CreateStates()
        {
            var blendStateDesc = new BlendStateDescription();
            blendStateDesc.BlendOperation = BlendOperation.Add;
            blendStateDesc.AlphaBlendOperation = BlendOperation.Add;
            blendStateDesc.SourceBlend = BlendOption.One;
            blendStateDesc.DestinationBlend = BlendOption.One;
            blendStateDesc.SourceAlphaBlend = BlendOption.One;
            blendStateDesc.DestinationAlphaBlend = BlendOption.Zero;
            blendStateDesc.IsAlphaToCoverageEnabled = false;
            blendStateDesc.SetBlendEnable(0, true);
            visualEffectsBlendState = BlendState.FromDescription(renderer.Device, blendStateDesc);
            blendStateDesc.DestinationBlend = BlendOption.Zero;
            blenderBlendState = BlendState.FromDescription(renderer.Device, blendStateDesc);

            var rasterizerStateDesc = new RasterizerStateDescription();
            rasterizerStateDesc.CullMode = CullMode.None;
            rasterizerStateDesc.FillMode = FillMode.Solid;
            rasterizerStateDesc.IsAntialiasedLineEnabled = false;
            rasterizerStateDesc.IsMultisampleEnabled = false;
            // TODO: probably use scissor test
            rasterizerStateDesc.IsScissorEnabled = false;
            rasterizerState = RasterizerState.FromDescription(renderer.Device, rasterizerStateDesc);

            var depthStencilStateDesc = new DepthStencilStateDescription();
            depthStencilStateDesc.IsDepthEnabled = false;
            depthStencilStateDesc.IsStencilEnabled = false;
            depthStencilState = DepthStencilState.FromDescription(renderer.Device, depthStencilStateDesc);
        }