Пример #1
0
            public virtual void AfterStroke(PaintCommand.UV command)
            {
                PaintCommand.ForPainterComponent painterCommand = command as PaintCommand.ForPainterComponent;
                Brush       br = command.Brush;
                Stroke      st = command.Stroke;
                TextureMeta id = command.TextureData;

                command.OnStrokeComplete();

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

                if (command.usedAlphaBuffer)
                {
                    var sh = br.GetBlitMode(false).ShaderForAlphaBufferBlit;
                    if (painterCommand == null || painterCommand.painter.NotUsingPreview)
                    {
                        TexMGMT.UpdateFromAlphaBuffer(id.CurrentRenderTexture(), sh);
                    }
                    else
                    {
                        TexMGMT.AlphaBufferSetDirtyBeforeRender(id, sh);
                    }
                }
                else if (!br.IsSingleBufferBrush() && !command.Is3DBrush)
                {
                    TexMGMT.UpdateBufferSegment();
                }

                if (painterCommand != null)
                {
                    foreach (var p in painterCommand.painter.Modules)
                    {
                        p.AfterGpuStroke(painterCommand);
                    }
                }
            }
Пример #2
0
            public override void PaintRenderTextureUvSpace(PaintCommand.UV command)  //PlaytimePainter painter, Brush br, Stroke st)
            {
                Brush  br = command.Brush;
                Stroke st = command.Stroke;

                BeforeStroke(command);

                var id = command.TextureData;

                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;
                    }

                    command.strokeAlphaPortion = 1;

                    TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(command); // br, 1, id, st, out alphaBuffer, command.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 = Stroke.BrushWorldPositionFrom(uv);

                    TexMGMT.Render();

                    AfterStroke(command);
                }
                else
                {
                    command.OnStrokeComplete(); //painter.AfterStroke(st);
                }
            }
Пример #3
0
            public virtual void PaintPixelsInRam(PaintCommand.UV command)
            {
                Brush  br = command.Brush;
                Stroke st = command.Stroke;

                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.Flow * (Application.isPlaying ? Time.deltaTime : 0.1f));

                var id = command.TextureData;

                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, IsAWorldSpaceBrush ? worldDist : uvDist);

                    deltaUv  /= steps;
                    deltaPos /= steps;

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

                Action <PaintCommand.UV> blitMethod = null;

                command.strokeAlphaPortion = alpha;

                var painter = command.TryGetPainter();

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

                if (blitMethod == null)
                {
                    blitMethod = BlitFunctions.Paint;
                    blitMethod(command);
                }

                for (float i = 1; i < steps; i++)
                {
                    st.uvFrom  += deltaUv;
                    st.posFrom += deltaPos;
                    blitMethod(command);
                }

                command.OnStrokeComplete();//.AfterStroke(st);
            }