Example #1
0
        private unsafe void CalculateRectangleVertices(UIImageDrawInfo *drawInfo, VertexPositionColorTextureSwizzle *vertex)
        {
            var currentPosition = drawInfo->LeftTopCornerWorld;

            // snap first pixel to prevent possible problems when left/top is in the middle of a pixel
            if (drawInfo->SnapImage)
            {
                var invW = 1.0f / currentPosition.W;
                var backBufferHalfWidth  = GraphicsContext.CommandList.RenderTarget.ViewWidth / 2;
                var backBufferHalfHeight = GraphicsContext.CommandList.RenderTarget.ViewHeight / 2;

                currentPosition.X *= invW;
                currentPosition.Y *= invW;
                currentPosition.X  = (float)(Math.Round(currentPosition.X * backBufferHalfWidth) / backBufferHalfWidth);
                currentPosition.Y  = (float)(Math.Round(currentPosition.Y * backBufferHalfHeight) / backBufferHalfHeight);
                currentPosition.X *= currentPosition.W;
                currentPosition.Y *= currentPosition.W;
            }

            var textureCoordX = new Vector2(drawInfo->Source.Left, drawInfo->Source.Right);
            var textureCoordY = new Vector2(drawInfo->Source.Top, drawInfo->Source.Bottom);

            // set the two first line of vertices
            for (var r = 0; r < 2; r++)
            {
                for (var c = 0; c < 2; c++)
                {
                    vertex->Color               = drawInfo->Color;
                    vertex->Swizzle             = (int)drawInfo->Swizzle;
                    vertex->TextureCoordinate.X = textureCoordX[c];
                    vertex->TextureCoordinate.Y = textureCoordY[r];

                    vertex->Position.X = currentPosition.X;
                    vertex->Position.Y = currentPosition.Y;
                    vertex->Position.Z = currentPosition.Z - currentPosition.W * drawInfo->DepthBias * DepthBiasShiftOneUnit;
                    vertex->Position.W = currentPosition.W;

                    if (drawInfo->SnapImage)
                    {
                        var backBufferHalfWidth  = GraphicsContext.CommandList.RenderTarget.ViewWidth / 2;
                        var backBufferHalfHeight = GraphicsContext.CommandList.RenderTarget.ViewHeight / 2;
                        vertex->Position.X = (float)(Math.Round(vertex->Position.X * backBufferHalfWidth) / backBufferHalfWidth);
                        vertex->Position.Y = (float)(Math.Round(vertex->Position.Y * backBufferHalfHeight) / backBufferHalfHeight);
                    }

                    vertex++;

                    if (c == 0)
                    {
                        Vector4.Add(ref currentPosition, ref drawInfo->UnitXWorld, out currentPosition);
                    }
                    else
                    {
                        Vector4.Subtract(ref currentPosition, ref drawInfo->UnitXWorld, out currentPosition);
                    }
                }

                Vector4.Add(ref currentPosition, ref drawInfo->UnitYWorld, out currentPosition);
            }
        }
Example #2
0
        private unsafe void CalculateBorderRectangleVertices(UIImageDrawInfo *drawInfo, VertexPositionColorTextureSwizzle *vertex)
        {
            // set the texture uv vectors
            var uvX = new Vector4();

            uvX[0] = drawInfo->Source.Left;
            uvX[3] = drawInfo->Source.Right;
            uvX[1] = uvX[0] + drawInfo->Source.Width * drawInfo->BorderSize.X;
            uvX[2] = uvX[3] - drawInfo->Source.Width * drawInfo->BorderSize.Z;
            var uvY = new Vector4();

            uvY[0] = drawInfo->Source.Top;
            uvY[3] = drawInfo->Source.Bottom;
            uvY[1] = uvY[0] + drawInfo->Source.Height * drawInfo->BorderSize.Y;
            uvY[2] = uvY[3] - drawInfo->Source.Height * drawInfo->BorderSize.W;

            // set the shift vectors
            shiftVectorX[0] = Vector4.Zero;
            Vector4.Multiply(ref drawInfo->UnitXWorld, drawInfo->VertexShift.X, out shiftVectorX[1]);
            Vector4.Multiply(ref drawInfo->UnitXWorld, drawInfo->VertexShift.Z, out shiftVectorX[2]);
            shiftVectorX[3] = drawInfo->UnitXWorld;

            shiftVectorY[0] = Vector4.Zero;
            Vector4.Multiply(ref drawInfo->UnitYWorld, drawInfo->VertexShift.Y, out shiftVectorY[1]);
            Vector4.Multiply(ref drawInfo->UnitYWorld, drawInfo->VertexShift.W, out shiftVectorY[2]);
            shiftVectorY[3] = drawInfo->UnitYWorld;

            // convert colors here instead of in the loop
            Color4 colorScale = drawInfo->ColorScale.ToColor4();
            Color4 colorAdd   = drawInfo->ColorAdd.ToColor4();

            for (var r = 0; r < 4; r++)
            {
                Vector4 currentRowPosition;
                Vector4.Add(ref drawInfo->LeftTopCornerWorld, ref shiftVectorY[r], out currentRowPosition);

                float uvYr = uvY[r]; // grab it out here

                for (var c = 0; c < 4; c++)
                {
                    Vector4 currentPosition;
                    Vector4.Add(ref currentRowPosition, ref shiftVectorX[c], out currentPosition);

                    vertex->Position.X = currentPosition.X;
                    vertex->Position.Y = currentPosition.Y;
                    vertex->Position.Z = currentPosition.Z - currentPosition.W * drawInfo->DepthBias * DepthBiasShiftOneUnit;
                    vertex->Position.W = currentPosition.W;

                    vertex->ColorScale = colorScale;
                    vertex->ColorAdd   = colorAdd;

                    vertex->TextureCoordinate.X = c == 0 ? uvX.X : uvX.Y;
                    vertex->TextureCoordinate.Y = uvYr;

                    vertex->Swizzle = (int)drawInfo->Swizzle;

                    vertex++;
                }
            }
        }
Example #3
0
        private static unsafe void CalculateCubeVertices(UIImageDrawInfo *drawInfo, VertexPositionColorTextureSwizzle *vertex)
        {
            var currentPosition = drawInfo->LeftTopCornerWorld;

            // convert colors here instead of in the loop
            Color4 colorScale = drawInfo->ColorScale.ToColor4();
            Color4 colorAdd   = drawInfo->ColorAdd.ToColor4();

            // set the two first line of vertices
            for (var l = 0; l < 2; ++l)
            {
                for (var r = 0; r < 2; r++)
                {
                    for (var c = 0; c < 2; c++)
                    {
                        vertex->ColorScale = colorScale;
                        vertex->ColorAdd   = colorAdd;

                        vertex->Swizzle             = (int)drawInfo->Swizzle;
                        vertex->TextureCoordinate.X = 0; // cubes are used only for color
                        vertex->TextureCoordinate.Y = 0; // cubes are used only for color

                        vertex->Position.X = currentPosition.X;
                        vertex->Position.Y = currentPosition.Y;
                        vertex->Position.Z = currentPosition.Z - currentPosition.W * drawInfo->DepthBias * DepthBiasShiftOneUnit;
                        vertex->Position.W = currentPosition.W;

                        vertex++;

                        if (c == 0)
                        {
                            Vector4.Add(ref currentPosition, ref drawInfo->UnitXWorld, out currentPosition);
                        }
                        else
                        {
                            Vector4.Subtract(ref currentPosition, ref drawInfo->UnitXWorld, out currentPosition);
                        }
                    }

                    if (r == 0)
                    {
                        Vector4.Add(ref currentPosition, ref drawInfo->UnitYWorld, out currentPosition);
                    }
                    else
                    {
                        Vector4.Subtract(ref currentPosition, ref drawInfo->UnitYWorld, out currentPosition);
                    }
                }

                Vector4.Add(ref currentPosition, ref drawInfo->UnitZWorld, out currentPosition);
            }
        }
Example #4
0
        private unsafe void CalculateRectangleVertices(UIImageDrawInfo *drawInfo, VertexPositionColorTextureSwizzle *vertex)
        {
            var currentPosition = drawInfo->LeftTopCornerWorld;

            // snap first pixel to prevent possible problems when left/top is in the middle of a pixel
            if (drawInfo->SnapImage)
            {
                var invW = 1.0f / currentPosition.W;
                var backBufferHalfWidth  = GraphicsContext.CommandList.RenderTarget.ViewWidth / 2;
                var backBufferHalfHeight = GraphicsContext.CommandList.RenderTarget.ViewHeight / 2;

                currentPosition.X *= invW;
                currentPosition.Y *= invW;
                currentPosition.X  = (float)(Math.Round(currentPosition.X * backBufferHalfWidth) / backBufferHalfWidth);
                currentPosition.Y  = (float)(Math.Round(currentPosition.Y * backBufferHalfHeight) / backBufferHalfHeight);
                currentPosition.X *= currentPosition.W;
                currentPosition.Y *= currentPosition.W;
            }

            float tcx0 = drawInfo->Source.Left;
            float tcx1 = drawInfo->Source.Right;
            float tcy0 = drawInfo->Source.Top;
            float tcy1 = drawInfo->Source.Bottom;

            // convert colors here instead of in the loop
            Color4 colorScale = drawInfo->ColorScale;
            float  depthShift = drawInfo->DepthBias * DepthBiasShiftOneUnit;

            // set the two first line of vertices
            for (var r = 0; r < 2; r++)
            {
                // unroll this loop
                // c = 0
                vertex->ColorScale          = colorScale;
                vertex->Swizzle             = (int)drawInfo->Swizzle;
                vertex->TextureCoordinate.X = tcx0;
                vertex->TextureCoordinate.Y = r == 0 ? tcy0 : tcy1;

                vertex->Position.X = currentPosition.X;
                vertex->Position.Y = currentPosition.Y;
                vertex->Position.Z = currentPosition.Z - currentPosition.W * depthShift;
                vertex->Position.W = currentPosition.W;

                if (drawInfo->SnapImage)
                {
                    var backBufferHalfWidth  = GraphicsContext.CommandList.RenderTarget.ViewWidth / 2;
                    var backBufferHalfHeight = GraphicsContext.CommandList.RenderTarget.ViewHeight / 2;
                    vertex->Position.X = (float)(Math.Round(vertex->Position.X * backBufferHalfWidth) / backBufferHalfWidth);
                    vertex->Position.Y = (float)(Math.Round(vertex->Position.Y * backBufferHalfHeight) / backBufferHalfHeight);
                }

                vertex++;

                Vector4.Add(ref currentPosition, ref drawInfo->UnitXWorld, out currentPosition);

                // c = 1
                vertex->ColorScale          = colorScale;
                vertex->Swizzle             = (int)drawInfo->Swizzle;
                vertex->TextureCoordinate.X = tcx1;
                vertex->TextureCoordinate.Y = r == 0 ? tcy0 : tcy1;

                vertex->Position.X = currentPosition.X;
                vertex->Position.Y = currentPosition.Y;
                vertex->Position.Z = currentPosition.Z - currentPosition.W * depthShift;
                vertex->Position.W = currentPosition.W;

                if (drawInfo->SnapImage)
                {
                    var backBufferHalfWidth  = GraphicsContext.CommandList.RenderTarget.ViewWidth / 2;
                    var backBufferHalfHeight = GraphicsContext.CommandList.RenderTarget.ViewHeight / 2;
                    vertex->Position.X = (float)(Math.Round(vertex->Position.X * backBufferHalfWidth) / backBufferHalfWidth);
                    vertex->Position.Y = (float)(Math.Round(vertex->Position.Y * backBufferHalfHeight) / backBufferHalfHeight);
                }

                vertex++;

                Vector4.Subtract(ref currentPosition, ref drawInfo->UnitXWorld, out currentPosition);

                Vector4.Add(ref currentPosition, ref drawInfo->UnitYWorld, out currentPosition);
            }
        }