Пример #1
0
        private void CreateFramebuffers()
        {
            if (_downsampler != null)
            {
                _downsampler.ForEach(a => a.Reset());
            }
            if (_upsample != null)
            {
                _upsample.ForEach(a => a.Reset());
            }

            _downsampler = new List <Framebuffer>();
            _upsample    = new List <Framebuffer>();

            Vector2 windowSize = Pipeline.ConnectedWindow.WindowSize;

            float minDim     = (float)Math.Min(windowSize.X, windowSize.Y);
            float maxIter    = (Radius - 8.0f) + (float)(Math.Log(minDim) / Math.Log(2));
            int   maxIterInt = (int)maxIter;

            _iterations = Math.Max(Math.Min(MAXBLOOMSTEPS, maxIterInt), 1);

            _sampleSize     = .5f + maxIter - maxIterInt;
            _thresholdCurve = new Vector4(
                Threshold - Knee,
                Knee * 2,
                0.25f / Math.Max(1e-5f, Knee),
                Threshold);

            float intens = (Intensity * INTENSITY);

            _bloomColor = new Color4(Color.R * intens, Color.G * intens, Color.B * intens, 1f);

            PixelInformation pixel = new PixelInformation(PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.Float);

            Vector2     texSize = windowSize;
            Framebuffer f       = new Framebuffer(texSize);

            f.Append("0", new ColorAttachment(0, pixel));
            f.Append("1", new ColorAttachment(1, pixel));
            _downsampler.Add(f);
            for (int i = 0; i < _iterations; i++)
            {
                texSize /= 2;

                f = new Framebuffer(texSize);
                f.Append("0", new ColorAttachment(0, pixel));
                _downsampler.Add(f);

                if (i == _iterations - 1)
                {
                    break;
                }
                f = new Framebuffer(texSize);
                f.Append("0", new ColorAttachment(0, pixel));
                _upsample.Add(f);
            }
        }
Пример #2
0
        /// <summary>
        /// This creates a finished setup for a framebuffer.
        /// </summary>
        public static Framebuffer CreateWindowFramebuffer(IFramebufferWindow window, int multisamples = 0, PixelInformation?pixelInformation = null, bool depth = true)
        {
            Framebuffer framebuffer = new Framebuffer(window);

            framebuffer.Append("color", new ColorAttachment(0, pixelInformation.GetValueOrDefault(PixelInformation.RGBA_LDR), multisamples: multisamples));

            if (depth)
            {
                RenderbufferAttachment depthAttach = RenderbufferAttachment.GenerateDepth();
                depthAttach.Multisample = multisamples;
                framebuffer.AppendRenderbuffer(depthAttach);
            }

            return(framebuffer);
        }