Example #1
0
        public static void Paint(StrokeVector stroke, float brushAlpha, ImageMeta 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) != BrushTypePixel.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;
            }
        }
Example #2
0
        public void PaintPixelsInRam(StrokeVector stroke, float brushAlpha, ImageMeta image, BrushConfig bc, PlaytimePainter painter)
        {
            var volume = image.texture2D.GetVolumeTextureData();

            if (!volume)
            {
                return;
            }

            if (volume.VolumeJobIsRunning)
            {
                return;
            }

            bc.brush3DRadius = Mathf.Min(BrushScaleMaxForCpu(volume), bc.brush3DRadius);

            var volumeScale = volume.size;

            var pos = (stroke.posFrom - volume.transform.position) / volumeScale + 0.5f * Vector3.one;

            var height   = volume.Height;
            var texWidth = image.width;

            BlitFunctions.brAlpha = brushAlpha;
            bc.PrepareCpuBlit(image);
            BlitFunctions.half = bc.Size(true) / volumeScale;

            var pixels = image.Pixels;

            var iHalf  = (int)(BlitFunctions.half - 0.5f);
            var smooth = bc.GetBrushType(true) != BrushTypePixel.Inst;

            if (smooth)
            {
                iHalf += 1;
            }

            BlitFunctions.alphaMode = BlitFunctions.SphereAlpha;

            var sliceWidth = texWidth / volume.hSlices;

            var hw = sliceWidth / 2;

            var y = (int)pos.y;
            var z = (int)(pos.z + hw);
            var x = (int)(pos.x + hw);

            for (BlitFunctions.y = -iHalf; BlitFunctions.y < iHalf + 1; BlitFunctions.y++)
            {
                var h = y + BlitFunctions.y;

                if (h >= height)
                {
                    return;
                }

                if (h < 0)
                {
                    continue;
                }
                var hy        = h / volume.hSlices;
                var hx        = h % volume.hSlices;
                var hTexIndex = (hy * texWidth + hx) * sliceWidth;

                for (BlitFunctions.z = -iHalf; BlitFunctions.z < iHalf + 1; BlitFunctions.z++)
                {
                    var trueZ = z + BlitFunctions.z;

                    if (trueZ < 0 || trueZ >= sliceWidth)
                    {
                        continue;
                    }
                    var yTexIndex = hTexIndex + trueZ * texWidth;

                    for (BlitFunctions.x = -iHalf; BlitFunctions.x < iHalf + 1; BlitFunctions.x++)
                    {
                        if (!BlitFunctions.alphaMode())
                        {
                            continue;
                        }
                        var trueX = x + BlitFunctions.x;

                        if (trueX < 0 || trueX >= sliceWidth)
                        {
                            continue;
                        }
                        var texIndex = yTexIndex + trueX;
                        BlitFunctions.blitMode(ref pixels[texIndex]);
                    }
                }
            }
        }