Ejemplo n.º 1
0
        internal void CreateResources(Int2 swapchainSize, IShaderInput sceneData)
        {
            ThrowIfDisposed();

            //Dispose of the old target
            depthTarget?.Dispose();

            //Dispose of the old sampler
            depthSampler?.Dispose();

            //Create the new render target
            depthTarget = DeviceTexture.CreateDepthTarget((targetSize, targetSize), depthFormat, scene);
            //Create sampler
            depthSampler = new DeviceSampler(scene.LogicalDevice, depthTarget, disposeTexture: false);

            //Bind inputs to the renderer
            renderer.BindGlobalInputs(new IShaderInput[] { sceneData, cameraBuffer });

            //Bind the targets to the renderer
            renderer.BindTargets(new [] { depthTarget });

            //Tell the renderer to allocate its resources based on the data we've provided
            renderer.CreateResources();

            //Store the aspect of the swapchain, we need it later to calculate the shadow frustum
            swapchainAspect = (float)swapchainSize.X / swapchainSize.Y;
        }
Ejemplo n.º 2
0
        internal void CreateResources(DeviceTexture blurTarget)
        {
            ThrowIfDisposed();

            //Dispose of the resources
            outputTarget?.Dispose();
            inputSampler?.Dispose();
            outputSampler?.Dispose();

            //Create a output target (same format and size as the blur-target)
            outputTarget = DeviceTexture.CreateColorTarget(blurTarget.Size, blurTarget.Format, scene);

            //Create samplers
            inputSampler  = new DeviceSampler(scene.LogicalDevice, blurTarget, disposeTexture: false);
            outputSampler = new DeviceSampler(scene.LogicalDevice, outputTarget, disposeTexture: false);

            //Bind the input
            renderer.BindGlobalInputs(new IShaderInput[] { inputSampler });

            //Bind the target
            renderer.BindTargets(new [] { outputTarget });

            //Tell the renderer to allocate its resources based on the data we've provided
            renderer.CreateResources();
        }
        internal void CreateResources(DeviceTexture blurTarget)
        {
            ThrowIfDisposed();

            //Dispose of the resources
            targetB?.Dispose();
            samplerHor?.Dispose();
            samplerVer?.Dispose();

            //Create a temp target (same format and size as the blur-target) so we can ping-point
            //between the original target and this temp target for each blur step
            targetB = DeviceTexture.CreateColorTarget(blurTarget.Size, blurTarget.Format, scene);

            //Create samplers
            samplerHor = new DeviceSampler(scene.LogicalDevice, blurTarget, disposeTexture: false);
            samplerVer = new DeviceSampler(scene.LogicalDevice, targetB, disposeTexture: false);

            //Bind the inputs
            rendererHor.BindGlobalInputs(new IShaderInput[] { samplerHor });
            rendererVer.BindGlobalInputs(new IShaderInput[] { samplerVer });

            //Bind the targets
            rendererHor.BindTargets(new [] { targetB });
            rendererVer.BindTargets(new [] { blurTarget });

            //Tell the renderers to allocate their resources based on the data we've provided
            rendererHor.CreateResources();
            rendererVer.CreateResources();
        }
Ejemplo n.º 4
0
        internal void CreateResources(Int2 swapchainSize)
        {
            ThrowIfDisposed();

            //Dispose of the old target
            bloomTarget?.Dispose();

            //Dispose of the old sampler
            bloomSampler?.Dispose();

            //Create the new render target
            bloomTarget = DeviceTexture.CreateColorTarget(
                size: (swapchainSize * targetSizeMultiplier).RoundToInt(), bloomFormat, scene);

            //Create sampler
            bloomSampler = new DeviceSampler(scene.LogicalDevice, bloomTarget, disposeTexture: false);

            //Bind inputs to the renderer
            renderer.BindGlobalInputs(new IShaderInput[] { gbufferTechnique.ColorOutput });

            //Bind the targets to the renderer
            renderer.BindTargets(new [] { bloomTarget });

            //Tell the renderer to allocate its resources based on the data we've provided
            renderer.CreateResources();

            //Initialize the blurTechnique, point it to the bloom-target
            blurTechnique.CreateResources(bloomTarget);
        }
Ejemplo n.º 5
0
        public static ISampler GetSampler(SamplerMetricType metricType)
        {
            ISampler sampler;

            switch (metricType)
            {
            case SamplerMetricType.FPS:
                sampler = new FPSSampler();
                break;

            case SamplerMetricType.SystemMemory:
                sampler = new SystemMemorySampler();
                break;

            case SamplerMetricType.ProfilerMemory:
                sampler = new ProfilerMemorySampler();
                break;

            case SamplerMetricType.XLuaMemory:
                sampler = new XLuaMemorySampler();
                break;

            case SamplerMetricType.Device:
                sampler = new DeviceSampler();
                break;

            case SamplerMetricType.App:
                sampler = new AppSampler();
                break;

            case SamplerMetricType.Battery:
                sampler = new BatterySampler();
                break;

            case SamplerMetricType.CPU:
                sampler = new CPUSampler();
                break;

            case SamplerMetricType.FrameTime:
                sampler = new FrameTimeSampler();
                break;

            case SamplerMetricType.Log:
                sampler = new LogSampler();
                break;

            default:
                sampler = null;
                break;
            }

            return(sampler);
        }
        internal void CreateResources(Int2 swapchainSize, IShaderInput sceneData)
        {
            ThrowIfDisposed();

            //Dispose of the old targets
            colorTarget?.Dispose();
            normalTarget?.Dispose();
            attributeTarget?.Dispose();
            depthTarget?.Dispose();

            //Dispose of the old samplers
            colorSampler?.Dispose();
            normalSampler?.Dispose();
            attributeSampler?.Dispose();
            depthSampler?.Dispose();

            //Create the new render targets
            colorTarget     = DeviceTexture.CreateColorTarget(swapchainSize, colorFormat, scene);
            normalTarget    = DeviceTexture.CreateColorTarget(swapchainSize, normalFormat, scene);
            attributeTarget = DeviceTexture.CreateColorTarget(swapchainSize, attributeFormat, scene);
            depthTarget     = DeviceTexture.CreateDepthTarget(swapchainSize, depthFormat, scene);

            //Create samplers for the targets
            colorSampler     = new DeviceSampler(scene.LogicalDevice, colorTarget, disposeTexture: false);
            normalSampler    = new DeviceSampler(scene.LogicalDevice, normalTarget, disposeTexture: false);
            attributeSampler = new DeviceSampler(scene.LogicalDevice, attributeTarget, disposeTexture: false);
            depthSampler     = new DeviceSampler(scene.LogicalDevice, depthTarget, disposeTexture: false);

            //Bind inputs to the renderer
            renderer.BindGlobalInputs(new IShaderInput[] { sceneData, cameraBuffer });

            //Bind the targets to the renderer
            renderer.BindTargets(new [] { colorTarget, normalTarget, attributeTarget, depthTarget });

            //Tell the renderer to allocate its resources based on the data we've provided
            renderer.CreateResources();
        }
Ejemplo n.º 7
0
        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);
        }