Пример #1
0
        public void Render(QbModel model)
        {
            ssao_geometryDepth.UseShader();
            geometryBuffer.BindFBOWritting();
            ssao_geometryDepth.WriteUniform("gWVP", camera.modelviewprojection);
            ssao_geometryDepth.WriteUniform("gWV", camera.view);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            model.Render();

            ssao.UseShader();
            geometryBuffer.BindFBOReading(TextureUnit.Texture1);
            SSAOBuffer.BindFBOWritting();
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.BindBuffer(BufferTarget.ArrayBuffer, quadBuffer);
            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, sizeof(float) * 3, 0);
            GL.DrawArrays(PrimitiveType.Quads, 0, 4);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            ssao_voxel.UseShader();
            SSAOBuffer.BindFBOReading(TextureUnit.Texture2);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            ssao_voxel.WriteUniform("modelview", camera.modelviewprojection);
            model.Render(ssao_voxel);
        }
Пример #2
0
        public override void Render(float x, float y, float width, float height)
        {
            quadInterpolation.UseShader();
            quadInterpolation.WriteUniform("mvp", Matrix4.CreateOrthographicOffCenter(-1f, 1f, -1f, 1f, -1, 1));

            data[0] = x;
            data[1] = y;
            data[2] = 0;
            data[3] = 1;
            data[4] = colors[0].R;
            data[5] = colors[0].G;
            data[6] = colors[0].B;

            data[7]  = x + width;
            data[8]  = y;
            data[9]  = 1;
            data[10] = 1;
            data[11] = colors[1].R;
            data[12] = colors[1].G;
            data[13] = colors[1].B;

            data[14] = x + width;
            data[15] = y + height;
            data[16] = 1;
            data[17] = 0;
            data[18] = colors[2].R;
            data[19] = colors[2].G;
            data[20] = colors[2].B;

            data[21] = x;
            data[22] = y + height;
            data[23] = 0;
            data[24] = 0;
            data[25] = colors[3].R;
            data[26] = colors[3].G;
            data[27] = colors[3].B;

            GL.BindBuffer(BufferTarget.ArrayBuffer, bufferID);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(sizeof(float) * data.Length), data, BufferUsageHint.DynamicDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.BindVertexArray(arrayID);
            GL.DrawArrays(PrimitiveType.Quads, 0, 4);
            GL.BindVertexArray(0);


            ShaderUtil.ResetShader();
        }
Пример #3
0
        public void write(string path, string name, QbModel model)
        {
            Client.OpenGLContextThread.Add(() =>
            {
                int Wwidth  = Client.window.Width;
                int Wheight = Client.window.Height;

                int framebuffer = GL.GenBuffer();
                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);

                int color = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, color);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, Wwidth, Wheight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, color, 0);

                int depth = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, depth);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent24, Wwidth, Wheight, 0, PixelFormat.DepthComponent, PixelType.UnsignedByte, IntPtr.Zero);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, TextureTarget.Texture2D, depth, 0);

                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);

                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);
                GL.DrawBuffers(1, new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0 });

                GL.ClearColor(0, 0, 0, 0);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                int minx  = 10000;
                int miny  = 10000;
                int minz  = 10000;
                int maxx  = 0;
                int maxy  = 0;
                int maxz  = 0;
                int sizex = 0;
                int sizey = 0;
                int sizez = 0;

                foreach (var matrix in model.matrices)
                {
                    if (!matrix.Visible)
                    {
                        continue;
                    }
                    if (matrix.minx < minx)
                    {
                        minx = matrix.minx;
                    }
                    if (matrix.maxx > maxx)
                    {
                        maxx = matrix.maxx;
                    }

                    if (matrix.miny < miny)
                    {
                        miny = matrix.miny;
                    }
                    if (matrix.maxy > maxy)
                    {
                        maxy = matrix.maxy;
                    }

                    if (matrix.minz < minz)
                    {
                        minz = matrix.minz;
                    }
                    if (matrix.maxz > maxz)
                    {
                        maxz = matrix.maxz;
                    }
                }

                sizex = maxx - minx;
                sizey = maxy - miny;
                sizez = maxz - minz;

                float backup = 0;

                if (sizey * 1.5f > 20)
                {
                    backup = sizey * 1.5f;
                }
                else if (sizex * 1.5f > 20)
                {
                    backup = sizex * 1.5f;
                }
                else
                {
                    backup = 20;
                }

                var centerpos = new Vector3((minx + ((maxx - minx) / 2)), (miny + ((maxy - miny) / 2)), (minz + ((maxz - minz) / 2)));
                var position  = centerpos + new Vector3(.5f, sizey * .65f, backup);
                Vector3 direction;

                Vector3.Subtract(ref centerpos, ref position, out direction);
                direction.Normalize();

                var cameraright = Vector3.Cross(direction, VectorUtils.UP);
                var cameraup    = Vector3.Cross(cameraright, direction);

                var view = Matrix4.LookAt(position, position + direction, cameraup);
                var modelviewprojection = view * Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45), (float)Wwidth / (float)Wheight, 1, 300);

                Shader voxelShader = ShaderUtil.GetShader("qb");

                voxelShader.UseShader();
                voxelShader.WriteUniform("modelview", modelviewprojection);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                model.RenderAll(voxelShader);

                string fullpath = Path.Combine(path, name + extension);
                using (FileStream f = new FileStream(fullpath, FileMode.OpenOrCreate))
                {
                    var bit       = Screenshot.ScreenShot(ReadBufferMode.ColorAttachment0);
                    bit           = cropImage(bit, new Rectangle(Wwidth / 4, 0, Wwidth - ((Wwidth / 4) * 2), Wheight));
                    bit           = bit.ResizeImage(ResizeKeepAspect(bit.Size, 400, 400));
                    byte[] buffer = new byte[0];
                    using (MemoryStream m = new MemoryStream())
                    {
                        bit.Save(m, System.Drawing.Imaging.ImageFormat.Png);
                        buffer = m.ToArray();
                    }

                    using (BinaryWriter w = new BinaryWriter(f))
                    {
                        w.Write(version);
                        w.Write((int)buffer.Length);
                        w.Write(buffer);

                        // note - just in case i allow extending the color pattet
                        // which i probably will
                        w.Write(colorpalletflag);
                        for (int i = 0; i < 10; i++)
                        {
                            var c = Singleton <GUI> .INSTANCE.Get <EmptyWidget>(GUIID.START_COLOR_SELECTORS + i).appearence.Get <PlainBackground>("background").color;
                            w.Write(c.R);
                            w.Write(c.G);
                            w.Write(c.B);
                        }

                        w.Write(model.version);
                        w.Write(model.colorFormat);
                        w.Write(model.zAxisOrientation);
                        w.Write(model.compressed);
                        w.Write(model.visibilityMaskEncoded);

                        w.Write((uint)model.matrices.Count);

                        for (int i = 0; i < model.numMatrices; i++)
                        {
                            QbMatrix m = model.matrices[i];
                            if (!m.Visible)
                            {
                                continue;
                            }

                            int startx = Math.Min(0, m.minx);
                            int starty = Math.Min(0, m.miny);
                            int startz = Math.Min(0, m.minz);

                            int width  = (int)(Math.Abs(Math.Min(0, m.minx)) + m.maxx + 1);
                            int height = (int)(Math.Abs(Math.Min(0, m.miny)) + m.maxy + 1);
                            int length = (int)(Math.Abs(Math.Min(0, m.minz)) + m.maxz + 1);

                            if (width < m.size.X)
                            {
                                width = (int)m.size.X;
                            }

                            if (height < m.size.Y)
                            {
                                height = (int)m.size.Y;
                            }

                            if (length < m.size.Z)
                            {
                                length = (int)m.size.Z;
                            }

                            w.Write(m.name);
                            w.Write((uint)width);
                            w.Write((uint)height);
                            w.Write((uint)length);

                            w.Write((int)m.position.X);
                            w.Write((int)m.position.Y);
                            w.Write((int)m.position.Z);

                            if (model.compressed == 0)
                            {
                                Voxel voxel;
                                for (int z = startz; z < startz + length; z++)
                                {
                                    for (int y = starty; y < starty + height; y++)
                                    {
                                        for (int x = startx; x < startx + width; x++)
                                        {
                                            int zz = model.zAxisOrientation == (int)0 ? z : (int)(length - z - 1);

                                            if (m.voxels.TryGetValue(m.GetHash(x, y, zz), out voxel))
                                            {
                                                Colort c = m.colors[voxel.colorindex];
                                                w.Write((byte)(c.R * 255));
                                                w.Write((byte)(c.G * 255));
                                                w.Write((byte)(c.B * 255));
                                                w.Write(voxel.alphamask);
                                            }
                                            else
                                            {
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
                    GL.DeleteTexture(color);
                    GL.DeleteTexture(depth);
                    GL.DeleteFramebuffer(framebuffer);
                }
            });
        }
Пример #4
0
        public void Render(QbModel model)
        {
            switch (wireFrameType)
            {
            case WireframeType.WireframeBlack:

                if (drawWireframe)
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                    GL.LineWidth(1);
                    wireframeShader.UseShader();
                    wireframeShader.WriteUniform("vHSV", new Vector3(1, 0f, 0));
                    wireframeShader.WriteUniform("modelview", camera.modelviewprojection);
                    model.getactivematrix.RenderAll(wireframeShader);
                }
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                GL.LineWidth(2);
                voxelShader.UseShader();
                voxelShader.WriteUniform("modelview", camera.modelviewprojection);
                selection.render(voxelShader);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                model.RenderAll(voxelShader);
                break;

            case WireframeType.WireframeColorMatch:
                if (drawWireframe)
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                    GL.LineWidth(1);
                    wireframeShader.UseShader();
                    wireframeShader.WriteUniform("vHSV", new Vector3(1, 1.1f, 1.1f));
                    wireframeShader.WriteUniform("modelview", camera.modelviewprojection);
                    model.getactivematrix.RenderAll(wireframeShader);
                }
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                GL.LineWidth(2);
                voxelShader.UseShader();
                voxelShader.WriteUniform("modelview", camera.modelviewprojection);
                selection.render(voxelShader);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                model.RenderAll(voxelShader);
                break;

            case WireframeType.SmartOutline:
                if (drawWireframe)
                {
                    GL.CullFace(CullFaceMode.Front);
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                    GL.LineWidth(2);
                    wireframeShader.UseShader();
                    wireframeShader.WriteUniform("vHSV", new Vector3(1, 1.5f, 1.0f));
                    wireframeShader.WriteUniform("modelview", camera.modelviewprojection);
                    model.getactivematrix.RenderAll(wireframeShader);
                }
                GL.CullFace(CullFaceMode.Back);
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                GL.LineWidth(2);
                voxelShader.UseShader();
                voxelShader.WriteUniform("modelview", camera.modelviewprojection);
                selection.render(voxelShader);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                model.RenderAll(voxelShader);
                break;
            }
        }