Exemplo n.º 1
0
        public void Render(CommandList cl, IBloomStageModel stage, GpuSurface original, GpuSurface bloom, GpuSurface target)
        {
            if (stage.MixAmount != _currentMixAmount)
            {
                _currentMixAmount = stage.MixAmount;
                var uniforms = new MixingShaderFactors
                {
                    MixAmount = _currentMixAmount,
                    Pad0      = 0.0f,
                    Pad1      = 0.0f,
                    Pad2      = 0.0f,
                    Pad3      = Vector4.Zero
                };

                cl.UpdateBuffer(_uniformBlockBuffer, 0, ref uniforms);
            }

            cl.SetFramebuffer(target.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);
            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, _uniformBlockResourceSet);
            cl.SetGraphicsResourceSet(1, original.ResourceSet_TexMirror);
            cl.SetGraphicsResourceSet(2, bloom.ResourceSet_TexMirror);
            cl.Draw(6);
        }
Exemplo n.º 2
0
        public void Render(CommandList cl, IMixStageModel stage, GpuSurface mix, GpuSurface t0, GpuSurface t1, GpuSurface t2, GpuSurface t3, GpuSurface target)
        {
            if (cl == null || stage == null || target == null)
            {
                _frameworkMessenger.Report("Warning: you are feeding the Mix Stage Renderer null inputs (for those that shouldn't be), aborting");
                return;
            }

            var factors = new MixStageFactors
            {
                MixAmounts = stage.MixAmount
            };

            cl.UpdateBuffer(_mixFactorsBuffer, 0, ref factors);

            cl.SetFramebuffer(target.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);
            cl.SetPipeline(_pipeline);

            cl.SetGraphicsResourceSet(0, _mixFactorsResource);
            cl.SetGraphicsResourceSet(1, mix == null ? _gpuSurfaceManager.SingleWhitePixel.ResourceSet_TexWrap : mix.ResourceSet_TexWrap);

            cl.SetGraphicsResourceSet(2, t0 == null ? _whiteTextures[0].ResourceSet_TexWrap : t0.ResourceSet_TexWrap);
            cl.SetGraphicsResourceSet(3, t1 == null ? _whiteTextures[1].ResourceSet_TexWrap : t1.ResourceSet_TexWrap);
            cl.SetGraphicsResourceSet(4, t2 == null ? _whiteTextures[2].ResourceSet_TexWrap : t2.ResourceSet_TexWrap);
            cl.SetGraphicsResourceSet(5, t3 == null ? _whiteTextures[3].ResourceSet_TexWrap : t3.ResourceSet_TexWrap);

            cl.Draw(6);
        }
Exemplo n.º 3
0
        public void Render(CommandList cl, IStyleEffectsStageModel stage, GpuSurface source, GpuSurface target)
        {
            if (cl == null || stage == null || source == null || target == null)
            {
                _frameworkMessenger.Report("Warning: you are feeding the Style Effect Stage Renderer null inputs, aborting");
                return;
            }

            //Updated every time as holds the shared TexelSize
            var factors = new PixellateFactors
            {
                PixAmount     = stage.PixellateCurrent.Intensity,
                NumXDivisions = stage.PixellateCurrent.NumXDivisions,
                NumYDivisions = stage.PixellateCurrent.NumYDivisions,
                Pad0          = 0,
                TexelSize     = new Vector2(1.0f / (1.0f * target.Framebuffer.Width), 1.0f / (1.0f * target.Framebuffer.Height)),
                Pad1          = Vector2.Zero
            };

            _systemComponents.Device.UpdateBuffer(stage.PixellateBuffer, 0, ref factors);

            cl.SetFramebuffer(target.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);
            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, source.ResourceSet_TexMirror);
            cl.SetGraphicsResourceSet(1, _gpuSurfaceManager.Noise.ResourceSet_TexWrap);
            cl.SetGraphicsResourceSet(2, _gpuSurfaceManager.CrtShadowMask.ResourceSet_TexWrap);
            cl.SetGraphicsResourceSet(3, stage.PixellateResourceSet);
            cl.SetGraphicsResourceSet(4, stage.EdgeDetectionResourceSet);
            cl.SetGraphicsResourceSet(5, stage.StaticResourceSet);
            cl.SetGraphicsResourceSet(6, stage.OldMovieResourceSet);
            cl.SetGraphicsResourceSet(7, stage.CrtEffectResourceSet);
            cl.Draw(6);
        }
Exemplo n.º 4
0
        public void Render(CommandList cl, ICustomShaderStageModel stage, GpuSurface t0, GpuSurface t1, GpuSurface t2, GpuSurface t3, GpuSurface target)
        {
            if (cl == null || stage == null || target == null)
            {
                _frameworkMessenger.Report("Warning: you are feeding a Custom Effect Stage Renderer null inputs, aborting");
                return;
            }

            cl.SetPipeline(stage.Pipeline);
            cl.SetFramebuffer(target.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);

            var assignedTextureCount = 0;
            var numUniforms          = stage.NumberUserUniforms;

            for (var n = 0; n < numUniforms; n++)
            {
                if (stage.UserUniformType(n) == ShaderUniformType.Texture)
                {
                    if (assignedTextureCount < 4)
                    {
                        GpuSurface surface = null;
                        switch (assignedTextureCount)
                        {
                        case 0:
                            surface = t0;
                            break;

                        case 1:
                            surface = t1;
                            break;

                        case 2:
                            surface = t2;
                            break;

                        case 3:
                            surface = t3;
                            break;
                        }
                        var resourceSet = surface == null ? _gpuSurfaceManager.SingleWhitePixel.ResourceSet_TexWrap : surface.ResourceSet_TexWrap;

                        cl.SetGraphicsResourceSet((uint)n, resourceSet);

                        assignedTextureCount++;
                    }
                    else
                    {
                        _frameworkMessenger.Report("Custom shader requires more than 4 textures. Should not have reached this stage...");
                    }
                }
                else
                {
                    var resourceSet = stage.UserUniformResourceSet(n);
                    cl.SetGraphicsResourceSet((uint)n, resourceSet);
                }
            }
            cl.Draw(6);
        }
Exemplo n.º 5
0
        public void Render(CommandList cl, GpuSurface source, GpuSurface surface)
        {
            if (cl == null || surface == null || source == null)
            {
                _frameworkMessenger.Report("Warning: you are feeding the Copy Stage Renderer null inputs, aborting");
                return;
            }

            cl.SetFramebuffer(surface.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);
            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, source.ResourceSet_TexWrap);
            cl.Draw(6);
        }
Exemplo n.º 6
0
        public void Render(CommandList cl, IMeshRenderStageModel stage, GpuSurface source, GpuSurface surface, ICameraModel3D camera)
        {
            if (cl == null || stage == null || source == null || surface == null || camera == null)
            {
                _frameworkMessenger.Report("Warning: you are feeding the Mesh Stage Renderer null inputs, aborting");
                return;
            }

            cl.SetFramebuffer(surface.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            cl.ClearDepthStencil(1.0f);
            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, camera.WvpResource);
            cl.SetGraphicsResourceSet(1, camera.PositionResource);
            cl.SetGraphicsResourceSet(2, source.ResourceSet_TexWrap);
            cl.SetGraphicsResourceSet(3, stage.LightPropertiesResource);
            cl.SetGraphicsResourceSet(4, stage.LightsResource);
            cl.SetVertexBuffer(0, stage.MeshVertexBuffer);
            cl.Draw(stage.MeshNumberVertices);
        }
Exemplo n.º 7
0
        public void Render(CommandList cl, IColourEffectsStageModel stage, GpuSurface surface, GpuSurface source)
        {
            if (cl == null || stage == null || source == null || surface == null)
            {
                _frameworkMessenger.Report("Warning: you are feeding the Colour Effect Stage Renderer null inputs, aborting");
                return;
            }

            cl.SetPipeline(_pipeline);
            cl.SetFramebuffer(surface.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            if (stage.ClearBackgroundBeforeRender)
            {
                cl.ClearColorTarget(0, stage.ClearColour);
            }
            cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);
            cl.SetGraphicsResourceSet(0, stage.FactorsResourceSet);
            cl.SetGraphicsResourceSet(1, source.ResourceSet_TexWrap);
            cl.Draw(6);
        }
Exemplo n.º 8
0
        public void Render(CommandList cl, IDistortionStageModel stage, GpuSurface source, GpuSurface shift, GpuSurface target)
        {
            float aspect = (1.0f * target.Framebuffer.Width) / (1.0f * target.Framebuffer.Height);
            float amount = stage.DistortionScalar / (1.0f * target.Framebuffer.Height);

            var distortionFactor = new DistortionFactorUniform
            {
                DistortionScalar = amount * new Vector2(aspect, 1.0f),
                Pad2             = Vector2.Zero,
                Pad3             = Vector4.Zero
            };

            cl.SetPipeline(_pipeline);
            cl.UpdateBuffer(_distortionFactorBuffer, 0, ref distortionFactor);
            cl.SetGraphicsResourceSet(0, _distortionFactorUniformResourceSet);
            cl.SetFramebuffer(target.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);
            cl.SetGraphicsResourceSet(1, shift.ResourceSet_TexWrap);
            cl.SetGraphicsResourceSet(2, source.ResourceSet_TexWrap);
            cl.Draw(6);
        }
Exemplo n.º 9
0
        public void Render(CommandList cl, IDrawStageModel stage, GpuSurface surface, ICameraModel2D camera)
        {
            if (cl == null || stage == null || surface == null || camera == null)
            {
                _frameworkMessenger.Report("Warning: you are feeding DrawStage Renderer null inputs, aborting");
                return;
            }

            cl.SetFramebuffer(surface.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            cl.SetVertexBuffer(0, stage.Buffers.VertexBuffer);
            cl.SetIndexBuffer(stage.Buffers.IndexBuffer, IndexFormat.UInt32); //Extract format and type
            cl.SetPipeline(_pipelineFactory.ReturnDrawingPipeline(stage.BlendState));
            cl.SetGraphicsResourceSet(0, camera.ResourceSet);

            //When drawing commands are queued need to check and ensure the same texture is not used for both tex inputs
            //We also need to trigger the sort somewhere earlier than this and ensure if already sorted into batches dont do it
            var batcher = stage.Batcher;

            for (var b = 0; b < batcher.NumberOfBatches; b++)
            {
                var batch = batcher.Pool[b];

                ResourceSet t0;
                if (batch.Texture0 == 0UL)
                {
                    t0 = _surfaceManager.SingleWhitePixel.ResourceSet_TexWrap;
                }
                else
                {
                    var retrieved = _surfaceManager.RetrieveSurface(batch.Texture0, new GpuSurfaceType[] { GpuSurfaceType.SwapChainOutput, GpuSurfaceType.Internal });

                    if (retrieved == surface)
                    {
                        _frameworkMessenger.Report("Warning: A draw stage is attempting to draw a surface onto itself. Aborting");
                        return;
                    }

                    t0 = retrieved == null ? _surfaceManager.SingleWhitePixel.ResourceSet_TexWrap :
                         batch.TextureMode0 == TextureCoordinateMode.Mirror ?
                         retrieved.ResourceSet_TexMirror : retrieved.ResourceSet_TexWrap;
                }
                cl.SetGraphicsResourceSet(1, t0);

                ResourceSet t1;
                if (batch.Texture1 == 0UL)
                {
                    t1 = _surfaceManager.SingleWhitePixel.ResourceSet_TexWrap;
                }
                else
                {
                    var retrieved = _surfaceManager.RetrieveSurface(batch.Texture1, new GpuSurfaceType[] { GpuSurfaceType.SwapChainOutput, GpuSurfaceType.Internal });

                    t1 = retrieved == null ? _surfaceManager.SingleWhitePixel.ResourceSet_TexWrap :
                         batch.TextureMode1 == TextureCoordinateMode.Mirror ?
                         retrieved.ResourceSet_TexMirror : retrieved.ResourceSet_TexWrap;

                    if (retrieved == surface)
                    {
                        _frameworkMessenger.Report("Warning: A draw stage is attempting to draw a surface onto itself. Aborting");
                        return;
                    }
                }
                cl.SetGraphicsResourceSet(2, t1);

                cl.DrawIndexed((uint)batch.NumIndices, 1, (uint)batch.StartIndex, 0, 0);
            }
        }