private void Draw() { // render cube into offscreen render targets var offScreenPassAction = default(PassAction); offScreenPassAction.Color().Action = PassAttachmentAction.Clear; offScreenPassAction.Color().Value = new Rgba32F(0.25f, 0.0f, 0.0f, 1.0f); offScreenPassAction.Color(1).Action = PassAttachmentAction.Clear; offScreenPassAction.Color(1).Value = new Rgba32F(0.0f, 0.25f, 0.0f, 1.0f); offScreenPassAction.Color(2).Action = PassAttachmentAction.Clear; offScreenPassAction.Color(2).Value = new Rgba32F(0.0f, 0.0f, 0.25f, 1.0f); // describe the binding of the off screen cube var offScreenBindings = default(ResourceBindings); offScreenBindings.VertexBuffer() = _cubeVertexBuffer; offScreenBindings.IndexBuffer = _cubeIndexBuffer; _offScreenPass.Begin(ref offScreenPassAction); _offScreenPass.ApplyPipeline(_offScreenPipeline); _offScreenPass.ApplyBindings(ref offScreenBindings); _offScreenPass.ApplyShaderUniforms(ShaderStageType.VertexStage, ref _modelViewProjectionMatrix); _offScreenPass.DrawElements(36); _offScreenPass.End(); // describe the binding of the debug quads var debugBindings = default(ResourceBindings); debugBindings.VertexBuffer() = _quadVertexBuffer; // describe the binding of the full screen quad vertex buffer var fullScreenBindings = default(ResourceBindings); fullScreenBindings.VertexBuffer() = _quadVertexBuffer; fullScreenBindings.FragmentStageImage() = _offScreenRenderTargets[0]; fullScreenBindings.FragmentStageImage(1) = _offScreenRenderTargets[1]; fullScreenBindings.FragmentStageImage(2) = _offScreenRenderTargets[2]; // render fullscreen quad with the 'composed image', // plus 3 small debug-views with the content of the offscreen render targets var pass = BeginDefaultPass(); pass.ApplyPipeline(_fullScreenPipeline); pass.ApplyBindings(ref fullScreenBindings); pass.ApplyShaderUniforms(ShaderStageType.VertexStage, ref _offset); pass.DrawElements(4); pass.ApplyPipeline(_debugPipeline); for (var i = 0; i < 3; i++) { pass.ApplyViewport(i * 100, 0, 100, 100); debugBindings.FragmentStageImage() = _offScreenRenderTargets[i]; pass.ApplyBindings(ref debugBindings); pass.DrawElements(4); } pass.End(); }
private void Draw() { // begin the offscreen render pass var offscreenPassAction = PassAction.Clear(Rgba32F.Black); _offscreenRenderPass.Begin(ref offscreenPassAction); // describe the bindings for rendering a non-textured cube into the render target var offscreenResourceBindings = default(ResourceBindings); offscreenResourceBindings.VertexBuffer() = _vertexBuffer; offscreenResourceBindings.IndexBuffer = _indexBuffer; // apply the render pipeline and bindings for the offscreen render pass _offscreenRenderPass.ApplyPipeline(_offscreenPipeline); _offscreenRenderPass.ApplyBindings(ref offscreenResourceBindings); // apply the mvp matrix to the offscreen vertex shader _offscreenRenderPass.ApplyShaderUniforms(ShaderStageType.VertexStage, ref _modelViewProjectionMatrix); // draw the non-textured cube into the target of the offscreen render pass _offscreenRenderPass.DrawElements(36); // end the offscreen render pass _offscreenRenderPass.End(); // begin a frame buffer render pass Rgba32F clearColor = 0x0040FFFF; var frameBufferPass = BeginDefaultPass(clearColor); // describe the bindings for using the offscreen render target as the sampled texture var frameBufferResourceBindings = default(ResourceBindings); frameBufferResourceBindings.VertexBuffer() = _vertexBuffer; frameBufferResourceBindings.IndexBuffer = _indexBuffer; frameBufferResourceBindings.FragmentStageImage() = _renderTarget; // apply the render pipeline and bindings for the frame buffer render pass frameBufferPass.ApplyPipeline(_frameBufferPipeline); frameBufferPass.ApplyBindings(ref frameBufferResourceBindings); // apply the mvp matrix to the frame buffer vertex shader frameBufferPass.ApplyShaderUniforms(ShaderStageType.VertexStage, ref _modelViewProjectionMatrix); // draw the textured cube into the target of the frame buffer render pass frameBufferPass.DrawElements(36); // end the frame buffer render pass frameBufferPass.End(); }