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); }
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); }
public void Render(CommandList cl, ISurfaceCopyStageModel stage, GpuSurface source) { if (cl == null || stage == null || source == null) { _frameworkMessenger.Report("Warning: you are feeding the Surface Copy Stage Renderer null inputs, aborting"); return; } //Ensure the staging texture is of the correct size var stagingTexture = _gpuSurfaceManager.RetrieveSurface(stage.StagingTextureId); var doStagingTexturePropertiesMatch = source.Texture.Width == stagingTexture.Texture.Width && source.Texture.Height == stagingTexture.Texture.Height; var pixelFormatOfSource = source.Texture.Format; if (pixelFormatOfSource != stagingTexture.Texture.Format) { doStagingTexturePropertiesMatch = false; } if (!doStagingTexturePropertiesMatch) { stage.SetPixelFormatAndCreateStagingTextureAndDataArray(source.Texture.Width, source.Texture.Height, TexturePixelFormatConverter.ConvertVeldridToYak(pixelFormatOfSource)); stagingTexture = _gpuSurfaceManager.RetrieveSurface(stage.StagingTextureId); } cl.CopyTexture(source.Texture, stagingTexture.Texture); }
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); }
public void Render(CommandList cl, IDistortionStageModel stage, GpuSurface target, ICameraModel2D camera) { cl.SetPipeline(_pipeline); cl.SetFramebuffer(target.Framebuffer); cl.ClearColorTarget(0, RgbaFloat.Clear); // HERE DIFFERENT TO STANDARD DRAW ONLY (FUTURE PULL OUT TO BASE?) cl.SetVertexBuffer(0, stage.Buffers.VertexBuffer); cl.SetIndexBuffer(stage.Buffers.IndexBuffer, IndexFormat.UInt32); //Extract format and type cl.SetGraphicsResourceSet(0, camera.ResourceSet); 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 == target) { _frameworkMessenger.Report("Warning: A distortion 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 }); if (retrieved == target) { _frameworkMessenger.Report("Warning: A distortion stage is attempting to draw a surface onto itself. Aborting"); return; } t1 = retrieved == null ? _surfaceManager.SingleWhitePixel.ResourceSet_TexWrap : batch.TextureMode1 == TextureCoordinateMode.Mirror ? retrieved.ResourceSet_TexMirror : retrieved.ResourceSet_TexWrap; } cl.SetGraphicsResourceSet(2, t1); cl.DrawIndexed((uint)batch.NumIndices, 1, (uint)batch.StartIndex, 0, 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); }
public void Render(CommandList cl, ISystemComponents systemComponents) { var framebuffer = systemComponents.Device.SwapchainFramebuffer; _drawStageModel.ClearDynamicDrawQueue(); CalculateAndDraw((int)framebuffer.Width, (int)framebuffer.Height); _drawStageModel.Process(); cl.SetFramebuffer(framebuffer); cl.ClearDepthStencil(1.0f); var surface = new GpuSurface { Type = GpuSurfaceType.SwapChainOutput, Framebuffer = framebuffer, Texture = null, TextureView = null, ResourceSet_TexMirror = null, ResourceSet_TexWrap = null }; _drawStageRenderer.Render(cl, _drawStageModel, surface, _camera); }
private void DisposeOfASurface(GpuSurface surface) { surface.Framebuffer?.Dispose(); surface.ResourceSet_TexWrap?.Dispose(); surface.ResourceSet_TexMirror?.Dispose(); surface.Texture?.Dispose(); surface.TextureView?.Dispose(); }
private void UpdateSamplerUniformBuffer(CommandList cl, GpuSurface source) { var factors = new DownSampleFactors { TexelSize = new Vector2(1.0f / (1.0f * source.Texture.Width), 1.0f / (1.0f * source.Texture.Height)), NumberOfSamples = _downSamplerValues.NumberOfSamples((ResizeSamplerType)_sampleType) }; cl.UpdateBuffer(_samplerFactorsUniformBlockBuffer, 0, ref factors); }
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); }
public void Render(CommandList cl, IDistortionStageModel stage, GpuSurface source, GpuSurface target, ICameraModel2D camera) { if (cl == null || stage == null || source == null || target == null || camera == null) { _frameworkMessenger.Report("Warning: you are feeding the Distortion Stage Renderer null inputs, aborting"); return; } _heightRenderer.Render(cl, stage, stage.HeightMapSurface, camera); _gradientShiftRenderer.Render(cl, stage, stage.HeightMapSurface, stage.GradientShiftSurface); _distortionRenderer.Render(cl, stage, source, stage.GradientShiftSurface, target); }
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); }
public void Render(CommandList cl, IBlur1DStageModel stage, GpuSurface source, GpuSurface target) { if (cl == null || stage == null || source == null || target == null) { _frameworkMessenger.Report("Warning: you are feeding the Blur1D Stage Renderer null inputs, aborting"); return; } //Downsample _blurSamplingRenderer.Render(cl, source, stage.LinearSampledSurface, stage.SampleType); //Blur _singlePassGaussianBlurRenderer.Render(cl, stage.TexelShiftSize, stage.NumberSamples, stage.LinearSampledSurface, stage.AnistropicallySampledSurface); //Mix _blurResultMixingRenderer.Render(cl, stage.MixAmount, source, stage.AnistropicallySampledSurface, target); }
public bool Add(ulong id, GpuSurface surface) { if (surface == null) { _frameworkMessenger.Report("GpuSurfaceCollection: Will not add null surface to collection"); return(false); } if (_surfaces.ContainsKey(id)) { _frameworkMessenger.Report("GpuSurfaceCollection: Unable to add surface, ulong exists in collection"); return(false); } _surfaces.Add(id, surface); return(true); }
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); }
public void Render(CommandList cl, IBloomStageModel stage, GpuSurface source, GpuSurface target) { if (cl == null || stage == null || source == null || target == null) { _frameworkMessenger.Report("Warning: you are feeding the Bloom Stage Renderer null inputs, aborting"); return; } //Downsample _bloomSamplingRenderer.Render(cl, stage.BrightnessThreshold, source, stage.LinearSampledSurface0, stage.SampleType); //Blur Horizontally _singlePassGaussianBlurRenderer.Render(cl, new Vector2(stage.TexelShiftSize.X, 0.0f), stage.NumberSamples, stage.LinearSampledSurface0, stage.LinearSampledSurface1); //Blur Vertically _singlePassGaussianBlurRenderer.Render(cl, new Vector2(0.0f, stage.TexelShiftSize.Y), stage.NumberSamples, stage.LinearSampledSurface1, stage.AnistropicallySampledSurface); //Mix _bloomResultMixingRenderer.Render(cl, stage, source, stage.AnistropicallySampledSurface, target); }
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); }
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); }
public void Render(CommandList cl, ICustomVeldridStageModel stage, GpuSurface t0, GpuSurface t1, GpuSurface t2, GpuSurface t3, GpuSurface target) { if (cl == null || stage == null) { _frameworkMessenger.Report("Warning: you are feeding a Custom Veldrid Stage Renderer null inputs, aborting"); return; } //Auto set render target if not done in user code if (target != null) { cl.SetFramebuffer(target.Framebuffer); } var tex0 = t0 == null ? _gpuSurfaceManager.SingleWhitePixel.ResourceSet_TexWrap : t0.ResourceSet_TexWrap; var tex1 = t1 == null ? _gpuSurfaceManager.SingleWhitePixel.ResourceSet_TexWrap : t1.ResourceSet_TexWrap; var tex2 = t2 == null ? _gpuSurfaceManager.SingleWhitePixel.ResourceSet_TexWrap : t2.ResourceSet_TexWrap; var tex3 = t3 == null ? _gpuSurfaceManager.SingleWhitePixel.ResourceSet_TexWrap : t3.ResourceSet_TexWrap; stage.CustomStage.Render(cl, _systemComponents.Device.RawVeldridDevice, tex0, tex1, tex2, tex3, target == null ? null : target.Framebuffer); }
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); }
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); }
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); } }