private void Draw()
        {
            _cl.Begin();
            if (_windowResized)
            {
                _windowResized = false;
                _gd.ResizeMainWindow((uint)_window.Width, (uint)_window.Height);
                _cl.UpdateBuffer(_screenSizeBuffer, 0, new Vector4(_window.Width, _window.Height, 0, 0));
            }

            _cl.SetPipeline(_computePipeline);
            _cl.SetComputeResourceSet(0, _computeResourceSet);
            _cl.SetComputeResourceSet(1, _computeScreenSizeResourceSet);
            _cl.Dispatch(1024, 1, 1);

            _cl.SetFramebuffer(_gd.SwapchainFramebuffer);
            _cl.SetFullViewports();
            _cl.SetFullScissorRects();
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.SetPipeline(_graphicsPipeline);
            _cl.SetGraphicsResourceSet(0, _graphicsParticleResourceSet);
            _cl.SetGraphicsResourceSet(1, _screenSizeResourceSet);
            _cl.Draw(ParticleCount, 1, 0, 0);
            _cl.End();

            _gd.ExecuteCommands(_cl);
            _gd.SwapBuffers();
        }
Пример #2
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);
        }
Пример #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);
        }
Пример #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);
        }
        protected override void Draw(float deltaSeconds)
        {
            if (!_initialized)
            {
                return;
            }

            _cl.Begin();

            _cl.SetPipeline(_computePipeline);
            _cl.SetComputeResourceSet(0, _computeResourceSet);
            _cl.SetComputeResourceSet(1, _computeScreenSizeResourceSet);
            _cl.Dispatch(1024, 1, 1);

            _cl.SetFramebuffer(MainSwapchain.Framebuffer);
            _cl.SetFullViewports();
            _cl.SetFullScissorRects();
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.SetPipeline(_graphicsPipeline);
            _cl.SetGraphicsResourceSet(0, _graphicsParticleResourceSet);
            _cl.SetGraphicsResourceSet(1, _screenSizeResourceSet);
            _cl.Draw(ParticleCount, 1, 0, 0);
            _cl.End();

            GraphicsDevice.SubmitCommands(_cl);
            GraphicsDevice.SwapBuffers(MainSwapchain);
        }
Пример #6
0
        private RgbaByte RenderQuad(Veldrid.Shader[] shaders)
        {
            using (var pipeline = ResourceFactory.CreateGraphicsPipeline(new GraphicsPipelineDescription(
                                                                             BlendStateDescription.SingleOverrideBlend,
                                                                             DepthStencilStateDescription.DepthOnlyLessEqual,
                                                                             RasterizerStateDescription.CullNone,
                                                                             PrimitiveTopology.TriangleStrip,
                                                                             new ShaderSetDescription(new VertexLayoutDescription[0], shaders),
                                                                             new ResourceLayout[0],
                                                                             Framebuffer.OutputDescription
                                                                             )))
            {
                CommandList.Begin();
                CommandList.SetFramebuffer(Framebuffer);
                CommandList.SetFullViewports();
                CommandList.ClearColorTarget(0, RgbaFloat.Black);
                CommandList.ClearDepthStencil(1);
                CommandList.SetPipeline(pipeline);
                CommandList.Draw(4);
                CommandList.End();

                GraphicsDevice.SubmitCommands(CommandList);
                GraphicsDevice.WaitForIdle();

                var readRenderTargetPixel = ReadRenderTargetPixel();
                return(readRenderTargetPixel);
            }
        }
Пример #7
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);
        }
Пример #8
0
 public Texture Apply(CommandList commandList)
 {
     commandList.SetFramebuffer(_fb);
     commandList.SetPipeline(_pipeline);
     commandList.SetGraphicsResourceSet(0, _rs);
     commandList.Draw(4);
     return(_fb.ColorTargets[0].Target);
 }
Пример #9
0
 public override void Render(GraphicsDevice gd, CommandList cl, SceneContext sc, RenderPasses renderPass)
 {
     cl.SetVertexBuffer(0, _vb);
     cl.SetIndexBuffer(_ib);
     cl.SetPipeline(_pipeline);
     cl.SetResourceSet(0, _resourceSet);
     cl.Draw((uint)s_indices.Length, 1, 0, 0, 0);
 }
Пример #10
0
 internal void Draw(CommandList commandList)
 {
     commandList.SetFramebuffer(Output);
     commandList.SetFullViewports();
     commandList.SetPipeline(pipeline);
     commandList.SetGraphicsResourceSet(0, resourceSet);
     commandList.Draw(4);
 }
Пример #11
0
 public void Render(CommandList cl, IDistortionStageModel stage, GpuSurface source, GpuSurface target)
 {
     cl.SetPipeline(_pipeline);
     cl.SetFramebuffer(target.Framebuffer);
     cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);
     cl.SetGraphicsResourceSet(0, stage.InternalSurfacePixelShiftUniform);
     cl.SetGraphicsResourceSet(1, source.ResourceSet_TexWrap);
     cl.ClearColorTarget(0, RgbaFloat.Clear);
     cl.Draw(6);
 }
Пример #12
0
 public void Draw(CommandList _cl)
 {
     //throw new NotImplementedException();
     _cl.SetPipeline(_screenPipeline);
     _cl.SetGraphicsResourceSet(0, _screenResourceSet);
     //_cl.SetGraphicsResourceSet(1, _pointStyleRSet);
     //_cl.SetVertexBuffer(0, _VertexBuffer);
     //_cl.SetIndexBuffer(_IndicesBuffer, IndexFormat.UInt16);
     //_systemEventUbo.MousePosition = PongGlobe.Scene.InputTracker.MousePosition;
     //_cl.UpdateBuffer(_eventBuffer, 0, _systemEventUbo);
     _cl.Draw(3, 1, 0, 0);
 }
Пример #13
0
        public void Draw(CommandList commandList, World world)
        {
            UpdateVertices(world);

            commandList.SetFramebuffer(_graphicsDevice.SwapchainFramebuffer);
            commandList.ClearColorTarget(0, RgbaFloat.Black);

            commandList.SetVertexBuffer(0, _vertexBuffer);
            commandList.SetPipeline(_pipeline);
            commandList.SetGraphicsResourceSet(0, _resourceSet);
            commandList.Draw(_vertices.Count);
        }
Пример #14
0
        protected override void Render()
        {
            if (isResizing)
            {
                return;
            }

            commandList.Begin();

            if (DrawModeCpu)
            {
                if (!renderOnce)
                {
                    Raytracer.RenderCpuNew();
                }

                if (!isResizing)
                {
                    unsafe
                    {
                        fixed(RgbaFloat *pixelDataPtr = Raytracer.FrameBuffer)
                        {
                            GraphicsDevice.UpdateTexture(transferTexture, (IntPtr)pixelDataPtr,
                                                         transferTexture.Width * transferTexture.Height * (uint)sizeof(RgbaFloat), 0, 0, 0,
                                                         transferTexture.Width, transferTexture.Height, 1, 0, 0);
                        }
                    }
                }
            }
            else
            {
                RenderGpu();
            }

            commandList.SetFramebuffer(GraphicsDevice.MainSwapchain.Framebuffer);
            commandList.SetPipeline(graphicsPipeline);
            commandList.SetGraphicsResourceSet(0, graphicsSet);
            commandList.Draw(3);
            commandList.End();

            if (!DrawModeCpu)
            {
                var rayCountView = GraphicsDevice.Map <uint>(rayCountReadback, MapMode.Read);
                var rPF          = rayCountView[0];
                GraphicsDevice.Unmap(rayCountReadback);
            }

            base.Render();
        }
Пример #15
0
        public void Render(CommandList cl, ResourceSet rs, Vector2 minUV, Vector2 maxUV)
        {
            Vector4 newVal = new Vector4(minUV.X, minUV.Y, maxUV.X, maxUV.Y);

            if (_lastMinMaxUV != newVal)
            {
                _lastMinMaxUV = newVal;
                cl.UpdateBuffer(_sampleRegionUB, 0, newVal);
            }

            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, rs);
            cl.SetGraphicsResourceSet(1, _sampleRegionSet);
            cl.Draw(4);
        }
Пример #16
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);
        }
Пример #17
0
        private void DrawOutput(CommandList commandList, Color color, bool secondPass, Vector4 rect)
        {
            textVertexProperties.Rectangle = rect;
            commandList.UpdateBuffer(textVertexPropertiesBuffer, 0, textVertexProperties);

            textFragmentProperties.GlyphColor = color;
            commandList.UpdateBuffer(textFragmentPropertiesBuffer, 0, textFragmentProperties);

            commandList.SetPipeline(secondPass ? outputColorPipeline : outputPipeline);
            commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
            commandList.SetGraphicsResourceSet(0, textPropertiesSet);
            // HACK workaround issue with texture view caching for shader resources
            commandList.SetGraphicsResourceSet(1, dummyTextureSet);
            commandList.SetGraphicsResourceSet(1, textTextureSet);
            commandList.SetVertexBuffer(0, quadVertexBuffer);
            commandList.Draw((uint)quadVertices.Length);
        }
Пример #18
0
        private void RenderFrame()
        {
            FramePerSecond++;
            _commandList.Begin();

            Update();

            fixed(RgbaFloat *pixel_data_ptr = _buff) _graphicsDevice.UpdateTexture(_transferTex, (IntPtr)pixel_data_ptr, Width * Height * (uint)sizeof(RgbaFloat), 0, 0, 0, Width, Height, 1, 0, 0);

            _commandList.SetFramebuffer(_graphicsDevice.MainSwapchain.Framebuffer);
            _commandList.SetPipeline(_graphicsPipeline);
            _commandList.SetGraphicsResourceSet(0, _graphicsSet);
            _commandList.Draw(3);
            _commandList.End();
            _graphicsDevice.SubmitCommands(_commandList);
            _graphicsDevice.SwapBuffers();
        }
Пример #19
0
        public void Render(CommandList cl, float brightnessThreshold, GpuSurface source, GpuSurface target, ResizeSamplerType samplerType)
        {
            if (_sampleType == null || _sampleType != samplerType)
            {
                _sampleType = samplerType;
                LoadWeightsAndOffsets(cl);
            }

            UpdateSamplerUniformBuffer(cl, source, brightnessThreshold);

            cl.SetFramebuffer(target.Framebuffer);
            cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);
            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, source.ResourceSet_TexMirror);
            cl.SetGraphicsResourceSet(1, _samplerFactorsUniformBlockResourceSet);
            cl.SetGraphicsResourceSet(2, _weightsAndOffsetsResourceSet);
            cl.Draw(6);
        }
        private void RenderFrame()
        {
            _sceneParams.FrameCount += 1;

            _cl.Begin();

            if (_drawModeCPU)
            {
                RenderCPU();
            }
            else
            {
                RenderGPU();
            }

            fixed(RgbaFloat *pixelDataPtr = _fb)
            {
                _gd.UpdateTexture(_transferTex, (IntPtr)pixelDataPtr, Width * Height * (uint)sizeof(RgbaFloat), 0, 0, 0, Width, Height, 1, 0, 0);
            }

            _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
            _cl.SetPipeline(_graphicsPipeline);
            _cl.SetGraphicsResourceSet(0, _graphicsSet);
            _cl.Draw(3);
            _cl.End();
            _gd.SubmitCommands(_cl);
            _gd.SwapBuffers();

            if (!_drawModeCPU)
            {
                MappedResourceView <uint> rayCountView = _gd.Map <uint>(_rayCountReadback, MapMode.Read);
                _totalRays += rayCountView[0];
                _gd.Unmap(_rayCountReadback);
            }

            float seconds   = _stopwatch.ElapsedMilliseconds / 1000f;
            float rate      = _totalRays / seconds;
            float mRate     = rate / 1_000_000;
            float frameRate = _sceneParams.FrameCount / (float)_stopwatch.Elapsed.TotalSeconds;

            _window.Title = $"Elapsed: {seconds} sec. | Rate: {mRate} MRays / sec. | {frameRate} fps";
        }
Пример #21
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);
        }
Пример #22
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);
        }
Пример #23
0
        public void Flush(CommandList cl)
        {
            var posInBuffer = bufferPos % buffer.Length;
            var bufferCount = (bufferPos - posInBuffer) / buffer.Length + 1;

            if (posInBuffer == 0)
            {
                bufferCount--;
                posInBuffer = buffer.Length;
            }

            if (bufferCount == 0)
            {
                return;
            }

            while (VertexBufferCache.Count < bufferCount)
            {
                var newBuffer = Factory.CreateBuffer(new BufferDescription((uint)(buffer.Length * itemSizeInBytes), BufferUsage.VertexBuffer | BufferUsage.Dynamic));
                VertexBufferCache.Add(newBuffer);
            }
            var bufferToWrite = VertexBufferCache[bufferCount - 1];

            lock (GraphicsDevice)
                GraphicsDevice.UpdateBuffer(bufferToWrite, 0, ref buffer[0], (uint)(posInBuffer * itemSizeInBytes));
            cl.SetVertexBuffer(0, bufferToWrite);

            if (indices == null)
            {
                cl.Draw((uint)posInBuffer);
            }
            else
            {
                cl.SetIndexBuffer(IndexBuffer, IndexFormat.UInt32);
                if (posInBuffer % vertsPerShape != 0)
                {
                    throw new Exception("Submitted an incomplete shape to the buffer flushing");
                }
                cl.DrawIndexed((uint)(posInBuffer / vertsPerShape * indicesPerShape));
            }
        }
        public void Render(CommandList cl, Vector2 texelShiftSize, int numberSamplesPerSideNotIncludingCentre, GpuSurface source, GpuSurface target)
        {
            var num = numberSamplesPerSideNotIncludingCentre + 1;

            if (num != _currentNumSamplesIncludingCentre)
            {
                _currentNumSamplesIncludingCentre = num;
                UpdateWeightsAndOffsetsBuffer(cl);
            }

            UpdateGaussianUniformBuffer(cl, texelShiftSize);

            cl.SetFramebuffer(target.Framebuffer);
            cl.ClearColorTarget(0, RgbaFloat.Clear);
            cl.SetVertexBuffer(0, _ndcQuadVertexBuffer.Buffer);
            cl.SetPipeline(_pipeline);
            cl.SetGraphicsResourceSet(0, source.ResourceSet_TexMirror);
            cl.SetGraphicsResourceSet(1, _gaussianFactorsUniformBlockResourceSet);
            cl.SetGraphicsResourceSet(2, _weightsAndOffsetsResourceSet);
            cl.Draw(6);
        }
Пример #25
0
        public void Render(float elapsedTotalSeconds)
        {
            _uniformValues.iTime      += elapsedTotalSeconds;
            _uniformValues.iTimeDelta  = elapsedTotalSeconds;
            _uniformValues.iSampleRate = 44100;
            _cl.Begin();

            _cl.UpdateBuffer(_uniforms, 0, ref _uniformValues);

            _cl.SetFramebuffer(_device.MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, RgbaFloat.Black);
            _cl.ClearDepthStencil(1f);
            _cl.SetPipeline(_pipeline);
            _cl.SetGraphicsResourceSet(0, _resourceSet);
            _cl.Draw(4);

            _cl.End();
            _device.SubmitCommands(_cl);
            _device.SwapBuffers(_device.MainSwapchain);
            _device.WaitForIdle();
        }
Пример #26
0
        public void Draw()
        {
            CommandList CommandList = Context.CommandList;

            Device.WaitIdle();

            CommandList.Begin();
            CommandList.BeginFramebuffer(Framebuffer);
            CommandList.Clear(0.0f, 0.2f, 0.4f, 1.0f);

            CommandList.SetViewport(Window.Width, Window.Height, 0, 0);
            CommandList.SetScissor(Window.Width, Window.Height, 0, 0);
            CommandList.SetPipelineState(PipelineState);
            CommandList.Draw(3, 1, 0, 0);

            CommandList.EndFramebuffer();
            CommandList.End();
            CommandList.Submit();

            Device.NativeSwapChain.Present();
        }
Пример #27
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);
        }
Пример #28
0
        private void RenderFrame()
        {
            _frameCount++;
            _commandList.Begin();

            foreach (KeyValuePair <string, Entity> item in Renderer.CurrentScene.Entities)
            {
                item.Value.Rotation += new Vector3(0.01f);
            }
            Renderer.Draw();

            fixed(RgbaFloat *pixelDataPtr = _buff)
            _graphicsDevice.UpdateTexture(_transferTex, (IntPtr)pixelDataPtr, Width * Height * (uint)sizeof(RgbaFloat), 0, 0, 0, Width, Height, 1, 0, 0);

            _commandList.SetFramebuffer(_graphicsDevice.MainSwapchain.Framebuffer);
            _commandList.SetPipeline(_graphicsPipeline);
            _commandList.SetGraphicsResourceSet(0, _graphicsSet);
            _commandList.Draw(3);
            _commandList.End();
            _graphicsDevice.SubmitCommands(_commandList);
            _graphicsDevice.SwapBuffers();
        }
Пример #29
0
        public void Render(CommandList cl)
        {
            if (RenderMode == DebugSkeletonRenderMode.Invisible)
            {
                return;
            }

            if (RenderMode == DebugSkeletonRenderMode.Skin)
            {
                (SkinMaterial as IMaterial).Apply(cl);
                Geometry.SetBuffers(cl);
                Geometry.SetSkinBuffer(cl);
                cl.DrawIndexed((uint)Geometry.SubMeshes.Sum(sm => sm.IndexCount));
            }
            if (RenderMode == DebugSkeletonRenderMode.SingleSkinBone)
            {
                (SkinHighlightedMaterial as IMaterial).Apply(cl);
                Geometry.SetBuffers(cl);
                Geometry.SetSkinBuffer(cl);
                cl.DrawIndexed((uint)Geometry.SubMeshes.Sum(sm => sm.IndexCount));
            }

            // always draw bones when visible
            (BoneMaterial as IMaterial).Apply(cl);
            cl.SetVertexBuffer(0, vertexBuffer);
            cl.SetVertexBuffer(1, skinBuffer);
            cl.SetIndexBuffer(indexBuffer, IndexFormat.UInt16);
            cl.DrawIndexed(indexBuffer.SizeInBytes / sizeof(ushort));

            if (highlightedBoneI >= 0)
            {
                LinesMaterial.World.Ref = Skeleton.Bones[highlightedBoneI].LocalToWorld;
                (LinesMaterial as IMaterial).Apply(cl);
                cl.SetVertexBuffer(0, lineBuffer);
                cl.Draw(lineBuffer.SizeInBytes / ColoredVertex.Stride);
            }
        }
Пример #30
0
        private void DrawGlyph(CommandList commandList, VertexPosition3Coord2[] glyphVertices, Vector2 coordsInPixels)
        {
            // Resize the vertex buffer if required
            var requiredBufferSize = VertexPosition3Coord2.SizeInBytes * (uint)glyphVertices.Length;

            if (glyphVertexBuffer.SizeInBytes < requiredBufferSize)
            {
                glyphVertexBuffer.Dispose();
                glyphVertexBuffer = graphicsDevice.ResourceFactory.CreateBuffer(
                    new BufferDescription(requiredBufferSize, BufferUsage.VertexBuffer));
            }

            commandList.UpdateBuffer(glyphVertexBuffer, 0, glyphVertices);
            commandList.SetVertexBuffer(0, glyphVertexBuffer);

            var coordsInScreenSpace = coordsInPixels * new Vector2(aspectWidth, aspectHeight);
            var textTransformMatrix = Matrix4x4.CreateScale(aspectWidth, aspectHeight, 1)
                                      * Matrix4x4.CreateTranslation(-1, 0, 0)
                                      * Matrix4x4.CreateTranslation(coordsInScreenSpace.X, 1f - coordsInScreenSpace.Y, 0);

            for (var i = 0; i < jitterPattern.Length; i++)
            {
                var jitter = jitterPattern[i];

                var glyphTransformMatrix = Matrix4x4.CreateTranslation(new Vector3(jitter, 0)) * textTransformMatrix;
                textVertexProperties.Transform = glyphTransformMatrix;
                commandList.UpdateBuffer(textVertexPropertiesBuffer, 0, textVertexProperties);

                if (i % 2 == 0)
                {
                    textFragmentProperties.GlyphColor = new Color(i == 0 ? 1 : 0, i == 2 ? 1 : 0, i == 4 ? 1 : 0, 0);
                    commandList.UpdateBuffer(textFragmentPropertiesBuffer, 0, textFragmentProperties);
                }

                commandList.Draw((uint)glyphVertices.Length);
            }
        }