コード例 #1
0
            protected override ITextureFilter CreateFilter(ITextureFilter input)
            {
                Func <TextureSize, TextureSize> transform = s => new TextureSize(2 * s.Width, 2 * s.Height);

                float[] arguments  = { EdgeStrength, Sharpness };
                string  fastToggle = FastMethod ? "FAST_METHOD=1;" : "";

                var pass0 = CompileShader("super-xbr.hlsl", entryPoint: "main_fragment", macroDefinitions: "Pass = 0;" + fastToggle).Configure(transform: transform, arguments: arguments);
                var pass1 = CompileShader("super-xbr.hlsl", entryPoint: "main_fragment", macroDefinitions: "Pass = 1;" + fastToggle).Configure(arguments: arguments);
                var pass2 = CompileShader("super-xbr.hlsl", entryPoint: "main_fragment", macroDefinitions: "Pass = 2;" + fastToggle).Configure(arguments: arguments);

                // Skip if downscaling
                if (Renderer.TargetSize.Width <= input.Output.Size.Width &&
                    Renderer.TargetSize.Height <= input.Output.Size.Height)
                {
                    return(input);
                }

                ITextureFilter xbr = input
                                     .Apply(pass0)
                                     .Apply(pass1);

                return(ThirdPass
                    ? (ITextureFilter)xbr.Apply(pass2)
                    : xbr.Resize(xbr.Output.Size, offset: new Vector2(0.5f, 0.5f)));
            }
コード例 #2
0
            protected override ITextureFilter CreateFilter(ITextureFilter input)
            {
                Func <TextureSize, TextureSize> transform = s => new TextureSize(2 * s.Width, 2 * s.Height);

                float[] arguments  = { EdgeStrength, Sharpness };
                string  fastToggle = FastMethod ? "FAST_METHOD=1;" : "";

                var pass0 = new Shader(FromFile("super-xbr.hlsl", entryPoint: "main_fragment", compilerOptions: "Pass = 0;" + fastToggle))
                {
                    Transform = transform, Arguments = arguments
                };
                var pass1 = new Shader(FromFile("super-xbr.hlsl", entryPoint: "main_fragment", compilerOptions: "Pass = 1;" + fastToggle))
                {
                    Arguments = arguments
                };
                var pass2 = new Shader(FromFile("super-xbr.hlsl", entryPoint: "main_fragment", compilerOptions: "Pass = 2;" + fastToggle))
                {
                    Arguments = arguments
                };

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

                ITextureFilter xbr = input
                                     .Apply(pass0)
                                     .Apply(pass1);

                return(ThirdPass
                    ? xbr.Apply(pass2)
                    : xbr.Resize(xbr.Size(), offset: new Vector2(0.5f, 0.5f)));
            }
コード例 #3
0
            private void ConvolveAndCalcR(ITextureFilter input, ITextureFilter sh, out ITextureFilter mean, out ITextureFilter r)
            {
                var Convolver = CompileShader("SinglePassConvolver.hlsl").Configure(format: input.Output.Format);
                var CalcR     = CompileShader("CalcR.hlsl").Configure(format: TextureFormat.Float16);

                mean = input.Apply(Convolver);
                r    = CalcR.ApplyTo(input, mean, sh);
            }
コード例 #4
0
            private void ConvolveAndCalcR(ITextureFilter input, ITextureFilter sh, out ITextureFilter mean, out ITextureFilter r)
            {
                var Convolver = new Shader(FromFile("SinglePassConvolver.hlsl"))
                {
                    Format = input.Output.Format
                };
                var CalcR = new Shader(FromFile("CalcR.hlsl"))
                {
                    Format = TextureFormat.Float16
                };

                mean = input.Apply(Convolver);
                r    = CalcR.ApplyTo(input, mean, sh);
            }
コード例 #5
0
            public ITextureFilter CreateFilter(ITextureFilter original, ITextureFilter initial)
            {
                ITextureFilter result;
                var            HQDownscaler = (IScaler) new Bicubic(0.75f, false);

                // Calculate Sizes
                var inputSize  = original.Size();
                var targetSize = TargetSize();

                string macroDefinitions = "";

                if (Softness == 0.0f)
                {
                    macroDefinitions += "SkipSoftening = 1;";
                }
                if (Strength == 0.0f)
                {
                    return(initial);
                }

                // Compile Shaders
                var Diff = new Shader(FromFile("Diff.hlsl"))
                {
                    Format = TextureFormat.Float16
                };

                var SuperRes = new Shader(FromFile("SuperRes.hlsl", compilerOptions: macroDefinitions))
                {
                    Arguments = new[] { Strength, Softness }
                };
                var FinalSuperRes = new Shader(FromFile("SuperRes.hlsl", compilerOptions: macroDefinitions + "FinalPass = 1;"))
                {
                    Arguments = new[] { Strength }
                };

                var GammaToLab    = new Shader(FromFile("../Common/GammaToLab.hlsl"));
                var LabToGamma    = new Shader(FromFile("../Common/LabToGamma.hlsl"));
                var LinearToGamma = new Shader(FromFile("../Common/LinearToGamma.hlsl"));
                var GammaToLinear = new Shader(FromFile("../Common/GammaToLinear.hlsl"));
                var LabToLinear   = new Shader(FromFile("../Common/LabToLinear.hlsl"));
                var LinearToLab   = new Shader(FromFile("../Common/LinearToLab.hlsl"));

                // Skip if downscaling
                if ((targetSize <= inputSize).Any)
                {
                    return(original);
                }

                // Initial scaling
                if (initial != original)
                {
                    // Always correct offset (if any)
                    var filter = initial as IOffsetFilter;
                    if (filter != null)
                    {
                        filter.ForceOffsetCorrection();
                    }

                    result = initial.SetSize(targetSize).Apply(GammaToLinear);
                }
                else
                {
                    result = original.Apply(GammaToLinear).Resize(targetSize, tagged: true);
                }

                for (int i = 1; i <= Passes; i++)
                {
                    // Downscale and Subtract
                    ITextureFilter diff;
                    if (LegacyDownscaling)
                    {
                        var loRes = result.Resize(inputSize, downscaler: HQDownscaler);
                        diff = Diff.ApplyTo(loRes, original);
                    }
                    else
                    {
                        diff = DownscaleAndDiff(result, original, inputSize);
                    }

                    // Update result
                    result = (i != Passes ? SuperRes : FinalSuperRes).ApplyTo(result, diff);
                }

                return(result);
            }
コード例 #6
0
            public ITextureFilter CreateFilter(ITextureFilter original, ITextureFilter initial)
            {
                ITextureFilter result;

                // Calculate Sizes
                var inputSize  = original.Size();
                var targetSize = TargetSize();

                // Compile Shaders
                var SharpDiff = CompileShader("Diff.hlsl", macroDefinitions: "MODE = 0;")
                                .Configure(format: TextureFormat.Float16);
                var Diff = CompileShader("Diff.hlsl", macroDefinitions: String.Format("MODE = {0};", Mode == SSSRMode.Sharp ? 0 : 1))
                           .Configure(format: TextureFormat.Float16);
                var SuperRes      = CompileShader("SuperRes.hlsl");
                var FinalSuperRes = CompileShader("SuperRes.hlsl", macroDefinitions: "FinalPass = 1;" + (LinearLight ? "LinearLight = 1;" : ""));
                var GammaToLinear = CompileShader("GammaToLinear.hlsl");

                SharpDiff["spread"]    = 1 / Locality;
                SharpDiff["oversharp"] = OverSharp;

                Diff["spread"]    = 1 / Locality;
                Diff["oversharp"] = OverSharp;

                // Skip if downscaling
                if ((targetSize <= inputSize).Any)
                {
                    return(original);
                }

                // Initial scaling
                if (initial != original)
                {
                    // Always correct offset (if any)
                    var filter = initial as IOffsetFilter;
                    if (filter != null)
                    {
                        filter.ForceOffsetCorrection();
                    }

                    result = initial.SetSize(targetSize, tagged: true);
                    if (LinearLight)
                    {
                        original = original.Apply(GammaToLinear);
                        result   = result.Apply(GammaToLinear);
                    }
                }
                else
                {
                    if (LinearLight)
                    {
                        original = original.Apply(GammaToLinear);
                    }
                    result = original.Resize(targetSize, tagged: true);
                }

                for (int i = 1; i <= Passes; i++)
                {
                    ITextureFilter diff;

                    // Downscale and Subtract
                    var loRes = Downscale(result, original, inputSize);

                    // Calculate difference
                    if (Mode == SSSRMode.Hybrid && i == 1)
                    {
                        diff = SharpDiff.ApplyTo(loRes, original);
                    }
                    else
                    {
                        diff = Diff.ApplyTo(loRes, original);
                    }

                    // Update result
                    result = (i != Passes ? SuperRes : FinalSuperRes).ApplyTo(result, diff, loRes);
                }

                return(result);
            }