public override void Initialize() { Form.SizeChanged += (o, args) => { _width = Form.ClientSize.Width; _height = Form.ClientSize.Height; if (_swapChain == null) return; renderView.Dispose(); depthView.Dispose(); _swapChain.ResizeBuffers(_swapChain.Description.BufferCount, 0, 0, Format.Unknown, 0); CreateBuffers(); SetSceneConstants(); }; _width = 1024; _height = 768; _nearPlane = 1.0f; ambient = new Color4(Color.Gray.ToArgb()); try { OnInitializeDevice(); } catch (Exception e) { MessageBox.Show(e.ToString(), "Could not create DirectX 10 device."); return; } // shader.fx const ShaderFlags shaderFlags = ShaderFlags.None; //const ShaderFlags shaderFlags = ShaderFlags.Debug | ShaderFlags.SkipOptimization; ShaderBytecode shaderByteCode = LoadShader("shader.fx", shaderFlags); effect = new Effect(_device, shaderByteCode); EffectTechnique technique = effect.GetTechniqueByIndex(0); shadowGenPass = technique.GetPassByIndex(0); gBufferGenPass = technique.GetPassByIndex(1); debugDrawPass = technique.GetPassByName("debug"); BufferDescription sceneConstantsDesc = new BufferDescription() { SizeInBytes = Marshal.SizeOf(typeof(ShaderSceneConstants)), Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.ConstantBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None }; sceneConstantsBuffer = new Buffer(_device, sceneConstantsDesc); EffectConstantBuffer effectConstantBuffer = effect.GetConstantBufferByName("scene"); effectConstantBuffer.SetConstantBuffer(sceneConstantsBuffer); RasterizerStateDescription desc = new RasterizerStateDescription() { CullMode = CullMode.None, FillMode = FillMode.Solid, IsFrontCounterClockwise = true, DepthBias = 0, DepthBiasClamp = 0, SlopeScaledDepthBias = 0, IsDepthClipEnabled = true, }; _device.Rasterizer.State = new RasterizerState(_device, desc); DepthStencilStateDescription depthDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; depthStencilState = new DepthStencilState(_device, depthDesc); DepthStencilStateDescription lightDepthStateDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; lightDepthStencilState = new DepthStencilState(_device, lightDepthStateDesc); // grender.fx shaderByteCode = LoadShader("grender.fx", shaderFlags); effect2 = new Effect(_device, shaderByteCode); technique = effect2.GetTechniqueByIndex(0); gBufferRenderPass = technique.GetPassByIndex(0); gBufferOverlayPass = technique.GetPassByIndex(1); Buffer quad = DemoFramework.SharpDX.MeshFactory.CreateScreenQuad(_device); quadBinding = new VertexBufferBinding(quad, 20, 0); Matrix quadProjection = Matrix.OrthoLH(1, 1, 0.1f, 1.0f); effect2.GetVariableByName("ViewProjection").AsMatrix().SetMatrix(quadProjection); InputElement[] elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0, InputClassification.PerVertexData, 0), }; quadBufferLayout = new InputLayout(_device, gBufferRenderPass.Description.Signature, elements); info = new InfoText(_device); _meshFactory = new MeshFactory(this); MeshFactory = _meshFactory; CreateBuffers(); LibraryManager.LibraryStarted(); }
public override void Initialize() { Form.SizeChanged += (o, args) => { if (_swapChain == null) { return; } renderView.Dispose(); depthView.Dispose(); DisposeBuffers(); if (Form.WindowState == FormWindowState.Minimized) { return; } _width = Form.ClientSize.Width; _height = Form.ClientSize.Height; _swapChain.ResizeBuffers(_swapChain.Description.BufferCount, 0, 0, Format.Unknown, 0); CreateBuffers(); SetSceneConstants(); }; _width = 1024; _height = 768; _nearPlane = 1.0f; ambient = new Color4(Color.Gray.ToArgb()); try { OnInitializeDevice(); } catch (Exception e) { MessageBox.Show(e.ToString(), "Could not create DirectX 10 device."); return; } // shader.fx const ShaderFlags shaderFlags = ShaderFlags.None; //const ShaderFlags shaderFlags = ShaderFlags.Debug | ShaderFlags.SkipOptimization; ShaderBytecode shaderByteCode = LoadShader("shader.fx", shaderFlags); effect = new Effect(_device, shaderByteCode); EffectTechnique technique = effect.GetTechniqueByIndex(0); shadowGenPass = technique.GetPassByIndex(0); gBufferGenPass = technique.GetPassByIndex(1); debugDrawPass = technique.GetPassByName("debug"); BufferDescription sceneConstantsDesc = new BufferDescription() { SizeInBytes = Marshal.SizeOf(typeof(ShaderSceneConstants)), Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.ConstantBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None }; sceneConstantsBuffer = new Buffer(_device, sceneConstantsDesc); EffectConstantBuffer effectConstantBuffer = effect.GetConstantBufferByName("scene"); effectConstantBuffer.SetConstantBuffer(sceneConstantsBuffer); RasterizerStateDescription desc = new RasterizerStateDescription() { CullMode = CullMode.None, FillMode = FillMode.Solid, IsFrontCounterClockwise = true, DepthBias = 0, DepthBiasClamp = 0, SlopeScaledDepthBias = 0, IsDepthClipEnabled = true, }; _device.Rasterizer.State = new RasterizerState(_device, desc); DepthStencilStateDescription depthDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; depthStencilState = new DepthStencilState(_device, depthDesc); DepthStencilStateDescription lightDepthStateDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; lightDepthStencilState = new DepthStencilState(_device, lightDepthStateDesc); // grender.fx shaderByteCode = LoadShader("grender.fx", shaderFlags); effect2 = new Effect(_device, shaderByteCode); technique = effect2.GetTechniqueByIndex(0); gBufferRenderPass = technique.GetPassByIndex(0); gBufferOverlayPass = technique.GetPassByIndex(1); info = new InfoText(_device); _meshFactory = new MeshFactory(this); MeshFactory = _meshFactory; CreateBuffers(); LibraryManager.LibraryStarted(); }
public override void Initialize() { Form.SizeChanged += (o, args) => { _width = Form.ClientSize.Width; _height = Form.ClientSize.Height; if (_swapChain == null) { return; } renderView.Dispose(); depthView.Dispose(); _swapChain.ResizeBuffers(_swapChain.Description.BufferCount, 0, 0, Format.Unknown, 0); CreateBuffers(); SetSceneConstants(); }; _width = 1024; _height = 768; _nearPlane = 1.0f; ambient = new Color4(Color.Gray.ToArgb()); try { OnInitializeDevice(); } catch (Exception e) { MessageBox.Show(e.ToString(), "Could not create DirectX 10 device."); return; } // shader.fx const ShaderFlags shaderFlags = ShaderFlags.None; //const ShaderFlags shaderFlags = ShaderFlags.Debug | ShaderFlags.SkipOptimization; ShaderBytecode shaderByteCode = LoadShader("shader.fx", shaderFlags); effect = new Effect(_device, shaderByteCode); EffectTechnique technique = effect.GetTechniqueByIndex(0); shadowGenPass = technique.GetPassByIndex(0); gBufferGenPass = technique.GetPassByIndex(1); debugDrawPass = technique.GetPassByName("debug"); BufferDescription sceneConstantsDesc = new BufferDescription() { SizeInBytes = Marshal.SizeOf(typeof(ShaderSceneConstants)), Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.ConstantBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None }; sceneConstantsBuffer = new Buffer(_device, sceneConstantsDesc); EffectConstantBuffer effectConstantBuffer = effect.GetConstantBufferByName("scene"); effectConstantBuffer.SetConstantBuffer(sceneConstantsBuffer); RasterizerStateDescription desc = new RasterizerStateDescription() { CullMode = CullMode.None, FillMode = FillMode.Solid, IsFrontCounterClockwise = true, DepthBias = 0, DepthBiasClamp = 0, SlopeScaledDepthBias = 0, IsDepthClipEnabled = true, }; _device.Rasterizer.State = new RasterizerState(_device, desc); DepthStencilStateDescription depthDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; depthStencilState = new DepthStencilState(_device, depthDesc); DepthStencilStateDescription lightDepthStateDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; lightDepthStencilState = new DepthStencilState(_device, lightDepthStateDesc); // grender.fx shaderByteCode = LoadShader("grender.fx", shaderFlags); effect2 = new Effect(_device, shaderByteCode); technique = effect2.GetTechniqueByIndex(0); gBufferRenderPass = technique.GetPassByIndex(0); gBufferOverlayPass = technique.GetPassByIndex(1); Buffer quad = DemoFramework.SharpDX.MeshFactory.CreateScreenQuad(_device); quadBinding = new VertexBufferBinding(quad, 20, 0); Matrix quadProjection = Matrix.OrthoLH(1, 1, 0.1f, 1.0f); effect2.GetVariableByName("ViewProjection").AsMatrix().SetMatrix(quadProjection); InputElement[] elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0, InputClassification.PerVertexData, 0), }; quadBufferLayout = new InputLayout(_device, gBufferRenderPass.Description.Signature, elements); info = new InfoText(_device); _meshFactory = new MeshFactory(this); MeshFactory = _meshFactory; CreateBuffers(); LibraryManager.LibraryStarted(); }
public override void Initialize() { Form.SizeChanged += (o, args) => { if (_swapChain == null) return; renderView.Dispose(); depthView.Dispose(); DisposeBuffers(); if (Form.WindowState == FormWindowState.Minimized) return; _width = Form.ClientSize.Width; _height = Form.ClientSize.Height; _swapChain.ResizeBuffers(_swapChain.Description.BufferCount, 0, 0, Format.Unknown, 0); CreateBuffers(); SetSceneConstants(); }; _width = 1024; _height = 768; _nearPlane = 1.0f; ambient = new Color4(Color.Gray.ToArgb()); try { OnInitializeDevice(); } catch (Exception e) { MessageBox.Show(e.ToString(), "Could not create DirectX 10 device."); return; } // shader.fx const ShaderFlags shaderFlags = ShaderFlags.None; //const ShaderFlags shaderFlags = ShaderFlags.Debug | ShaderFlags.SkipOptimization; ShaderBytecode shaderByteCode = LoadShader("shader.fx", shaderFlags); effect = new Effect(_device, shaderByteCode); EffectTechnique technique = effect.GetTechniqueByIndex(0); shadowGenPass = technique.GetPassByIndex(0); gBufferGenPass = technique.GetPassByIndex(1); debugDrawPass = technique.GetPassByName("debug"); BufferDescription sceneConstantsDesc = new BufferDescription() { SizeInBytes = Marshal.SizeOf(typeof(ShaderSceneConstants)), Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.ConstantBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None }; sceneConstantsBuffer = new Buffer(_device, sceneConstantsDesc); EffectConstantBuffer effectConstantBuffer = effect.GetConstantBufferByName("scene"); effectConstantBuffer.SetConstantBuffer(sceneConstantsBuffer); RasterizerStateDescription desc = new RasterizerStateDescription() { CullMode = CullMode.None, FillMode = FillMode.Solid, IsFrontCounterClockwise = true, DepthBias = 0, DepthBiasClamp = 0, SlopeScaledDepthBias = 0, IsDepthClipEnabled = true, }; _device.Rasterizer.State = new RasterizerState(_device, desc); DepthStencilStateDescription depthDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; depthStencilState = new DepthStencilState(_device, depthDesc); DepthStencilStateDescription lightDepthStateDesc = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less }; lightDepthStencilState = new DepthStencilState(_device, lightDepthStateDesc); // grender.fx shaderByteCode = LoadShader("grender.fx", shaderFlags); effect2 = new Effect(_device, shaderByteCode); technique = effect2.GetTechniqueByIndex(0); gBufferRenderPass = technique.GetPassByIndex(0); gBufferOverlayPass = technique.GetPassByIndex(1); info = new InfoText(_device); _meshFactory = new MeshFactory(this); MeshFactory = _meshFactory; CreateBuffers(); LibraryManager.LibraryStarted(); }