Example #1
0
            public static void Paint(Vector2 uv, BrushConfig br, RenderTexture rt)
            {
                var stroke = new StrokeVector(uv)
                {
                    firstStroke = false
                };

                var id = rt.GetTextureMeta();

                bool alphaBuffer;

                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, id, stroke, out alphaBuffer);

                float width = br.StrokeWidth(id.width, false);

                RtBrush.localScale = Vector3.one;

                BrushMesh             = PainterCamera.BrushMeshGenerator.GetLongMesh(0, width);
                RtBrush.localRotation = Quaternion.Euler(new Vector3(0, 0, Vector2.Angle(Vector2.up, Vector2.zero)));

                RtBrush.localPosition = StrokeVector.BrushWorldPositionFrom(stroke.uvTo);

                TexMGMT.Render();

                AfterStroke_NoPainter(br, alphaBuffer, rt);
            }
Example #2
0
            public virtual void PaintRenderTexture(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                BeforeStroke(painter, br, st);

                if (st.CrossedASeam())
                {
                    st.uvFrom = st.uvTo;
                }

                var id = painter.TexMeta;

                bool alphaBuffer;

                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, id, st, painter, out alphaBuffer);

                var rb = RtBrush;

                rb.localScale = Vector3.one;
                var direction = st.DeltaUv;
                var length    = direction.magnitude;

                BrushMesh        = PainterCamera.BrushMeshGenerator.GetLongMesh(length * 256, br.StrokeWidth(id.width, false));
                rb.localRotation = Quaternion.Euler(new Vector3(0, 0,
                                                                (direction.x > 0 ? -1 : 1) * Vector2.Angle(Vector2.up, direction)));

                rb.localPosition = StrokeVector.BrushWorldPositionFrom((st.uvFrom + st.uvTo) * 0.5f);

                TexMGMT.Render();

                AfterStroke_Painter(painter, br, st, alphaBuffer, id);
            }
 public override void AfterGpuStroke(PlaytimePainter painter, BrushConfig br, StrokeVector st, BrushTypes.Base type)
 {
     if (br.IsA3DBrush(painter) && painter.IsAtlased())
     {
         PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(0, 0, 1, 0);
     }
 }
Example #4
0
        public void PaintRenderTexture(StrokeVector stroke, ImageMeta image, BrushConfig bc, PlaytimePainter painter)
        {
            var vt = painter.GetVolumeTexture();

            if (!vt)
            {
                Debug.LogError("Painted volume was not found");
                return;
            }

            if (_enableRayTracing)
            {
                rayTraceCameraConfiguration.From(stroke);

                bc.useAlphaBuffer = false;

                delayedPaintingConfiguration = new BrushStrokePainterImage(stroke, image, bc, painter);


                //Debug.Log("Setting position: "+stroke.posTo);

                PainterCamera.GetProjectorCamera().RenderRightNow(this);
            }
            else
            {
                PaintRenderTexture(new BrushStrokePainterImage(stroke, image, bc, painter));
            }
        }
Example #5
0
        public PlaytimePainter Paint(StrokeVector stroke, PlaytimePainter painter)
        {
            var imgData = painter.ImgMeta;

            if (imgData == null)
            {
                painter.InitIfNotInitialized();
                imgData = painter.ImgMeta;
                if (imgData == null)
                {
                    return(painter);
                }
            }

            var cpu       = imgData.TargetIsTexture2D();
            var brushType = GetBrushType(cpu);
            var blitMode  = GetBlitMode(cpu);

            blitMode.PrePaint(painter, this, stroke);

            if (cpu)
            {
                painter.RecordingMgmt();
                brushType.PaintToTexture2D(painter, this, stroke);
            }
            else
            {
                var materialData = painter.MatDta;

                if (!imgData.renderTexture && !TexMGMT.materialsUsingRenderTexture.Contains(materialData))
                {
                    TexMGMT.ChangeBufferTarget(imgData, materialData, painter.GetMaterialTextureProperty, painter);
                    painter.SetTextureOnMaterial(imgData);
                }

                var rendered = false;

                foreach (var pl in PainterSystemManagerModuleBase.BrushPlugins)
                {
                    if (pl.IsEnabledFor(painter, imgData, this))
                    {
                        pl.PaintRenderTexture(stroke, imgData, this, painter);
                        rendered = true;
                        break;
                    }
                }

                if (!painter.terrain || brushType.SupportedForTerrainRt)
                {
                    painter.RecordingMgmt();

                    if (!rendered)
                    {
                        brushType.PaintRenderTexture(painter, this, stroke);
                    }
                }
            }

            return(painter);
        }
Example #6
0
            public override void PrePaint(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                var v4 = new Vector4(st.unRepeatedUv.x, st.unRepeatedUv.y, Mathf.Floor(st.unRepeatedUv.x),
                                     Mathf.Floor(st.unRepeatedUv.y));

                _pointedUvUnTiledProperty.GlobalValue = v4;

                if (!st.firstStroke)
                {
                    return;
                }

                if (method == (ColorSetMethod.MDownColor))
                {
                    if (painter)
                    {
                        painter.SampleTexture(st.uvTo);
                        FromColor(br, st.unRepeatedUv);
                    }
                }
                else if (method == (ColorSetMethod.MDownPosition))
                {
                    FromUv(st.uvTo);
                }

                PainterDataAndConfig.BRUSH_SAMPLING_DISPLACEMENT.GlobalValue = new Vector4(
                    (currentPixel.x + 0.5f) / Cfg.samplingMaskSize.x,

                    (currentPixel.y + 0.5f) / Cfg.samplingMaskSize.y,

                    Cfg.samplingMaskSize.x, Cfg.samplingMaskSize.y);
            }
Example #7
0
 public BrushStrokePainterImage(StrokeVector s, TextureMeta id, BrushConfig br, PlaytimePainter pp)
 {
     stroke  = s;
     image   = id;
     brush   = br;
     painter = pp;
 }
Example #8
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 #9
0
        public void From(StrokeVector vec, bool lookInNormalDirection = true)
        {
            position       = vec.posTo;
            localTransform = false;

            if (lookInNormalDirection)
            {
                position += vec.collisionNormal;
                rotation  = Quaternion.LookRotation(vec.collisionNormal, Vector3.up);
            }
        }
Example #10
0
            public static void Paint(RenderTexture rt, GameObject go, SkinnedMeshRenderer skinner, BrushConfig br,
                                     StrokeVector st, int subMeshIndex)
            {
                br.GetBlitMode(false).PrePaint(null, br, st);

                bool alphaBuffer;

                PrepareSphereBrush(rt.GetTextureMeta(), br, st, out alphaBuffer);
                TexMGMT.brushRenderer.UseSkinMeshAsBrush(go, skinner, subMeshIndex);
                TexMGMT.Render();
                AfterStroke_NoPainter(br, alphaBuffer, rt);
            }
Example #11
0
            public void BeforeStroke(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                var cam = TexMGMT;

                if (!RenderTextureBuffersManager.secondBufferUpdated)
                {
                    RenderTextureBuffersManager.UpdateBufferTwo();
                }

                foreach (var p in painter.Modules)
                {
                    p.BeforeGpuStroke(painter, br, st, this);
                }
            }
Example #12
0
        public static void SHADER_POSITION_AND_PREVIEW_UPDATE(StrokeVector st, bool hidePreview, float size)
        {
            PainterDataAndConfig.BRUSH_POINTED_UV.GlobalValue = st.uvTo.ToVector4(0, _previewAlpha);

            if (hidePreview && Math.Abs(_previewAlpha) < float.Epsilon)
            {
                return;
            }

            QcMath.IsLerpingBySpeed(ref _previewAlpha, hidePreview ? 0 : 1, 4f);

            PainterDataAndConfig.BRUSH_WORLD_POS_FROM.GlobalValue = _prevPosPreview.ToVector4(size);
            PainterDataAndConfig.BRUSH_WORLD_POS_TO.GlobalValue   = st.posTo.ToVector4((st.posTo - _prevPosPreview).magnitude); //new Vector4(st.posTo.x, st.posTo.y, st.posTo.z, (st.posTo - prevPosPreview).magnitude));
            _prevPosPreview = st.posTo;
        }
Example #13
0
            private static void PrepareSphereBrush(TextureMeta id, BrushConfig br, StrokeVector stroke, out bool alphaBuffer,
                                                   PlaytimePainter painter = null)
            {
                // if (stroke.mouseDwn)
                //    stroke.posFrom = stroke.posTo;

                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, id, stroke, out alphaBuffer, painter);

                var offset = id.offset - stroke.unRepeatedUv.Floor();

                stroke.SetWorldPosInShader();

                PainterShaderVariables.BRUSH_EDITED_UV_OFFSET.GlobalValue =
                    new Vector4(id.tiling.x, id.tiling.y, offset.x, offset.y);
                PainterShaderVariables.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(0, 0, 1, 0);
            }
Example #14
0
        public StrokeVector(StrokeVector other)
        {
            uvFrom  = other.uvFrom;
            posFrom = other.posFrom;
            uvTo    = other.uvTo;

            posTo        = other.posTo;
            unRepeatedUv = other.unRepeatedUv;

            previousDelta = other.previousDelta;
            avgBrushSpeed = other.avgBrushSpeed;

            MouseDownEvent = other.MouseDownEvent;
            firstStroke    = other.firstStroke; // For cases like Lazy Brush, when painting doesn't start on the first frame.
            MouseUpEvent   = other.MouseDownEvent;

            Down_Internal();
        }
Example #15
0
        public StrokeVector(StrokeVector other)
        {
            uvFrom  = other.uvFrom;
            posFrom = other.posFrom;
            uvTo    = other.uvTo;

            posTo        = other.posTo;
            unRepeatedUv = other.unRepeatedUv;

            previousDelta = other.previousDelta;
            avgBrushSpeed = other.avgBrushSpeed;

            mouseDwn    = other.mouseDwn;
            firstStroke = other.firstStroke;  // For cases like Lazy Brush, when painting doesn't start on the first frame.
            mouseUp     = other.mouseDwn;

            Dwn();
        }
Example #16
0
 public void PaintRenderTexture(StrokeVector stroke, ImageMeta image, BrushConfig bc, PlaytimePainter painter)
 {
 }
Example #17
0
            public override void PaintRenderTexture(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                BeforeStroke(br, st, painter);

                if (st.CrossedASeam())
                {
                    st.uvFrom = st.uvTo;
                }

                TextureMeta id = painter.TexMeta;

                bool alphaBuffer;

                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, id, st, out alphaBuffer, painter);

                RtBrush.localScale = Vector3.one * br.StrokeWidth(id.width, false);

                BrushMesh             = PainterCamera.BrushMeshGenerator.GetQuad();
                RtBrush.localRotation = Quaternion.identity;

                RtBrush.localPosition = st.BrushWorldPosition;

                TexMGMT.Render();

                AfterStroke_Painter(painter, br, st, alphaBuffer, id);
            }
        public override void BeforeGpuStroke(PlaytimePainter painter, BrushConfig br, StrokeVector st, BrushTypes.Base type)
        {
            if (!br.IsA3DBrush(painter) || !painter.IsAtlased())
            {
                return;
            }

            var ats = GetAtlasedSection();

            PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(ats.x, ats.y, atlasRows, 1);
        }
Example #19
0
 public virtual void PrePaint(PlaytimePainter painter, BrushConfig br, StrokeVector st)
 {
 }
Example #20
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]);
                    }
                }
            }
        }
        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);
        }
Example #22
0
            public override void PaintRenderTexture(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                var id = painter.TexMeta;

                BeforeStroke(br, st, painter);

                bool alphaBuffer;

                PrepareSphereBrush(id, br, st, out alphaBuffer, painter);

                if (!st.MouseDownEvent)
                {
                    TexMGMT.brushRenderer.UseMeshAsBrush(painter);
                    TexMGMT.Render();
                }

                AfterStroke_Painter(painter, br, st, alphaBuffer, id);
            }
Example #23
0
            public static void PaintAtlased(RenderTexture rt, GameObject go, Mesh mesh, BrushConfig br, StrokeVector st,
                                            List <int> subMeshIndex, int aTexturesInRow)
            {
                br.GetBlitMode(false).PrePaint(null, br, st);

                PainterShaderVariables.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(0, 0, aTexturesInRow, 1);

                bool alphaBuffer;

                PrepareSphereBrush(rt.GetTextureMeta(), br, st, out alphaBuffer);
                TexMGMT.brushRenderer.UseMeshAsBrush(go, mesh, subMeshIndex);
                TexMGMT.Render();

                AfterStroke_NoPainter(br, alphaBuffer, rt);

                PainterShaderVariables.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(0, 0, 1, 0);
            }
Example #24
0
            public override void PaintRenderTexture(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                BeforeStroke(br, st, painter);

                var deltaUv   = st.DeltaUv; //uv - st.uvFrom;//.Previous_uv;
                var magnitude = deltaUv.magnitude;

                var id = painter.TexMeta;

                var width = br.Size(false) / id.width * 4;

                var trackPortion = (deltaUv.magnitude - width * 0.5f) * 0.25f;

                if (!(trackPortion > 0) && !st.MouseUpEvent)
                {
                    return;
                }

                if (st.firstStroke)
                {
                    previousDirectionLazy = st.previousDelta = deltaUv;
                    _lazySpeedDynamic     = deltaUv.magnitude;
                    _lazyAngleSmoothed    = 0;
                    // Debug.Log("First stroke");
                }

                var angle = Mathf.Deg2Rad * Vector2.Angle(st.previousDelta, deltaUv);

                var smooth = angle < Mathf.PI * 0.5f;

                if (st.CrossedASeam() && (magnitude > previousDirectionLazy.magnitude * 8))
                {
                    // Debug.Log("Crossed a seam");
                    st.MouseUpEvent = true;
                    st.uvTo         = st.uvFrom; // painter.Previous_uv;
                    deltaUv         = Vector2.zero;
                    smooth          = false;
                }

                previousDirectionLazy = deltaUv;

                if (!st.MouseUpEvent)
                {
                    if (smooth)
                    {
                        var   clockwise = Vector3.Cross(st.previousDelta, deltaUv).z > 0 ? 1f : -1f;
                        var   sin       = Mathf.Sin(angle) * clockwise;
                        float maxSinus  = 8;
                        _lazyAngleSmoothed = Mathf.Abs(_lazyAngleSmoothed) > Mathf.Abs(sin)
                            ? sin
                            : Mathf.Lerp(_lazyAngleSmoothed, sin, 0.2f);

                        sin = _lazyAngleSmoothed;

                        if ((sin * sin > maxSinus * maxSinus) || ((sin > 0) != (maxSinus > 0)))
                        {
                            var absSin  = Mathf.Abs(sin);
                            var absNSin = Mathf.Abs(maxSinus);

                            if (absSin < absNSin)
                            {
                                maxSinus = maxSinus * absSin / absNSin;
                            }

                            st.uvTo = st.uvFrom + st.previousDelta.normalized.Rotate_Radians(maxSinus * clockwise) *
                                      trackPortion;
                            _lazySpeedDynamic = trackPortion;
                        }
                        else
                        {
                            _lazySpeedDynamic = Mathf.Min(deltaUv.magnitude * 0.5f,
                                                          Mathf.Lerp(_lazySpeedDynamic, deltaUv.magnitude * 0.5f, 0.001f));

                            _lazySpeedDynamic = Mathf.Max(trackPortion, _lazySpeedDynamic);
                            st.uvTo           = st.uvFrom + st.previousDelta.normalized.Rotate_Radians(sin) * _lazySpeedDynamic;
                        }
                    }
                    else
                    {
                        _lazySpeedDynamic  = deltaUv.magnitude;
                        _lazyAngleSmoothed = 0;
                        st.uvTo            = st.uvFrom + deltaUv.normalized * trackPortion;
                    }
                }

                var r = TexMGMT;

                var meshWidth = br.StrokeWidth(id.width, false);

                var tf = RtBrush;

                var direction = st.DeltaUv;

                var isTail = st.firstStroke;

                bool alphaBuffer;

                if (!isTail && !smooth)
                {
                    var st2 = new StrokeVector(st)
                    {
                        firstStroke = false
                    };
                    r.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, id, st2, out alphaBuffer, painter);

                    Vector3 junkPoint = st.uvFrom + st.previousDelta * 0.01f;
                    BrushMesh = PainterCamera.BrushMeshGenerator.GetStreak(UvToPosition(st.uvFrom),
                                                                           UvToPosition(junkPoint), meshWidth, true, false);
                    tf.localScale    = Vector3.one;
                    tf.localRotation = Quaternion.identity;
                    tf.localPosition = new Vector3(0, 0, 10);


                    r.Render();
                    st.uvFrom = junkPoint;
                    isTail    = true;
                }

                r.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, id, st, out alphaBuffer, painter);

                BrushMesh = PainterCamera.BrushMeshGenerator.GetStreak(UvToPosition(st.uvFrom), UvToPosition(st.uvTo),
                                                                       meshWidth, st.MouseUpEvent, isTail);
                tf.localScale    = Vector3.one;
                tf.localRotation = Quaternion.identity;
                tf.localPosition = new Vector3(0, 0, 10);

                st.previousDelta = direction;

                r.Render();

                AfterStroke_Painter(painter, br, st, alphaBuffer, id);
            }
Example #25
0
            public virtual void PaintToTexture2D(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                var deltaUv = st.uvTo - st.uvFrom;

                if (deltaUv.magnitude > (0.2f + st.avgBrushSpeed * 3))
                {
                    deltaUv = Vector2.zero; // This is made to avoid glitch strokes on seams
                }
                else
                {
                    st.avgBrushSpeed = (st.avgBrushSpeed + deltaUv.magnitude) / 2;
                }

                var alpha = Mathf.Clamp01(br.Speed * (Application.isPlaying ? Time.deltaTime : 0.1f));

                var worldSpace = painter.NeedsGrid();

                var id = painter.TexMeta;

                var deltaPos = st.DeltaWorldPos;

                float steps = 1;

                if (id.disableContiniousLine)
                {
                    st.uvFrom  = st.uvTo;
                    st.posFrom = st.posTo;
                }
                else
                {
                    var uvDist    = (deltaUv.magnitude * id.width * 8 / br.Size(false));
                    var worldDist = st.DeltaWorldPos.magnitude;

                    steps = (int)Mathf.Max(1, worldSpace ? worldDist : uvDist);

                    deltaUv  /= steps;
                    deltaPos /= steps;

                    st.uvFrom  += deltaUv;
                    st.posFrom += deltaPos;
                }


                BlitFunctions.PaintTexture2DMethod blitMethod = null;

                foreach (var p in CameraModuleBase.BrushPlugins)
                {
                    if (p.IsEnabledFor(painter, id, br))
                    {
                        p.PaintPixelsInRam(st, alpha, id, br, painter);
                        blitMethod = p.PaintPixelsInRam;
                        break;
                    }
                }

                if (blitMethod == null)
                {
                    blitMethod = BlitFunctions.Paint;
                    blitMethod(st, alpha, id, br, painter);
                }

                for (float i = 1; i < steps; i++)
                {
                    st.uvFrom  += deltaUv;
                    st.posFrom += deltaPos;
                    blitMethod(st, alpha, id, br, painter);
                }

                painter.AfterStroke(st);
            }
Example #26
0
            public override void AfterStroke_Painter(PlaytimePainter painter, BrushConfig br, StrokeVector st,
                                                     bool alphaBuffer, TextureMeta id)
            {
                base.AfterStroke_Painter(painter, br, st, alphaBuffer, id);

                if (br.rotationMethod != RotationMethod.Random)
                {
                    return;
                }

                br.decalAngle = Random.Range(-90f, 450f);
                OnShaderBrushUpdate(Cfg.brushConfig);
            }
Example #27
0
            public override void PaintRenderTexture(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                BeforeStroke(br, st, painter);

                var id = painter.TexMeta;

                if (st.firstStroke || br.decalContentious)
                {
                    if (br.rotationMethod == RotationMethod.FaceStrokeDirection)
                    {
                        var delta = st.uvTo - _previousUv;

                        var portion = Mathf.Clamp01(delta.magnitude * id.width * 4 / br.Size(false));

                        var newAngle = Vector2.SignedAngle(Vector2.up, delta) + br.decalAngleModifier;
                        br.decalAngle = Mathf.LerpAngle(br.decalAngle, newAngle, portion);

                        _previousUv = st.uvTo;
                    }

                    bool alphaBuffer;

                    TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(br, 1, id, st, out alphaBuffer, painter);
                    var tf = RtBrush;
                    tf.localScale    = Vector3.one * br.Size(false);
                    tf.localRotation = Quaternion.Euler(new Vector3(0, 0, br.decalAngle));
                    BrushMesh        = PainterCamera.BrushMeshGenerator.GetQuad();

                    st.uvTo = st.uvTo.To01Space();

                    var deltaUv = st.DeltaUv;

                    var uv = st.uvTo;

                    if (br.rotationMethod == RotationMethod.FaceStrokeDirection && !st.firstStroke)
                    {
                        var length = Mathf.Max(deltaUv.magnitude * 2 * id.width / br.Size(false), 1);
                        var scale  = tf.localScale;

                        if ((Mathf.Abs(Mathf.Abs(br.decalAngleModifier) - 90)) < 40)
                        {
                            scale.x *= length;
                        }
                        else
                        {
                            scale.y *= length;
                        }

                        tf.localScale = scale;
                        uv           -= deltaUv * ((length - 1) * 0.5f / length);
                    }

                    tf.localPosition = StrokeVector.BrushWorldPositionFrom(uv);

                    TexMGMT.Render();

                    AfterStroke_Painter(painter, br, st, alphaBuffer, id);
                }
                else
                {
                    painter.AfterStroke(st);
                }
            }
Example #28
0
 public static void Paint(RenderTexture renderTexture, BrushConfig br, StrokeVector st,
                          PlaytimePainter painter = null) => _inst.PaintRenderTexture(renderTexture.GetTextureMeta(), br, st);
Example #29
0
 public virtual void PaintRenderTexture(PlaytimePainter painter, BrushConfig br, StrokeVector st) => PaintRenderTexture(painter.TexMeta, br, st, painter);
Example #30
0
            public virtual void AfterStroke_Painter(PlaytimePainter painter, BrushConfig br, StrokeVector st,
                                                    bool alphaBuffer, TextureMeta id)
            {
                painter.AfterStroke(st);

                if (br.useMask && st.MouseUpEvent && br.randomMaskOffset)
                {
                    br.maskOffset = new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f));
                }

                if (alphaBuffer)
                {
                    var sh = br.GetBlitMode(false).ShaderForAlphaBufferBlit;
                    if (painter.NotUsingPreview)
                    {
                        TexMGMT.UpdateFromAlphaBuffer(id.CurrentRenderTexture(), sh);
                    }
                    else
                    {
                        TexMGMT.AlphaBufferSetDirtyBeforeRender(id, sh);
                    }
                }
                else if (!br.IsSingleBufferBrush() && !br.IsA3DBrush(painter))
                {
                    TexMGMT.UpdateBufferSegment();
                }

                foreach (var p in painter.Modules)
                {
                    p.AfterGpuStroke(br, st, this);
                }
            }