public Direct3DRenderer()
        {
            _device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);
            _rasterizerStateDescription = new RasterizerStateDescription()
            {
                CullMode = SlimDX.Direct3D10.CullMode.None,
                FillMode = FillMode.Solid,
                IsFrontCounterclockwise = true
            };
            var rasterizerState = RasterizerState.FromDescription(_device, _rasterizerStateDescription);

            _device.Rasterizer.State = rasterizerState;

            _depthStencilStateDescription = new DepthStencilStateDescription()
            {
                IsDepthEnabled  = true,
                DepthComparison = Comparison.Less,
                DepthWriteMask  = DepthWriteMask.All
            };
            var depthStencilState = DepthStencilState.FromDescription(_device, _depthStencilStateDescription);

            _device.OutputMerger.DepthStencilState = depthStencilState;

            _semanticsTable.Add("inPosition", "POSITION");
            _semanticsTable.Add("inNormal", "NORMAL");
            _semanticsTable.Add("inTextureCoords", "TEXCOORD");
            _semanticsTable.Add("instanceMatrix", "INSTANCE_TRANSFORM");
        }
Beispiel #2
0
        public override bool Init()
        {
            if (!base.Init())
            {
                return(false);
            }

            _waves.Init(200, 200, 0.8f, 0.03f, 3.25f, 0.4f);

            BuildLandGeometryBuffers();
            BuildWavesGeometryBuffers();
            BuildFX();
            BuildVertexLayout();

            var wireFrameDesc = new RasterizerStateDescription {
                FillMode = FillMode.Wireframe,
                CullMode = CullMode.Back,
                IsFrontCounterclockwise = false,
                IsDepthClipEnabled      = true
            };

            _wireframeRS = RasterizerState.FromDescription(Device, wireFrameDesc);


            return(true);
        }
Beispiel #3
0
        private void InitializeDevices()
        {
            InitializeMatricies();
            //3DCGの初期化
            if (DeviceManager == null)
            {
                disposeDeviceManager = true;
                DeviceManager        = new BasicGraphicDeviceManager();
                DeviceManager.Load();
            }
            RasterizerStateDescription desc = new RasterizerStateDescription();

            desc.CullMode             = CullMode.Back;
            desc.FillMode             = FillMode.Solid;
            CullingRasterizerState    = RasterizerState.FromDescription(DeviceManager.Device, desc);
            desc.CullMode             = CullMode.None;
            NonCullingRasterizerState = RasterizerState.FromDescription(DeviceManager.Device, desc);

            //DirectWriteファクトリの作成
#if VSG_DEBUG
#else
            DWFactory  = new SlimDX.DirectWrite.Factory(FactoryType.Isolated);
            D2DFactory = new Factory(SlimDX.Direct2D.FactoryType.Multithreaded, DebugLevel.Information);
#endif
        }
Beispiel #4
0
        private void BeginScene()
        {
            // make sure buffers are initialized with current size
            EnsureOutputBuffers();

            // bind the views to the output merger stage
            _dxDevice.OutputMerger.SetTargets(_dxDepthStencilView, _dxRenderView);

            // clear buffers
            _dxDevice.ClearDepthStencilView(_dxDepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
            _dxDevice.ClearRenderTargetView(_dxRenderView, new Color4(0f, 0, 0, 0)); // uses transparent color

            // set rasterization parameters
            var rsd = new RasterizerStateDescription
            {
                //IsAntialiasedLineEnabled = true,
                IsFrontCounterclockwise = false,
                CullMode = CullMode.None,
                FillMode = (_wireframe) ? FillMode.Wireframe : FillMode.Solid
            };

            RasterizerState rsdState = RasterizerState.FromDescription(_dxDevice, rsd);

            _dxDevice.Rasterizer.State = rsdState;

            // set viewport
            _dxDevice.Rasterizer.SetViewports(new Viewport(0, 0, ClientWidth, ClientHeight, 0.0f, 1.0f));
        }
Beispiel #5
0
        private void InitializeDevices()
        {
            InitializeMatricies();
            //Initializing the 3D CG
            if (this.DeviceManager == null)
            {
                this.disposeDeviceManager = true;
                this.DeviceManager        = new BasicGraphicDeviceManager();
                this.DeviceManager.Load();
            }
            RasterizerStateDescription desc = new RasterizerStateDescription();

            desc.CullMode = CullMode.Back;
            desc.FillMode = FillMode.Solid;
            this.CullingRasterizerState = RasterizerState.FromDescription(this.DeviceManager.Device, desc);
            desc.CullMode = CullMode.None;
            this.NonCullingRasterizerState = RasterizerState.FromDescription(this.DeviceManager.Device, desc);

            //Creation of DirectWrite factory
#if VSG_DEBUG
#else
            this.DWFactory  = new SlimDX.DirectWrite.Factory(FactoryType.Isolated);
            this.D2DFactory = new Factory(SlimDX.Direct2D.FactoryType.Multithreaded, DebugLevel.Information);
#endif
        }
Beispiel #6
0
        protected void SetupRenderer()
        {
            try
            {
                Renderable.Initialize(Device);
                FieldPlane.Initialize();
                ColorMapping.Initialize(Device);
                PointCloud.Initialize();
                LineBall.Initialize();
                Mesh.Initialize();


                Device.ImmediateContext.OutputMerger.SetTargets(_host.RenderTargetView);
                Device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, _host.RenderTargetWidth, _host.RenderTargetHeight, 0.0f, 1.0f));

                _renderables = new List <Renderable>();
                Camera       = new Camera(Device, ((float)_host.RenderTargetWidth) / _host.RenderTargetHeight);
                var desc = new RasterizerStateDescription {
                    CullMode = CullMode.None, FillMode = FillMode.Solid
                };
                Device.ImmediateContext.Rasterizer.State = RasterizerState.FromDescription(Device, desc);

                SetupCuda();
                AlgorithmCuda.Initialize(ContextCuda, Device);
                FlowMapUncertain.Initialize();
                CutDiffusion.Initialize();
                LocalDiffusion.Initialize();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        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);
        }
Beispiel #8
0
        protected override void DrawOverride()
        {
            using (var rasterizerState = RasterizerState.FromDescription(Device, new RasterizerStateDescription {
                FillMode = FillMode.Wireframe,
                CullMode = CullMode.None,
                IsAntialiasedLineEnabled = UseAntialiazing,
                IsFrontCounterclockwise = false,
                IsDepthClipEnabled = true
            })) {
                DeviceContext.OutputMerger.BlendState = null;
                DeviceContext.Rasterizer.State        = rasterizerState;
                DeviceContext.ClearRenderTargetView(RenderTargetView, Color.Transparent);

                using (var buffer = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm)) {
                    buffer.Resize(DeviceContextHolder, Width, Height, null);

                    DeviceContext.ClearRenderTargetView(buffer.TargetView, Color.Transparent);
                    DeviceContext.OutputMerger.SetTargets(buffer.TargetView);

                    RenderUv();

                    DeviceContext.Rasterizer.State = null;

                    PrepareForFinalPass();
                    if (UseFxaa)
                    {
                        DeviceContextHolder.GetHelper <FxaaHelper>().Draw(DeviceContextHolder, buffer.View, RenderTargetView);
                    }
                    else
                    {
                        DeviceContextHolder.GetHelper <CopyHelper>().Draw(DeviceContextHolder, buffer.View, RenderTargetView);
                    }
                }
            }
        }
Beispiel #9
0
        public D3DManager(Form renderForm)
        {
            if (renderForm == null)
            {
                throw new ArgumentNullException("renderForm");
            }

            var swapChainDescription = new SwapChainDescription {
                BufferCount       = 1,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription(renderForm.ClientSize.Width, renderForm.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                OutputHandle      = renderForm.Handle,
                SampleDescription = new SampleDescription(4, 4),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, swapChainDescription, out Device, out SwapChain);

            SwapChain.GetParent <Factory>().SetWindowAssociation(renderForm.Handle, WindowAssociationFlags.IgnoreAll);

            CreateRenderTargets(renderForm.ClientSize.Width, renderForm.ClientSize.Height);

            Device.ImmediateContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView);

            Device.ImmediateContext.Rasterizer.State = RasterizerState.FromDescription(Device,
                                                                                       new RasterizerStateDescription {
                CullMode             = CullMode.Back,
                FillMode             = FillMode.Solid,
                IsMultisampleEnabled = true
            });
        }
Beispiel #10
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);
        }
Beispiel #11
0
        void DxInitStuff()
        {
            _effectTest   = new EffectTest(CurrentDevice);
            _effectScreen = new EffectScreen(CurrentDevice);

            _squareBuffers = new SquareBuffers(CurrentDevice);

            _wireframeRs = RasterizerState.FromDescription(CurrentDevice, new RasterizerStateDescription {
                FillMode = FillMode.Wireframe,
                CullMode = CullMode.Back,
                IsFrontCounterclockwise = false,
                IsDepthClipEnabled      = true
            });

            var transDesc = new BlendStateDescription {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false
            };

            transDesc.RenderTargets[0].BlendEnable           = true;
            transDesc.RenderTargets[0].SourceBlend           = BlendOption.SourceAlpha;
            transDesc.RenderTargets[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
            transDesc.RenderTargets[0].BlendOperation        = BlendOperation.Add;
            transDesc.RenderTargets[0].SourceBlendAlpha      = BlendOption.One;
            transDesc.RenderTargets[0].DestinationBlendAlpha = BlendOption.One;
            transDesc.RenderTargets[0].BlendOperationAlpha   = BlendOperation.Add;
            transDesc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;

            _transparentBlendState = BlendState.FromDescription(CurrentDevice, transDesc);
        }
Beispiel #12
0
        private void Init(string name, InputElement[] inplElems, FillMode fillMode, bool geometryShader)
        {
            geom = geometryShader;
            //Shaders
            using (var b = ShaderBytecode.CompileFromFile("Shaders\\" + name + "Shader.fx", "vs", "vs_4_0", ShaderFlags.None, EffectFlags.None))
            {
                Sig = ShaderSignature.GetInputSignature(b);
                VS  = new VertexShader(Renderer.viewport.Device, b);
            }
            using (var b = ShaderBytecode.CompileFromFile("Shaders\\" + name + "Shader.fx", "ps", "ps_4_0", ShaderFlags.None, EffectFlags.None))
            {
                PS = new PixelShader(Renderer.viewport.Device, b);
            }
            if (geometryShader)
            {
                using (var b = ShaderBytecode.CompileFromFile("Shaders\\" + name + "Shader.fx", "gs", "gs_4_0", ShaderFlags.None, EffectFlags.None))
                {
                    GS_Tri = new GeometryShader(Renderer.viewport.Device, b);
                }
            }
            //InputLayout
            Inpl = new InputLayout(Renderer.viewport.Device, Sig, inplElems);

            //Rasterizer state
            var wireFrameDesc = new RasterizerStateDescription
            {
                FillMode = fillMode,
                CullMode = CullMode.None,
                IsFrontCounterclockwise = false,
                IsDepthClipEnabled      = true
            };

            RS = RasterizerState.FromDescription(Renderer.viewport.Device, wireFrameDesc);
        }
Beispiel #13
0
        public void InitializeD3D()
        {
            var swapChainDesc = new SwapChainDescription()
            {
                BufferCount       = 2, // 2 back buffers (a.k.a. Triple Buffering).
                Usage             = Usage.RenderTargetOutput,
                OutputHandle      = FormObject.Handle,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags             = SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SwapEffect.Discard
            };

            if (Device.CreateWithSwapChain(DriverType.Hardware,
                                           DeviceCreationFlags.Debug,
                                           new FeatureLevel[] { FeatureLevel.Level_11_0 },
                                           swapChainDesc,
                                           out _device,
                                           out _swapChain).IsFailure)
            {
                throw new Exception("Error creating swap chain");
            }

            using (var resource = Resource.FromSwapChain <Texture2D>(_swapChain, 0))
            {
                _renderTargetView = new RenderTargetView(_device, resource);
            };

            _deviceContext = _device.ImmediateContext;

            _viewport = new Viewport(0.0f,
                                     0.0f,
                                     FormObject.Width,
                                     FormObject.Height,
                                     0.0f,
                                     1.0f);

            _rasterizerDescription = new RasterizerStateDescription()
            {
                CullMode = CullMode.None,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = true,
                IsFrontCounterclockwise  = true,
                IsMultisampleEnabled     = true,
                IsDepthClipEnabled       = true,
                IsScissorEnabled         = false
            };

            _deviceContext.Rasterizer.State = RasterizerState.FromDescription(_device, _rasterizerDescription);

            _deviceContext.Rasterizer.SetViewports(_viewport);
            _deviceContext.OutputMerger.SetTargets(_renderTargetView);

            // Prevent DXGI handling of Alt+Enter since it does not work properly with Winforms
            using (var factory = _swapChain.GetParent <Factory>())
            {
                factory.SetWindowAssociation(FormObject.Handle, WindowAssociationFlags.IgnoreAltEnter);
            };
        }
        public void EnableWireframe(bool enable)
        {
            _rasterizerStateDescription.FillMode = enable ? FillMode.Wireframe : FillMode.Solid;
            var rasterizerState = RasterizerState.FromDescription(_device, _rasterizerStateDescription);

            _device.Rasterizer.State = rasterizerState;
        }
Beispiel #15
0
        /// <summary>
        /// Initialise the device and set up a render window
        /// </summary>
        public static RenderForm InitD3D(
            out SlimDX.Direct3D11.Device device,
            out SwapChain swapChain,
            out RenderTargetView renderView)
        {
            var form = new RenderForm("Solar simulation");

            form.Width  = 1080;
            form.Height = 1080;

            var desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            SlimDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain);

            Factory factory = swapChain.GetParent <Factory>();

            factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);

            RasterizerStateDescription rsd = new RasterizerStateDescription()
            {
                CullMode                 = CullMode.None,
                DepthBias                = 0,
                DepthBiasClamp           = 0.0f,
                FillMode                 = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled       = false,
                IsFrontCounterclockwise  = false,
                IsMultisampleEnabled     = false,
                IsScissorEnabled         = false,
                SlopeScaledDepthBias     = 0.0f
            };

            RasterizerState rs = RasterizerState.FromDescription(device, rsd);

            device.ImmediateContext.Rasterizer.State = rs;


            Texture2D backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0);

            renderView = new RenderTargetView(device, backBuffer);

            device.ImmediateContext.OutputMerger.SetTargets(renderView);
            device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));

            rs.Dispose();
            backBuffer.Dispose();

            return(form);
        }
Beispiel #16
0
 private void ChangeWireFrame(bool enabled)
 {
     _device.ImmediateContext.Rasterizer.State = RasterizerState.FromDescription(_device,
                                                                                 new RasterizerStateDescription {
         CullMode             = CullMode.Back,
         FillMode             = enabled ? FillMode.Wireframe : FillMode.Solid,
         IsMultisampleEnabled = true
     });
 }
        private Texture2D CreateTexture(int width, int height, bool multiSampling)
        {
            var description = new SlimDX.Direct3D10.Texture2DDescription();

            description.ArraySize      = 1;
            description.BindFlags      = SlimDX.Direct3D10.BindFlags.RenderTarget | SlimDX.Direct3D10.BindFlags.ShaderResource;
            description.CpuAccessFlags = CpuAccessFlags.None;
            description.Format         = Format.B8G8R8A8_UNorm;
            description.MipLevels      = 1;
            //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared;

            // Multi-sample anti-aliasing
            //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared;
            int count;

            if (multiSampling)
            {
                count = 8;
            }
            else
            {
                count = 1;
            }
            int quality = device.CheckMultisampleQualityLevels(description.Format, count);

            if (count == 1)
            {
                quality = 1;
            }
            // Multi-sample anti-aliasing
            SampleDescription sampleDesc = new SampleDescription(count, 0);

            description.SampleDescription = sampleDesc;

            RasterizerStateDescription rastDesc = new RasterizerStateDescription();

            rastDesc.CullMode                 = CullMode.Back;
            rastDesc.FillMode                 = FillMode.Solid;
            rastDesc.IsMultisampleEnabled     = false;
            rastDesc.IsAntialiasedLineEnabled = false;
            //rastDesc.DepthBias = 0;
            //rastDesc.DepthBiasClamp = 0;
            //rastDesc.IsDepthClipEnabled = true;
            //rastDesc.IsFrontCounterclockwise = false;
            //rastDesc.IsScissorEnabled = true;
            //rastDesc.SlopeScaledDepthBias = 0;

            device.Rasterizer.State = RasterizerState.FromDescription(device, rastDesc);

            description.Usage       = ResourceUsage.Default;
            description.OptionFlags = ResourceOptionFlags.Shared;
            description.Height      = (int)height;
            description.Width       = (int)width;

            return(new Texture2D(device, description));
        }
Beispiel #18
0
        private void OnViewportInitialized(object sender, RenderEventArgs e)
        {
            var rsd = new RasterizerStateDescription();

            rsd.FillMode              = FillMode.Solid;
            rsd.CullMode              = CullMode.None;
            rsd.IsDepthClipEnabled    = true;
            rsd.IsMultisampleEnabled  = true;
            e.Device.Rasterizer.State = RasterizerState.FromDescription(
                e.Device, rsd);
        }
Beispiel #19
0
 public void Initialize(IDeviceContextHolder contextHolder)
 {
     _effect          = contextHolder.GetEffect <EffectDeferredGSky>();
     _rasterizerState = RasterizerState.FromDescription(contextHolder.Device, new RasterizerStateDescription {
         FillMode = FillMode.Solid,
         CullMode = CullMode.Front,
         IsAntialiasedLineEnabled = false,
         IsFrontCounterclockwise  = false,
         IsDepthClipEnabled       = true
     });
 }
Beispiel #20
0
 private static void InitializeRasterizer()
 {
     Rasterizer = new RasterizerStateDescription()
     {
         FillMode = FillMode.Solid,
         CullMode = CullMode.Back,
         IsFrontCounterclockwise = false,
         IsDepthClipEnabled      = true
     };
     DeviceContext.Rasterizer.State = RasterizerState.FromDescription(Device, Rasterizer);
 }
Beispiel #21
0
        /// <summary>
        /// Updates the rasterizer state for the rasterizer stage of the pipeline.
        /// </summary>
        void UpdateRasterizerState()
        {
            var rs    = RasterizerState.FromDescription(device, rsDescription);
            var oldRs = Context.Rasterizer.State;

            Context.Rasterizer.State = rs;
            if (oldRs != null)
            {
                oldRs.Dispose();
            }
        }
Beispiel #22
0
 public static void SetCullingMode(SlimDX.Direct3D11.CullMode mode, FillMode filleMode = FillMode.Solid)
 {
     // http://memeplex.blog.shinobi.jp/directx11/c-%E3%81%A7directx11%20slimdx%E3%83%81%E3%ぷbl83%A5%E3%83%BC%E3%83%88%E3%83%AA%E3%82%A2%E3%83%AB%E3%81%9D%E3%81%AE12%20%E3%83%AF%E3%82%A4%E3%83%A4%E3%83%BC%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0
     ImmediateContext.Rasterizer.State = RasterizerState.FromDescription(
         Device,
         new RasterizerStateDescription()
     {
         CullMode = mode,
         FillMode = filleMode
     }
         );
 }
Beispiel #23
0
        private void InitializeBuffers()
        {
            _shadowBuffer = TargetResourceDepthTexture.Create();
            _bufferFSumm  = TargetResourceTexture.Create(Format.R32G32B32A32_Float);
            _bufferF1     = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _bufferF2     = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _bufferA      = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);

            _summBlendState = Device.CreateBlendState(new RenderTargetBlendDescription {
                BlendEnable           = true,
                SourceBlend           = BlendOption.One,
                DestinationBlend      = BlendOption.One,
                BlendOperation        = BlendOperation.Add,
                SourceBlendAlpha      = BlendOption.One,
                DestinationBlendAlpha = BlendOption.One,
                BlendOperationAlpha   = BlendOperation.Add,
                RenderTargetWriteMask = ColorWriteMaskFlags.All,
            });

            _bakedBlendState = Device.CreateBlendState(new RenderTargetBlendDescription {
                BlendEnable           = true,
                SourceBlend           = BlendOption.One,
                DestinationBlend      = BlendOption.One,
                BlendOperation        = BlendOperation.Maximum,
                SourceBlendAlpha      = BlendOption.One,
                DestinationBlendAlpha = BlendOption.One,
                BlendOperationAlpha   = BlendOperation.Maximum,
                RenderTargetWriteMask = ColorWriteMaskFlags.All,
            });

            _effect = DeviceContextHolder.GetEffect <EffectSpecialShadow>();

            _rasterizerStateFrontCull = RasterizerState.FromDescription(Device, new RasterizerStateDescription {
                CullMode = CullMode.Front,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled       = true,
                DepthBias            = (int)(100 * ShadowBiasCullFront),
                DepthBiasClamp       = 0.0f,
                SlopeScaledDepthBias = ShadowBiasCullFront
            });

            _rasterizerStateBackCull = RasterizerState.FromDescription(Device, new RasterizerStateDescription {
                CullMode = CullMode.Back,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled       = true,
                DepthBias            = (int)(100 * ShadowBiasCullBack),
                DepthBiasClamp       = 0.0f,
                SlopeScaledDepthBias = ShadowBiasCullBack
            });
        }
Beispiel #24
0
        /// <summary>
        /// Dessine cette cellule.
        /// </summary>
        public void Draw()
        {
            // Dessine la cellule.
            var device = Scene.GetGraphicsDevice().ImmediateContext;

            device.InputAssembler.SetIndexBuffer(Generation.ModelGenerator.GetIndexBuffer(GridResolution), Format.R32_UInt, 0);
            device.InputAssembler.PrimitiveTopology = (PrimitiveTopology.TriangleList);
            device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_vBuffer, Graphics.VertexPositionTextureNormal.Vertex.Stride, 0));
            RasterizerStateDescription rsd = new RasterizerStateDescription()
            {
                CullMode                 = CullMode.Front,
                DepthBias                = 0,
                DepthBiasClamp           = 0.0f,
                FillMode                 = FillMode.Solid,
                IsAntialiasedLineEnabled = true,
                IsDepthClipEnabled       = true,
                IsFrontCounterclockwise  = false,
                IsMultisampleEnabled     = false,
                IsScissorEnabled         = false,
                SlopeScaledDepthBias     = 0.0f
            };

            // Alpha blending
            var transDesc = new BlendStateDescription
            {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false
            };

            transDesc.RenderTargets[0].BlendEnable           = true;
            transDesc.RenderTargets[0].SourceBlend           = BlendOption.SourceAlpha;
            transDesc.RenderTargets[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
            transDesc.RenderTargets[0].BlendOperation        = BlendOperation.Add;
            transDesc.RenderTargets[0].SourceBlendAlpha      = BlendOption.One;
            transDesc.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
            transDesc.RenderTargets[0].BlendOperationAlpha   = BlendOperation.Add;
            transDesc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            var bs = BlendState.FromDescription(device.Device, transDesc);

            device.OutputMerger.BlendState = bs;

            RasterizerState rs = RasterizerState.FromDescription(Scene.GetGraphicsDevice(), rsd);

            device.Rasterizer.State = rs;

            // Variables
            Graphics.AtmosphereEffect effect = Scene.GetGraphicsEngine().AtmosphereEffect;
            effect.Apply(Matrix.Identity, Scene.Instance.Camera.View, Scene.Instance.Camera.Projection, m_material);
            device.DrawIndexed(Generation.ModelGenerator.GetIndexBuffer(GridResolution).Description.SizeInBytes / sizeof(int), 0, 0);

            device.OutputMerger.BlendState = null;
        }
        private void updateRasterizerState()
        {
            if (rasterizerState != null)
            {
                rasterizerState.Dispose();
            }

            rasterizerState = RasterizerState.FromDescription(game.Device, new RasterizerStateDescription()
            {
                CullMode = cullMode,
                FillMode = wireframe ? FillMode.Wireframe : FillMode.Solid
            });
        }
        public void ShotBodyShadow(string outputFile)
        {
            _width  = 512;
            _height = 512;

            foreach (var obj in _objs.Where(obj => obj.Blen != null))
            {
                obj.Blen.Dispose();
                obj.Blen = null;
            }

            ShotBodyShadow_SetCamera();

            DxResize();
            DrawFrame();

            var doubleSided = RasterizerState.FromDescription(CurrentDevice, new RasterizerStateDescription {
                FillMode = FillMode.Solid,
                CullMode = CullMode.None,
                IsFrontCounterclockwise = true,
                IsDepthClipEnabled      = false
            });

            var tmpTexture = new Texture2D(CurrentDevice, new Texture2DDescription {
                Width             = _width,
                Height            = _height,
                MipLevels         = 1,
                ArraySize         = 1,
                Format            = Format.R8G8B8A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.None
            });

            _effectShotBodyShadow = new EffectShotBodyShadow(CurrentDevice);

            var tmpRenderTarget = new RenderTargetView(CurrentDevice, tmpTexture);

            DrawPreviousBodyDepthTo(tmpRenderTarget, doubleSided);
            BlurBodyShadow(tmpTexture, 1);
            BlurSomething(tmpTexture, 5, 2f / AmbientBodyShadowSize.X, 2f / AmbientBodyShadowSize.Z);

            Resource.SaveTextureToFile(_context, tmpTexture, ImageFileFormat.Png, outputFile);

            _effectShotBodyShadow.Dispose();
            tmpRenderTarget.Dispose();
            tmpTexture.Dispose();
            doubleSided.Dispose();
        }
Beispiel #27
0
        /// <summary>
        /// ラスタライザステート
        /// </summary>
        static void InitializeRasterizerState()
        {
            var device = D3D11Device;

            rasterizerState_ = new RasterizerState[(int)RenderState.RasterizerState.Max];

            // CullBack
            RasterizerStateDescription rsStateDesc = new RasterizerStateDescription()
            {
                CullMode = CullMode.Back,
                IsFrontCounterclockwise = true,
                FillMode           = FillMode.Solid,
                IsDepthClipEnabled = true
            };

            rasterizerState_[(int)RenderState.RasterizerState.CullBack] = RasterizerState.FromDescription(device, rsStateDesc);

            // CullFront
            rsStateDesc = new RasterizerStateDescription()
            {
                CullMode = CullMode.Front,
                IsFrontCounterclockwise = true,
                FillMode           = FillMode.Solid,
                IsDepthClipEnabled = true
            };
            rasterizerState_[(int)RenderState.RasterizerState.CullFront] = RasterizerState.FromDescription(device, rsStateDesc);

            // CullNone
            rsStateDesc = new RasterizerStateDescription()
            {
                CullMode = CullMode.None,
                IsFrontCounterclockwise = true,
                FillMode           = FillMode.Solid,
                IsDepthClipEnabled = true
            };
            rasterizerState_[(int)RenderState.RasterizerState.CullNone] = RasterizerState.FromDescription(device, rsStateDesc);

            // WireFrame
            rsStateDesc = new RasterizerStateDescription()
            {
                CullMode = CullMode.Back,
                IsFrontCounterclockwise = true,
                FillMode           = FillMode.Wireframe,
                IsDepthClipEnabled = true
            };
            rasterizerState_[(int)RenderState.RasterizerState.WireFrame] = RasterizerState.FromDescription(device, rsStateDesc);

            // 初期値
            SetRasterizerState(RenderState.RasterizerState.CullBack);
        }
Beispiel #28
0
        public void Apply(DX11RenderContext context)
        {
            DeviceContext ctx = context.CurrentDeviceContext;

            RasterizerState   rs = RasterizerState.FromDescription(context.Device, this.Rasterizer);
            DepthStencilState ds = DepthStencilState.FromDescription(context.Device, this.DepthStencil);
            BlendState        bs = BlendState.FromDescription(context.Device, this.Blend);

            ctx.Rasterizer.State = rs;
            ctx.OutputMerger.DepthStencilState     = ds;
            ctx.OutputMerger.DepthStencilReference = this.DepthStencilReference;
            ctx.OutputMerger.BlendState            = bs;
            ctx.OutputMerger.BlendFactor           = this.BlendFactor;
            ctx.OutputMerger.BlendSampleMask       = int.MaxValue;
        }
Beispiel #29
0
 public override void OnInitialize(DeviceContextHolder holder)
 {
     _effect     = holder.GetEffect <EffectDeferredLight>();
     _sphere     = SphereObject.Create(Radius);
     _rasterizer = RasterizerState.FromDescription(holder.Device, new RasterizerStateDescription {
         CullMode                 = CullMode.Front,
         FillMode                 = FillMode.Solid,
         IsDepthClipEnabled       = true,
         IsAntialiasedLineEnabled = false
     });
     _depth = DepthStencilState.FromDescription(holder.Device, new DepthStencilStateDescription {
         DepthComparison  = Comparison.Greater,
         IsDepthEnabled   = true,
         IsStencilEnabled = false,
         DepthWriteMask   = DepthWriteMask.Zero
     });
 }
Beispiel #30
0
        private void CreateDefaultRenderStates()
        {
            var blendStateDesc = new BlendStateDescription();

            blendStateDesc.IsAlphaToCoverageEnabled = false;
            blendStateDesc.BlendOperation           = BlendOperation.Add;
            blendStateDesc.AlphaBlendOperation      = BlendOperation.Add;
            blendStateDesc.SourceBlend           = BlendOption.One;
            blendStateDesc.DestinationBlend      = BlendOption.Zero;
            blendStateDesc.SourceAlphaBlend      = BlendOption.One;
            blendStateDesc.DestinationAlphaBlend = BlendOption.Zero;
            defaultBlendState = BlendState.FromDescription(device, blendStateDesc);

            var rasterizerStateDesc = new RasterizerStateDescription();

            rasterizerStateDesc.FillMode = FillMode.Solid;
            rasterizerStateDesc.CullMode = CullMode.Back;
            rasterizerStateDesc.IsFrontCounterclockwise = false;
            rasterizerStateDesc.DepthBias                = 0;
            rasterizerStateDesc.DepthBiasClamp           = 0;
            rasterizerStateDesc.SlopeScaledDepthBias     = 0;
            rasterizerStateDesc.IsDepthClipEnabled       = true;
            rasterizerStateDesc.IsScissorEnabled         = false;
            rasterizerStateDesc.IsMultisampleEnabled     = false;
            rasterizerStateDesc.IsAntialiasedLineEnabled = false;
            defaultRasterizerState = RasterizerState.FromDescription(device, rasterizerStateDesc);

            var depthStencilStateDesc = new DepthStencilStateDescription();

            depthStencilStateDesc.IsDepthEnabled   = true;
            depthStencilStateDesc.DepthWriteMask   = DepthWriteMask.All;
            depthStencilStateDesc.DepthComparison  = Comparison.LessEqual;
            depthStencilStateDesc.IsStencilEnabled = false;
            depthStencilStateDesc.StencilReadMask  = 0xff;
            depthStencilStateDesc.StencilWriteMask = 0xff;
            var depthStencilStateFaceDesk = new DepthStencilOperationDescription();

            depthStencilStateFaceDesk.Comparison         = Comparison.Always;
            depthStencilStateFaceDesk.DepthFailOperation = StencilOperation.Keep;
            depthStencilStateFaceDesk.FailOperation      = StencilOperation.Keep;
            depthStencilStateFaceDesk.PassOperation      = StencilOperation.Keep;
            depthStencilStateDesc.FrontFace = depthStencilStateFaceDesk;
            depthStencilStateDesc.BackFace  = depthStencilStateFaceDesk;
            defaultDepthStencilState        = DepthStencilState.FromDescription(device, depthStencilStateDesc);
        }