public DeferredRenderer(LightDevice device, string shaderFile, Texture2D[] input, bool alphaBlend) { _device = device; //target var screenTarget = device.GetDefaultTarget(); _target = new RenderTargetList(screenTarget); //pipeline _pipeline = device.CompilePipeline(InputTopology.Triangle, ShaderSource.FromResource(shaderFile, ShaderType.Vertex | ShaderType.Pixel)); if (alphaBlend) { _pipeline.SetBlender(Blender.AlphaBlender); } _psConstants = _pipeline.CreateConstantBuffer <PSConstants>(); _psConstants.Value.ClearColor = Color.AliceBlue.WithAlpha(1); _pipeline.SetConstant(ShaderType.Pixel, 0, _psConstants); for (int i = 0; i < input.Length; ++i) { _pipeline.SetResource(i, input[i]); } //vb var processor = _pipeline.CreateVertexDataProcessor <Vertex>(); var data = new Vertex[] { new Vertex { Position = new Vector2(0, 0) }, new Vertex { Position = new Vector2(1, 0) }, new Vertex { Position = new Vector2(0, 1) }, new Vertex { Position = new Vector2(0, 1) }, new Vertex { Position = new Vector2(1, 0) }, new Vertex { Position = new Vector2(1, 1) }, }; _vertexBuffer = processor.CreateImmutableBuffer(data); }
private void InitializeRendering() { _renderWindow = new Form(); _renderWindow.FormBorderStyle = FormBorderStyle.None; _renderWindow.TopLevel = false; _renderWindow.Parent = this; _renderWindow.Dock = DockStyle.Fill; _renderWindow.Show(); _device = LightDevice.Create(_renderWindow); _device.AutoResize = false; //We don't use loop, so AutoResize is not checked. _spriteDebug = new Sprite(_device); _spriteFont = new TextureFontCache(_device, SystemFonts.DefaultFont); _target = new RenderTargetList(_device.GetDefaultTarget(Color.AliceBlue.WithAlpha(1)), _device.CreateDepthStencilTarget()); _target.Apply(); _modelPipeline = _device.CompilePipeline(InputTopology.Point, ShaderSource.FromResource("Model.fx", ShaderType.Vertex | ShaderType.Geometry | ShaderType.Pixel)); _inputProcessor = _modelPipeline.CreateVertexDataProcessor <Voxel>(); _vsConstant = _modelPipeline.CreateConstantBuffer <Matrix4x4>(); _modelPipeline.SetConstant(ShaderType.Vertex, 0, _vsConstant); _gsConstant = _modelPipeline.CreateConstantBuffer <GSConstant>(); _modelPipeline.SetConstant(ShaderType.Geometry, 0, _gsConstant); _camera = new Camera(_device, new Vector3(0, 0, 0)); _camera.SetForm(_renderWindow); _renderWindowLastWidth = _renderWindow.ClientSize.Width; _renderWindowLastHeight = _renderWindow.ClientSize.Height; ResizeBegin += RenderWindow_ResizeBegin; ResizeEnd += RenderWindow_ResizeEnd; _renderWindow.ResizeBegin += RenderWindow_ResizeBegin; _renderWindow.ResizeEnd += RenderWindow_ResizeEnd; _renderWindow.ClientSizeChanged += RenderWindow_ClientSizeChanged; _renderWindow.DoubleClick += delegate(object obj, EventArgs e) { ResetCamera(); }; }
public DeferredTarget(LightDevice device) { _device = device; //target & output var screenTarget = device.GetDefaultTarget(); var colorTarget = device.CreateTextureTarget(); var normalTarget = device.CreateTextureTarget(); var depthTarget = device.CreateDepthStencilTarget(); _normalTargetObj = normalTarget; _renderTarget1 = new RenderTargetList(colorTarget, normalTarget, depthTarget); _renderTarget2 = new RenderTargetList(screenTarget, normalTarget, depthTarget); colorTarget.ClearColor = Color.Black.WithAlpha(0); _colorData = colorTarget.GetTexture2D(); _depthData = depthTarget.GetTexture2D(); _normalData = normalTarget.GetTexture2D(); }