Esempio n. 1
0
            protected override ITextureFilter CreateFilter(ITextureFilter input)
            {
                if (!Renderer.IsDx11Avail)
                {
                    Renderer.FallbackOccurred = true; // Warn user via player stats OSD
                    return(input);                    // DX11 is not available; fallback
                }

                Func <TextureSize, TextureSize> transform = s => new TextureSize(2 * s.Height, s.Width);

                var shaderPass1 = GetShader(Neurons1);
                var shaderPass2 = GetShader(Neurons2);
                var interleave  = new Shader(FromFile("Interleave.hlsl"))
                {
                    Transform = transform
                };

                if ((Renderer.TargetSize <= input.Size()).Any)
                {
                    return(input);
                }

                var yuv         = input.ConvertToYuv();
                var composition = input.Decompose();

                var resultY = interleave.ApplyTo(composition.Luma, shaderPass1.ApplyTo(yuv));
                var luma    = interleave.ApplyTo(resultY, shaderPass2.ApplyTo(resultY));

                composition = luma.ComposeWith(composition.Chroma, chromaOffset: new Vector2(-0.25f, -0.25f));
                var result = ChromaScaler.ScaleChroma(composition);

                return(result.Convolve(null, offset: new Vector2(0.5f, 0.5f)));
            }
            protected override ITextureFilter CreateFilter(ITextureFilter input)
            {
                if (!Renderer.IsOpenClAvail || Renderer.RenderQuality.PerformanceMode())
                {
                    Renderer.FallbackOccurred = true; // Warn user via player stats OSD
                    return(input);                    // OpenCL is not available, or UNORM8 textures used (not supported); fallback
                }

                Func <TextureSize, TextureSize> transformWidth  = s => new TextureSize(2 * s.Width, s.Height);
                Func <TextureSize, TextureSize> transformHeight = s => new TextureSize(s.Width, 2 * s.Height);

                var neuronCount1 = s_NeuronCount[(int)Neurons1];
                var neuronCount2 = s_NeuronCount[(int)Neurons2];
                var weights1     = s_Weights[(int)Neurons1];
                var buffer1      = Renderer.CreateClBuffer(weights1);
                var buffer2      = buffer1;

                var differentWeights = neuronCount1 != neuronCount2;

                if (differentWeights)
                {
                    var weights2 = s_Weights[(int)Neurons2];
                    buffer2 = Renderer.CreateClBuffer(weights2);
                }

                var kernel  = GetKernel(); // Note Kernel is reused between different filters
                var shaderH = new NNedi3Kernel(kernel)
                {
                    Horizontal = true, Buffer = buffer1, NeuronCount = neuronCount1, Transform = transformWidth
                };
                var shaderV = new NNedi3Kernel(kernel)
                {
                    Horizontal = false, Buffer = buffer2, NeuronCount = neuronCount2, Transform = transformHeight, ReloadWeights = differentWeights
                };

                var sourceSize = input.Size();

                if ((Renderer.TargetSize <= sourceSize).Any)
                {
                    return(input);
                }

                var composition = input.Decompose();

                var nnedi3H = shaderH.ApplyTo(composition.Luma);
                var nnedi3V = shaderV.ApplyTo(nnedi3H);

                composition = nnedi3V.ComposeWith(composition.Chroma, chromaOffset: new Vector2(-0.25f, -0.25f));
                var result = ChromaScaler.ScaleChroma(composition);

                return(result.Convolve(null, offset: new Vector2(0.5f, 0.5f)));
            }