Example #1
0
        }                                                               // 当前输出的画布的像素单精度浮点数个数

        public Renderer(int bufferW = 512, int bufferH = 512, PixelFormat outPixelFormat = PixelFormat.Format24bppRgb)
        {
            this.BackBufferWidth  = bufferW;
            this.BackBufferHeight = bufferH;

            this.OutPxielFormat     = outPixelFormat;
            this.OutPixelFormatSize = GetDevicePixelSize(outPixelFormat);

            this.defaultFrameBuffer = new FrameBuffer(bufferW, bufferH);
            this.FrameBuffer        = this.defaultFrameBuffer; // using default buffer

            this.frontBuffer = new Buffer_Color(bufferW, bufferH);

            State       = new RendererState(this);
            GlobalState = new GlobalRenderSstate();
            Rasterizer  = new Rasterizer(this);
            ShaderData  = new ShaderData(1);
            ShaderMgr   = new ShaderLoadMgr(this);

            if (Instance == null)
            {
                Instance = this;
            }
        }
Example #2
0
        private void FullScreenBlurHandle()
        {
            if (!GlobalState.fullscreen_blur)
            {
                return;
            }
            var w          = BackBufferWidth;
            var h          = BackBufferHeight;
            var backbuffer = FrameBuffer.Attachment.ColorBuffer[0];

            if (blur_src_buffer == null ||
                blur_src_buffer.Len != w * h)
            {
                blur_src_buffer = new Buffer_Color(w, h);
            }
            backbuffer.CopyTo(blur_src_buffer);
            var sampleOffset = new int[]
            {     //x, y
                // 1
                -1, 0,
                1, 0,
                0, 1,
                0, -1,
                -1, -1,
                1, -1,
                -1, 1,
                1, 1,
            };
            var sampleCount      = sampleOffset.Length;
            var half_sampleCount = sampleCount / 2;

            var maxOX = w - 1;
            var maxOY = h - 1;

            var resampleCount = GlobalState.fullscreen_blur_resample_count;

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    var srcPosColor = backbuffer.Get(x, y);
                    for (int rs = 0; rs < resampleCount; rs++)
                    {
                        for (int i = 0; i < sampleCount; i += 2)
                        {
                            var ox = sampleOffset[i] * (rs + 1) + x;
                            var oy = sampleOffset[i + 1] * (rs + 1) + y;
                            if (ox < 0)
                            {
                                ox = 0;
                            }
                            if (ox > maxOX)
                            {
                                ox = maxOX;
                            }
                            if (oy < 0)
                            {
                                oy = 0;
                            }
                            if (oy > maxOY)
                            {
                                oy = maxOY;
                            }
                            srcPosColor += blur_src_buffer[ox, oy];
                        }
                    }
                    srcPosColor /= half_sampleCount * resampleCount + 1;
                    FrameBuffer.WriteColor(0, x, y, srcPosColor, ColorMask.RGBA);
                }
            }
        }
Example #3
0
        private void MSAAHandle()
        {
            var w          = BackBufferWidth;
            var h          = BackBufferHeight;
            var backbuffer = FrameBuffer.Attachment.ColorBuffer[0];

            if (AA_src_buffer == null ||
                AA_src_buffer.Len != w * h)
            {
                AA_src_buffer = new Buffer_Color(w, h);
            }
            backbuffer.CopyTo(AA_src_buffer);
            var sampleOffset = new int[]
            {     //x, y
                // 1
                -1, 0,
                1, 0,
                //0,1,
                //0,-1,
                //-1, -1,
                //1, -1,
                //-1, 1,
                //1, 1,
            };
            var sampleCount      = sampleOffset.Length;
            var half_sampleCount = sampleCount / 2;

            var maxOX = w - 1;
            var maxOY = h - 1;

            var resampleCount = GlobalState.aa_resample_count;

            for (int i = 0; i < AA_edge_count; i += 2)
            {
                var x           = AA_edgePosList[i];
                var y           = AA_edgePosList[i + 1];
                var srcPosColor = backbuffer.Get(x, y);
                for (int rs = 0; rs < resampleCount; rs++)
                {
                    for (int j = 0; j < sampleCount; j += 2)
                    {
                        var ox = sampleOffset[j] * (rs + 1) + x;
                        var oy = sampleOffset[j + 1] * (rs + 1) + y;
                        if (ox < 0)
                        {
                            ox = 0;
                        }
                        if (ox > maxOX)
                        {
                            ox = maxOX;
                        }
                        if (oy < 0)
                        {
                            oy = 0;
                        }
                        if (oy > maxOY)
                        {
                            oy = maxOY;
                        }
                        srcPosColor += AA_src_buffer[ox, oy];
                    }
                }
                srcPosColor /= half_sampleCount * resampleCount + 1;
                FrameBuffer.WriteColor(0, x, y, srcPosColor, ColorMask.RGBA);
            }
        }
Example #4
0
        private void AAEdgePickup()
        {
            var depthbuff = FrameBuffer.Attachment.DepthBuffer;
            var w         = BackBufferWidth;
            var h         = BackBufferHeight;

            if (AA_edgePosList == null ||
                AA_edgePosList.Length != w * h)
            {
                AA_edgePosList = new int[w * h];
            }
            AA_edge_count = 0;

            var sampleOffset = new int[]
            {     //x, y
                // 1
                //-1, -1,
                //1, -1,
                -1, 1,
                1, 1,
            };
            var sampleCount = sampleOffset.Length;

            var maxOX = w - 1;
            var maxOY = h - 1;

            var edgeColor     = Vector4.red;
            var edge_thresold = GlobalState.edge_thresold;
            var show_edge     = GlobalState.show_edge;

            var backbuffer = FrameBuffer.Attachment.ColorBuffer[0];

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    var depth = depthbuff.Get(x, y);

                    var isEdge = false;
                    for (int i = 0; i < sampleCount; i += 2)
                    {
                        var ox = sampleOffset[i] + x;
                        var oy = sampleOffset[i + 1] + y;
                        if (ox < 0)
                        {
                            ox = 0;
                        }
                        if (ox > maxOX)
                        {
                            ox = maxOX;
                        }
                        if (oy < 0)
                        {
                            oy = 0;
                        }
                        if (oy > maxOY)
                        {
                            oy = maxOY;
                        }
                        var offsetDepth = depthbuff.Get(ox, oy);
                        if (float.IsNaN(depth))
                        {
                            if (float.IsNaN(offsetDepth))
                            {
                                continue;
                            }
                            else
                            {
                                isEdge = true;
                                break;
                            }
                        }
                        else
                        {
                            if (float.IsNaN(offsetDepth))
                            {
                                isEdge = true;
                                break;
                            }
                        }

                        if (Math.Abs(depth - offsetDepth) > edge_thresold)
                        {
                            isEdge = true;
                            break;
                        }
                    }
                    if (isEdge)
                    {
                        if (show_edge)
                        {
                            FrameBuffer.WriteColor(0, x, y, edgeColor, ColorMask.RGBA);
                        }
                        AA_edgePosList[AA_edge_count]     = x;
                        AA_edgePosList[AA_edge_count + 1] = y;
                        AA_edge_count += 2;
                    }
                }
            }
        }
Example #5
0
 public void Clear(ClearFlag flag = ClearFlag.ColorBuffer | ClearFlag.DepthBuffer | ClearFlag.StencilBuffer)
 {
     FrameBuffer.Clear(flag);
 }