public override void PaintRenderTextureUvSpace(PaintCommand.UV command) { Brush br = command.Brush; Stroke st = command.Stroke; TextureMeta id = command.TextureData; BeforeStroke(command); if (st.CrossedASeam()) { st.uvFrom = st.uvTo; } command.strokeAlphaPortion = Mathf.Clamp01(br.Flow * 0.05f); TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(command);// 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(command);//painter, br, st, alphaBuffer, id); }
public virtual void PaintRenderTextureUvSpace(PaintCommand.UV command) { TextureMeta textureMeta = command.TextureData; Brush br = command.Brush; Stroke st = command.Stroke; BeforeStroke(command); if (st.CrossedASeam()) { st.uvFrom = st.uvTo; } command.strokeAlphaPortion = Mathf.Clamp01(br.Flow * 0.05f); TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(command); var rb = RtBrush; rb.localScale = Vector3.one; var direction = st.DeltaUv; var length = direction.magnitude; BrushMesh = PainterCamera.BrushMeshGenerator.GetLongMesh(length * 256, br.StrokeWidth(textureMeta.width, false)); rb.localRotation = Quaternion.Euler(new Vector3(0, 0, (direction.x > 0 ? -1 : 1) * Vector2.Angle(Vector2.up, direction))); rb.localPosition = Stroke.BrushWorldPositionFrom((st.uvFrom + st.uvTo) * 0.5f); TexMGMT.Render(); AfterStroke(command); }
public override void PaintRenderTextureUvSpace(PaintCommand.UV command)//PlaytimePainter painter, Brush br, Stroke st) { Brush br = command.Brush; Stroke st = command.Stroke; var id = command.TextureData; BeforeStroke(command); var deltaUv = st.DeltaUv; //uv - st.uvFrom;//.Previous_uv; var magnitude = deltaUv.magnitude; 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 Stroke(st) { firstStroke = false }; r.SHADER_STROKE_SEGMENT_UPDATE(command);//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; } command.strokeAlphaPortion = Mathf.Clamp01(br.Flow * 0.05f); r.SHADER_STROKE_SEGMENT_UPDATE(command);//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(command); //painter, br, st, alphaBuffer, id); }