public override void PaintRenderTexture(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { BeforeStroke(pntr, br, st); if (st.CrossedASeam()) { st.uvFrom = st.uvTo; } if (TexMGMT.BigRT_pair == null) { TexMGMT.UpdateBuffersState(); } ImageData id = pntr.ImgData; TexMGMT.ShaderPrepareStroke(br, br.speed * 0.05f, id, st, pntr); Rtbrush.localScale = Vector3.one * br.StrokeWidth(id.width, false); BrushMesh = brushMeshGenerator.inst().GetQuad(); Rtbrush.localRotation = Quaternion.identity; Rtbrush.localPosition = st.BrushWorldPosition; TexMGMT.Render(); AfterStroke(pntr, br, st); }
public static void Paint(Vector2 uv, BrushConfig br, RenderTexture rt) { if (TexMGMT.BigRT_pair == null) { TexMGMT.UpdateBuffersState(); } var id = rt.GetImgData(); var stroke = new StrokeVector(uv) { useTexcoord2 = false, firstStroke = false }; TexMGMT.ShaderPrepareStroke(br, br.speed * 0.05f, id, stroke, null); float width = br.StrokeWidth(id.width, false); Rtbrush.localScale = Vector3.one; BrushMesh = brushMeshGenerator.inst().GetLongMesh(0, width); Rtbrush.localRotation = Quaternion.Euler(new Vector3(0, 0, Vector2.Angle(Vector2.up, Vector2.zero))); Rtbrush.localPosition = StrokeVector.BrushWorldPositionFrom(uv); TexMGMT.Render(); AfterStroke(br); }
public virtual void PaintRenderTexture(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { BeforeStroke(pntr, br, st); if (st.CrossedASeam()) { st.uvFrom = st.uvTo; } ImageData id = pntr.ImgData; TexMGMT.ShaderPrepareStroke(br, br.speed * 0.05f, id, st, pntr); var rb = Rtbrush; rb.localScale = Vector3.one; Vector2 direction = st.Delta_uv; float length = direction.magnitude; BrushMesh = brushMeshGenerator.inst().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) / 2); TexMGMT.Render(); AfterStroke(pntr, br, st); }
public override void PaintRenderTexture(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { BeforeStroke(pntr, br, st); // Vector2 outb = new Vector2(Mathf.Floor(st.uvTo.x), Mathf.Floor(st.uvTo.y)); // st.uvTo -= outb; // st.uvFrom -= outb; Vector2 delta_uv = st.Delta_uv;//uv - st.uvFrom;//.Previous_uv; float magn = delta_uv.magnitude; var id = pntr.ImgData; float width = br.Size(false) / ((float)id.width) * 4; //const float followPortion = 0.5f; //float follow = width; float trackPortion = (delta_uv.magnitude - width * 0.5f) * 0.25f; if ((trackPortion > 0) || (st.mouseUp)) { if (st.firstStroke) { previousDirectionLazy = st.previousDelta = delta_uv; LazySpeedDynamic = delta_uv.magnitude; LazyAngleSmoothed = 0; // Debug.Log("First stroke"); } float angle = Mathf.Deg2Rad * Vector2.Angle(st.previousDelta, delta_uv); bool smooth = angle < Mathf.PI * 0.5f; if ((st.CrossedASeam()) && (magn > previousDirectionLazy.magnitude * 8)) { // Debug.Log("Crossed a seam"); st.mouseUp = true; st.uvTo = st.uvFrom;// painter.Previous_uv; delta_uv = Vector2.zero; smooth = false; } previousDirectionLazy = delta_uv; if (!st.mouseUp) { if (smooth) { float clockwise = Vector3.Cross(st.previousDelta, delta_uv).z > 0 ? 1 : -1; float sin = Mathf.Sin(angle) * clockwise; float maxSinus = 8; if (Mathf.Abs(LazyAngleSmoothed) > Mathf.Abs(sin)) { LazyAngleSmoothed = sin; } else { LazyAngleSmoothed = Mathf.Lerp(LazyAngleSmoothed, sin, 0.2f); } sin = LazyAngleSmoothed; if ((sin * sin > maxSinus * maxSinus) || ((sin > 0) != (maxSinus > 0))) { float absSin = Mathf.Abs(sin); float absNSin = Mathf.Abs(maxSinus); if (absSin < absNSin) { maxSinus = maxSinus * absSin / absNSin; } st.uvTo = st.uvFrom + st.previousDelta.normalized.Rotate(maxSinus * clockwise) * trackPortion; LazySpeedDynamic = trackPortion; } else { LazySpeedDynamic = Mathf.Min(delta_uv.magnitude * 0.5f, Mathf.Lerp(LazySpeedDynamic, delta_uv.magnitude * 0.5f, 0.001f)); LazySpeedDynamic = Mathf.Max(trackPortion, LazySpeedDynamic); st.uvTo = st.uvFrom + st.previousDelta.normalized.Rotate(sin) * LazySpeedDynamic; } } else { LazySpeedDynamic = delta_uv.magnitude; LazyAngleSmoothed = 0; st.uvTo = st.uvFrom + delta_uv.normalized * trackPortion; } } PainterCamera r = TexMGMT; //RenderTexturePainter.inst.RenderLazyBrush(painter.Previous_uv, uv, brush.speed * 0.05f, painter.curImgData, brush, painter.LmouseUP, smooth ); if (TexMGMT.BigRT_pair == null) { TexMGMT.UpdateBuffersState(); } float meshWidth = br.StrokeWidth(id.width, false); //.Size(false) / ((float)id.width) * 2 * rtp.orthoSize; Transform tf = Rtbrush; Vector2 direction = st.Delta_uv; //uvTo - uvFrom; bool isTail = st.firstStroke; //(!previousTo.Equals(uvFrom)); if ((!isTail) && (!smooth)) { var st2 = new StrokeVector(st) { firstStroke = false }; r.ShaderPrepareStroke(br, br.speed * 0.05f, id, st2, pntr); Vector3 junkPoint = st.uvFrom + st.previousDelta * 0.01f; BrushMesh = brushMeshGenerator.inst().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();//Render_UpdateSecondBufferIfUsing(id); st.uvFrom = junkPoint; isTail = true; } r.ShaderPrepareStroke(br, br.speed * 0.05f, id, st, pntr); BrushMesh = brushMeshGenerator.inst().GetStreak(UvToPosition(st.uvFrom), UvToPosition(st.uvTo), meshWidth, st.mouseUp, isTail); tf.localScale = Vector3.one; tf.localRotation = Quaternion.identity; tf.localPosition = new Vector3(0, 0, 10); st.previousDelta = direction; r.Render(); AfterStroke(pntr, br, st); } }