internal BoxBlurTechnique( ShaderProgram postVertProg, ShaderProgram blurFragProg, int sampleRange, float sampleScale, RenderScene scene, Logger logger = null) { if (postVertProg == null) { throw new ArgumentNullException(nameof(postVertProg)); } if (blurFragProg == null) { throw new ArgumentNullException(nameof(blurFragProg)); } if (scene == null) { throw new NullReferenceException(nameof(scene)); } this.scene = scene; //Setup renderer renderer = new Renderer(scene, logger); renderer.AddSpecialization(sampleRange); renderer.AddSpecialization(sampleScale); //Add a full-screen object to the renderer renderObject = new AttributelessObject(scene, vertexCount: 3, new TextureInfo[0]); renderer.AddObject(renderObject, postVertProg, blurFragProg, debugName: "fullscreen"); }
internal GaussianBlurTechnique( ShaderProgram postVertProg, ShaderProgram blurFragProg, int iterations, float sampleScale, RenderScene scene, Logger logger = null) { if (postVertProg == null) { throw new ArgumentNullException(nameof(postVertProg)); } if (blurFragProg == null) { throw new ArgumentNullException(nameof(blurFragProg)); } if (scene == null) { throw new NullReferenceException(nameof(scene)); } this.iterations = iterations; this.scene = scene; //Create renderers (2 so we can ping-pong between two targets) rendererHor = new Renderer(scene, logger); rendererHor.AddSpecialization(true); //IsHorizontal rendererHor.AddSpecialization(sampleScale); rendererVer = new Renderer(scene, logger); rendererVer.AddSpecialization(false); //NOT IsHorizontal rendererVer.AddSpecialization(sampleScale); //Add a full-screen object to both renderers renderObject = new AttributelessObject(scene, vertexCount: 3, new TextureInfo[0]); rendererHor.AddObject(renderObject, postVertProg, blurFragProg, debugName: "horizontal"); rendererVer.AddObject(renderObject, postVertProg, blurFragProg, debugName: "vertical"); }
internal GBufferTechnique( RenderScene scene, Logger logger = null) { if (scene == null) { throw new NullReferenceException(nameof(scene)); } this.scene = scene; //Create buffer for storing camera transformations cameraBuffer = new Memory.HostBuffer( scene.LogicalDevice, scene.MemoryPool, BufferUsages.UniformBuffer, size: CameraData.SIZE * scene.SwapchainCount); //Create renderer for rendering into the g-buffer targets renderer = new Renderer(scene, logger); renderer.AddSpecialization(scene.SwapchainCount); renderer.AddSpecialization(false); //NOT IsShadow swapchainIndexPushDataBinding = renderer.AddPushData <int>(); }
internal AmbientOcclusionTechnique( GBufferTechnique gbufferTechnique, ShaderProgram postVertProg, ShaderProgram aoFragProg, ShaderProgram boxBlurFragProg, RenderScene scene, Logger logger = null) { if (gbufferTechnique == null) { throw new NullReferenceException(nameof(gbufferTechnique)); } if (postVertProg == null) { throw new ArgumentNullException(nameof(postVertProg)); } if (aoFragProg == null) { throw new ArgumentNullException(nameof(aoFragProg)); } if (boxBlurFragProg == null) { throw new ArgumentNullException(nameof(boxBlurFragProg)); } if (scene == null) { throw new NullReferenceException(nameof(scene)); } this.gbufferTechnique = gbufferTechnique; this.scene = scene; this.logger = logger; //Create renderer for rendering the ao texture renderer = new Renderer(scene, logger); renderer.AddSpecialization(scene.SwapchainCount); renderer.AddSpecialization(sampleKernelSize); renderer.AddSpecialization(sampleRadius); renderer.AddSpecialization(sampleBias); swapchainIndexPushDataBinding = renderer.AddPushData <int>(); targetSizePushBinding = renderer.AddPushData <Int2>(); //Create random for generating the kernel and noise (using a arbitrary fixed seed) IRandom random = new ShiftRandom(seed: 1234); //Create the sample kernel Span <Float4> sampleKernel = stackalloc Float4[sampleKernelSize]; GenerateSampleKernel(random, sampleKernel); sampleKernelBuffer = DeviceBuffer.UploadData <Float4>( sampleKernel, scene, BufferUsages.UniformBuffer); //Create the rotation noise texture Float4Texture rotationNoiseTexture = TextureUtils.CreateRandomFloatTexture( random, min: (-1f, -1f, 0f, 0f), max: (1f, 1f, 0f, 0f), size: (noiseSize, noiseSize)); rotationNoiseSampler = new DeviceSampler(scene.LogicalDevice, texture: DeviceTexture.UploadTexture(rotationNoiseTexture, scene), repeat: true, pointFilter: true); //Add full-screen object for drawing the composition renderObject = new AttributelessObject(scene, vertexCount: 3, new TextureInfo[0]); renderer.AddObject(renderObject, postVertProg, aoFragProg, debugName: "fullscreen"); //Create a BlurTechnique for blurring the ao texture (to hide the ao sample pattern) blurTechnique = new BoxBlurTechnique( postVertProg, boxBlurFragProg, blurSampleRange, sampleScale: 1f, scene, logger); }
internal DeferredTechnique( GBufferTechnique gbufferTechnique, ShadowTechnique shadowTechnique, BloomTechnique bloomTechnique, AmbientOcclusionTechnique aoTechnique, TextureInfo reflectionTexture, ShaderProgram compositionVertProg, ShaderProgram compositionFragProg, RenderScene scene, Logger logger = null) { if (gbufferTechnique == null) { throw new NullReferenceException(nameof(gbufferTechnique)); } if (shadowTechnique == null) { throw new NullReferenceException(nameof(shadowTechnique)); } if (bloomTechnique == null) { throw new NullReferenceException(nameof(bloomTechnique)); } if (aoTechnique == null) { throw new NullReferenceException(nameof(aoTechnique)); } if (reflectionTexture.Texture == null) { throw new ArgumentNullException(nameof(reflectionTexture)); } if (compositionVertProg == null) { throw new ArgumentNullException(nameof(compositionVertProg)); } if (compositionFragProg == null) { throw new ArgumentNullException(nameof(compositionFragProg)); } if (scene == null) { throw new NullReferenceException(nameof(scene)); } this.gbufferTechnique = gbufferTechnique; this.shadowTechnique = shadowTechnique; this.bloomTechnique = bloomTechnique; this.aoTechnique = aoTechnique; this.scene = scene; //Create renderer for rendering the composition effects renderer = new Renderer(scene, logger); renderer.AddSpecialization(scene.SwapchainCount); swapchainIndexPushDataBinding = renderer.AddPushData <int>(); //Add full-screen object for drawing the composition renderObject = new AttributelessObject(scene, vertexCount: 3, new [] { reflectionTexture }); renderer.AddObject( renderObject, compositionVertProg, compositionFragProg, debugName: "fullscreen"); }