Пример #1
0
        public static void Paint(StrokeVector stroke, float brushAlpha, TextureMeta image, BrushConfig bc, PlaytimePainter painter)
        {
            if (image?.Pixels == null)
            {
                return;
            }

            var uvCoords = stroke.uvFrom;

            brAlpha = brushAlpha;

            bc.PrepareCpuBlit(image);

            var iHalf = (int)(half);

            Vector2 offset;

            var tmp = image.UvToPixelNumber(uvCoords, out offset);

            var smooth = bc.GetBrushType(true) != BrushTypes.Pixel.Inst;

            if (smooth)
            {
                iHalf += 1;
                offset = Vector2.zero;
            }

            var hf = half - 0.5f;

            var halfFromX = Mathf.RoundToInt(-hf + offset.x);
            var halfFromY = Mathf.RoundToInt(-hf + offset.y);
            var halfToX   = Mathf.RoundToInt(hf + offset.x);
            var halfToY   = Mathf.RoundToInt(hf + offset.y);

            var fromX = tmp.x + halfFromX;

            tmp.y += halfFromY;

            var pixels = image.Pixels;

            for (y = halfFromY; y <= halfToY; y++)
            {
                tmp.x = fromX;

                for (x = halfFromX; x <= halfToX; x++)
                {
                    if (alphaMode())
                    {
                        blitMode(ref pixels[image.PixelNo(tmp)]);
                    }

                    tmp.x += 1;
                }

                tmp.y += 1;
            }
        }
Пример #2
0
        public static void Paint(PaintCommand.UV command)
        {
            TextureMeta image = command.TextureData;

            if (image.Pixels == null)
            {
                return;
            }

            Brush bc = command.Brush;

            var uvCoords = command.Stroke.uvFrom;

            brAlpha = command.strokeAlphaPortion;

            bc.PrepareCpuBlit(image);

            var iHalf = (int)(half);

            Vector2 offset;

            var tmp = image.UvToPixelNumber(uvCoords, out offset);

            var smooth = bc.GetBrushType(true) != BrushTypes.Pixel.Inst;

            if (smooth)
            {
                iHalf += 1;
                offset = Vector2.zero;
            }

            var hf = half - 0.5f;

            var halfFromX = Mathf.RoundToInt(-hf + offset.x);
            var halfFromY = Mathf.RoundToInt(-hf + offset.y);
            var halfToX   = Mathf.RoundToInt(hf + offset.x);
            var halfToY   = Mathf.RoundToInt(hf + offset.y);

            var fromX = tmp.x + halfFromX;

            tmp.y += halfFromY;

            var pixels = image.Pixels;

            for (y = halfFromY; y <= halfToY; y++)
            {
                tmp.x = fromX;

                for (x = halfFromX; x <= halfToX; x++)
                {
                    if (alphaMode())
                    {
                        blitMode(ref pixels[image.PixelNo(tmp)]);
                    }

                    tmp.x += 1;
                }

                tmp.y += 1;
            }
        }
        public bool PaintTexture2D(StrokeVector stroke, float brushAlpha, TextureMeta image, BrushConfig bc, PlaytimePainter painter)
        {
            if (!painter.IsAtlased())
            {
                return(false);
            }

            var uvCoords = stroke.uvFrom;

            var atlasedSection = GetAtlasedSection();

            sectorSize = image.width / atlasRows;
            atlasSector.From(atlasedSection * sectorSize);

            BlitFunctions.brAlpha = brushAlpha;

            BlitFunctions.half = (bc.Size(false)) / 2;
            var iHalf = Mathf.FloorToInt(BlitFunctions.half - 0.5f);

            var smooth = bc.GetBrushType(true) != BrushTypes.Pixel.Inst;

            if (smooth)
            {
                BlitFunctions.alphaMode = BlitFunctions.CircleAlpha;
            }
            else
            {
                BlitFunctions.alphaMode = BlitFunctions.NoAlpha;
            }

            BlitFunctions.blitMode = bc.GetBlitMode(true).BlitFunctionTex2D(image);

            if (smooth)
            {
                iHalf += 1;
            }

            BlitFunctions.alpha = 1;


            BlitFunctions.Set(bc.mask);

            BlitFunctions.cSrc = bc.Color;

            var tmp = image.UvToPixelNumber(uvCoords);

            var fromX = tmp.x - iHalf;

            tmp.y -= iHalf;

            var pixels = image.Pixels;

            for (BlitFunctions.y = -iHalf; BlitFunctions.y < iHalf + 1; BlitFunctions.y++)
            {
                tmp.x = fromX;

                for (BlitFunctions.x = -iHalf; BlitFunctions.x < iHalf + 1; BlitFunctions.x++)
                {
                    if (BlitFunctions.alphaMode())
                    {
                        var sx = tmp.x - atlasSector.x;
                        var sy = tmp.y - atlasSector.y;

                        sx %= sectorSize;
                        if (sx < 0)
                        {
                            sx += sectorSize;
                        }
                        sy %= sectorSize;
                        if (sy < 0)
                        {
                            sy += sectorSize;
                        }

                        BlitFunctions.blitMode(ref pixels[((atlasSector.y + sy)) * image.width + (atlasSector.x + sx)]);
                    }

                    tmp.x += 1;
                }

                tmp.y += 1;
            }
            return(true);
        }