Exemple #1
0
        protected override void Draw()
        {
            base.Draw();

            if (shader == null)
            {
                shader = game.Shaders.Load(VertexShader.Colour, FragmentShader.Colour);
            }

            shader.Bind();

            batch.Add(new Vertex2d()
            {
                Colour = DrawInfo.Colour, Position = screenSpaceDrawQuad.BottomLeft
            });
            batch.Add(new Vertex2d()
            {
                Colour = DrawInfo.Colour, Position = screenSpaceDrawQuad.BottomRight
            });
            batch.Add(new Vertex2d()
            {
                Colour = DrawInfo.Colour, Position = screenSpaceDrawQuad.TopRight
            });
            batch.Add(new Vertex2d()
            {
                Colour = DrawInfo.Colour, Position = screenSpaceDrawQuad.TopLeft
            });
            batch.Draw();

            shader.Unbind();
        }
Exemple #2
0
            private void addLineQuads(Line line, RectangleF texRect)
            {
                Vector2 ortho     = line.OrthogonalDirection;
                Line    lineLeft  = new Line(line.StartPoint + ortho * radius, line.EndPoint + ortho * radius);
                Line    lineRight = new Line(line.StartPoint - ortho * radius, line.EndPoint - ortho * radius);

                Line screenLineLeft  = new Line(Vector2Extensions.Transform(lineLeft.StartPoint, DrawInfo.Matrix), Vector2Extensions.Transform(lineLeft.EndPoint, DrawInfo.Matrix));
                Line screenLineRight = new Line(Vector2Extensions.Transform(lineRight.StartPoint, DrawInfo.Matrix), Vector2Extensions.Transform(lineRight.EndPoint, DrawInfo.Matrix));
                Line screenLine      = new Line(Vector2Extensions.Transform(line.StartPoint, DrawInfo.Matrix), Vector2Extensions.Transform(line.EndPoint, DrawInfo.Matrix));

                quadBatch.Add(new TexturedVertex3D
                {
                    Position        = new Vector3(screenLineRight.EndPoint.X, screenLineRight.EndPoint.Y, 0),
                    TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
                    Colour          = colourAt(lineRight.EndPoint)
                });
                quadBatch.Add(new TexturedVertex3D
                {
                    Position        = new Vector3(screenLineRight.StartPoint.X, screenLineRight.StartPoint.Y, 0),
                    TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
                    Colour          = colourAt(lineRight.StartPoint)
                });

                // Each "quad" of the slider is actually rendered as 2 quads, being split in half along the approximating line.
                // On this line the depth is 1 instead of 0, which is done properly handle self-overlap using the depth buffer.
                // Thus the middle vertices need to be added twice (once for each quad).
                Vector3 firstMiddlePoint   = new Vector3(screenLine.StartPoint.X, screenLine.StartPoint.Y, 1);
                Vector3 secondMiddlePoint  = new Vector3(screenLine.EndPoint.X, screenLine.EndPoint.Y, 1);
                Color4  firstMiddleColour  = colourAt(line.StartPoint);
                Color4  secondMiddleColour = colourAt(line.EndPoint);

                for (int i = 0; i < 2; ++i)
                {
                    quadBatch.Add(new TexturedVertex3D
                    {
                        Position        = firstMiddlePoint,
                        TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
                        Colour          = firstMiddleColour
                    });
                    quadBatch.Add(new TexturedVertex3D
                    {
                        Position        = secondMiddlePoint,
                        TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
                        Colour          = secondMiddleColour
                    });
                }

                quadBatch.Add(new TexturedVertex3D
                {
                    Position        = new Vector3(screenLineLeft.EndPoint.X, screenLineLeft.EndPoint.Y, 0),
                    TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
                    Colour          = colourAt(lineLeft.EndPoint)
                });
                quadBatch.Add(new TexturedVertex3D
                {
                    Position        = new Vector3(screenLineLeft.StartPoint.X, screenLineLeft.StartPoint.Y, 0),
                    TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
                    Colour          = colourAt(lineLeft.StartPoint)
                });
            }
        private void glDrawQuad(Matrix m)
        {
            quadBatch.Add(new TexturedVertex3d()
            {
                Position        = Vector3.Transform(new Vector3(-QUAD_OVERLAP_FUDGE, -1.0f, 0.0f), m),
                TexturePosition = new Vector2(0, 0),
                Colour          = Color.White
            });
            quadBatch.Add(new TexturedVertex3d()
            {
                Position        = Vector3.Transform(new Vector3(1.0f + QUAD_OVERLAP_FUDGE, -1.0f, 0.0f), m),
                TexturePosition = new Vector2(0, 0),
                Colour          = Color.White
            });

            // Each "quad" of the slider is actually rendered as 2 quads, being split in half along the approximating line.
            // On this line the depth is 1 instead of 0, which is done properly handle self-overlap using the depth buffer.
            // Thus the middle vertices need to be added twice (once for each quad).
            Vector3 firstMiddlePoint  = Vector3.Transform(new Vector3(1.0f + QUAD_OVERLAP_FUDGE, QUAD_MIDDLECRACK_FUDGE, 1.0f), m);
            Vector3 secondMiddlePoint = Vector3.Transform(new Vector3(-QUAD_OVERLAP_FUDGE, QUAD_MIDDLECRACK_FUDGE, 1.0f), m);

            for (int i = 0; i < 2; ++i)
            {
                quadBatch.Add(new TexturedVertex3d()
                {
                    Position        = firstMiddlePoint,
                    TexturePosition = new Vector2(1.0f - 1.0f / (float)TextureSize.Width, 0),
                    Colour          = Color.White
                });
                quadBatch.Add(new TexturedVertex3d()
                {
                    Position        = secondMiddlePoint,
                    TexturePosition = new Vector2(1.0f - 1.0f / (float)TextureSize.Width, 0),
                    Colour          = Color.White
                });
            }

            quadBatch.Add(new TexturedVertex3d()
            {
                Position        = Vector3.Transform(new Vector3(-QUAD_OVERLAP_FUDGE, 1.0f, 0.0f), m),
                TexturePosition = new Vector2(0, 0),
                Colour          = Color.White
            });
            quadBatch.Add(new TexturedVertex3d()
            {
                Position        = Vector3.Transform(new Vector3(1.0f + QUAD_OVERLAP_FUDGE, 1.0f, 0.0f), m),
                TexturePosition = new Vector2(0, 0),
                Colour          = Color.White
            });
        }
Exemple #4
0
        public override void Draw()
        {
            if (Texture == null)
            {
                return;
            }

            // For billboarding
            Shader.SetGlobalProperty("g_InverseViewMatrix", InverseViewMatrix);

            // Taken from DrawNode3D, since we don't need the world transform for particle systems
            GLWrapper.SetBlend(Blending);

            Shader.Bind();

            // Force create a separate batch so we can use instanced rendering
            if (particleInstancedBatch == null)
            {
                particleInstancedBatch = new QuadBatch <TexturedVertex2D>(TexturedVertex2D.Stride * 4, 1);
            }

            var colourInfo = new ColourInfo {
                Colour = Color4.White
            };

            Texture.DrawQuad(new Quad(-0.5f, -0.5f, 1.0f, 1.0f), colourInfo, vertexAction: v => particleInstancedBatch.Add(v));

            // Set GPU buffer data
            Buffer.SetData(BufferData);

            Buffer.Bind();

            // Render instanced
            particleInstancedBatch.DrawInstanced(InstanceCount);

            Shader.Unbind();
        }
 internal void DrawQuad(Vector2 topLeft, Vector2 bottomRight, Color colour)
 {
     quadBatch.Add(new Vertex2d()
     {
         Position = new Vector2(topLeft.X, bottomRight.Y), Colour = colour
     });
     quadBatch.Add(new Vertex2d()
     {
         Position = bottomRight, Colour = colour
     });
     quadBatch.Add(new Vertex2d()
     {
         Position = new Vector2(bottomRight.X, topLeft.Y), Colour = colour
     });
     quadBatch.Add(new Vertex2d()
     {
         Position = topLeft, Colour = colour
     });
 }