示例#1
0
            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 bool PaintRenderTexture(StrokeVector stroke, ImageData image, BrushConfig bc, PlaytimePainter pntr)
        {
            var vt = pntr.GetVolumeTexture();

            if (vt != null)
            {
                BrushTypeSphere.Inst.BeforeStroke(pntr, bc, stroke);

                Shader.SetGlobalVector(VOLUME_POSITION_N_SIZE + "_BRUSH", vt.PosNsize4Shader);
                Shader.SetGlobalVector(VOLUME_H_SLICES + "_BRUSH", vt.Slices4Shader);
                if (stroke.mouseDwn)
                {
                    stroke.posFrom = stroke.posTo;
                }

                stroke.useTexcoord2 = false;

                TexMGMT.ShaderPrepareStroke(bc, bc.speed * 0.05f, image, stroke, pntr);
                stroke.SetWorldPosInShader();

                TexMGMT.brushRendy.FullScreenQuad();

                TexMGMT.Render();

                BrushTypeSphere.Inst.AfterStroke(pntr, bc, stroke);

                return(true);
            }
            return(false);
        }
示例#3
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);
            }
示例#4
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);
            }
示例#5
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);
            }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
            public static void Paint(Vector2 uv, Brush br, RenderTexture rt)
            {
                var command = new PaintCommand.UV(new Stroke(uv)
                {
                    firstStroke = false
                }, rt.GetTextureMeta(), br)
                {
                    strokeAlphaPortion = Mathf.Clamp01(br.Flow * 0.05f)
                };

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

                float width = br.StrokeWidth(command.TextureData.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 = Stroke.BrushWorldPositionFrom(command.Stroke.uvTo);

                TexMGMT.Render();

                br.GetBrushType(false).AfterStroke(command);
            }
示例#10
0
            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);
            }
示例#11
0
 public static void Paint(RenderTexture rt, GameObject go, SkinnedMeshRenderer skinner, BrushConfig br, StrokeVector st, int submeshIndex)
 {
     br.BlitMode.PrePaint(null, br, st);
     PrepareSphereBrush(rt.GetImgData(), br, st, null);
     TexMGMT.brushRendy.UseSkinMeshAsBrush(go, skinner, submeshIndex);
     TexMGMT.Render();
     AfterStroke(br);
 }
示例#12
0
        public static void Paint(RenderTexture rt, GameObject go, Mesh mesh, BrushConfig br, StrokeVector st, List <int> subMeshIndex)
        {
            br.GetBlitMode(false).PrePaint(null, br, st);

            bool alphaBuffer;

            PrepareSphereBrush(rt.GetImgData(), br, st, null, out alphaBuffer);
            TexMGMT.brushRenderer.UseMeshAsBrush(go, mesh, subMeshIndex);
            TexMGMT.Render();
            AfterStroke_NoPainter(br, alphaBuffer, rt);
        }
示例#13
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);
            }
示例#14
0
        public static void PaintAtlased(RenderTexture rt, GameObject go, Mesh mesh, BrushConfig br, StrokeVector st, List <int> submeshIndex, int A_Textures_in_row)
        {
            br.BlitMode.PrePaint(null, br, st);

            Shader.SetGlobalVector(PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS, new Vector4(0, 0, A_Textures_in_row, 1));

            PrepareSphereBrush(rt.GetImgData(), br, st, null);
            TexMGMT.brushRendy.UseMeshAsBrush(go, mesh, submeshIndex);
            TexMGMT.Render();
            AfterStroke(br);

            Shader.SetGlobalVector(PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS, new Vector4(0, 0, 1, 0));
        }
示例#15
0
            public static void Paint(PaintCommand.WorldSpace command)
            {
                Brush  br = command.Brush;
                Stroke st = command.Stroke;


                br.GetBlitMode(false).PrePaint(command);

                PrepareSphereBrush(command);
                TexMGMT.brushRenderer.Prepare(command);
                TexMGMT.Render();
                br.GetBrushType(false).AfterStroke(command);
            }
示例#16
0
        public override void PaintRenderTexture(PlaytimePainter pntr, BrushConfig br, StrokeVector st)
        {
            ImageData id = pntr.ImgData;

            BeforeStroke(pntr, br, st);

            PrepareSphereBrush(id, br, st, pntr);

            if (!st.mouseDwn)
            {
                TexMGMT.brushRendy.UseMeshAsBrush(pntr);
                TexMGMT.Render();
            }

            AfterStroke(pntr, br, st);
        }
示例#17
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);

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

            bool alphaBuffer;

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

            AfterStroke_NoPainter(br, alphaBuffer, rt);

            PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(0, 0, 1, 0);
        }
示例#18
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);
            }
示例#19
0
            public override void PaintRenderTextureInWorldSpace(PaintCommand.WorldSpace command) //PlaytimePainter painter, Brush br, Stroke st)
            {
                var id = command.TextureData;                                                    //painter.TexMeta;

                BeforeStroke(command);                                                           //br, st, painter);

                //bool alphaBuffer;

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

                if (!command.Stroke.MouseDownEvent)
                {
                    TexMGMT.brushRenderer.Prepare(command);
                    TexMGMT.Render();
                }

                AfterStroke(command); //painter, br, st, alphaBuffer, id);
            }
示例#20
0
        public RenderBrush CopyBuffer(Texture tex, RenderTexture onto, Material material, Shader shade)
        {
            if (tex != null && onto != null)
            {
                float size        = PainterCamera.orthoSize * 2;
                float aspectRatio = (float)tex.width / (float)tex.height;

                float ar2 = (float)onto.width / (float)onto.height;


#if UNITY_2018_1_OR_NEWER
                if (tex.GetType() == typeof(RenderTexture))
                {
                    aspectRatio = ar2 / aspectRatio;
                }
                else
                {
                    aspectRatio = 1;
                }
#else
                aspectRatio = ar2 / aspectRatio;
#endif

                TexMGMT.rtcam.targetTexture = onto;

                transform.localScale    = new Vector3(size * aspectRatio, size, 0);
                transform.localPosition = Vector3.forward * 10;
                transform.localRotation = Quaternion.identity;
                meshFilter.mesh         = brushMeshGenerator.inst().GetQuad();

                Shader.SetGlobalFloat(PainterDataAndConfig.bufferCopyAspectRatio, 1f / aspectRatio);

                if (material)
                {
                    var tmpMat = meshRendy.material;
                    meshRendy.material = material;
                    if (tex)
                    {
                        Set(tex);
                    }
                    TexMGMT.Render();
                    meshRendy.material = tmpMat;
                }
                else
                {
                    if (shade == null)
                    {
                        shade = TexMGMTdata.pixPerfectCopy;
                    }
                    Set(shade);
                    Set(tex);
                    TexMGMT.Render();
                }


                if (aspectRatio != 1)
                {
                    Shader.SetGlobalFloat(PainterDataAndConfig.bufferCopyAspectRatio, 1);
                }
            }

            return(this);
        }
示例#21
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);
                }
            }
示例#22
0
        public override void PaintRenderTexture(PlaytimePainter pntr, BrushConfig br, StrokeVector st)
        {
            BeforeStroke(pntr, br, st);

            ImageData id = pntr.ImgData;

            if ((st.firstStroke) || (br.decalContinious))
            {
                if (br.decalRotationMethod == DecalRotationMethod.StrokeDirection)
                {
                    Vector2 delta = st.uvTo - previousUV;

                    // if ((st.firstStroke) || (delta.magnitude*id.width > br.Size(false)*0.25f)) {

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

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

                    previousUV = st.uvTo;
                    //}
                }

                if (TexMGMT.BigRT_pair == null)
                {
                    TexMGMT.UpdateBuffersState();
                }

                TexMGMT.ShaderPrepareStroke(br, 1, id, st, pntr);
                Transform tf = Rtbrush;
                tf.localScale    = Vector3.one * br.Size(false);
                tf.localRotation = Quaternion.Euler(new Vector3(0, 0, br.decalAngle));
                BrushMesh        = brushMeshGenerator.inst().GetQuad();

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

                Vector2 deltauv = st.Delta_uv;

                /*
                 *
                 * int strokes = Mathf.Max(1, (br.decalContinious && (!st.firstStroke)) ? (int)(deltauv.magnitude*id.width/br.Size(false)) : 1);
                 *
                 * deltauv /=  strokes;
                 *
                 * for (int i = 0; i < strokes; i++) {
                 *   st.uvFrom += deltauv;*/

                Vector2 uv = st.uvTo;

                if ((br.decalRotationMethod == DecalRotationMethod.StrokeDirection) && (!st.firstStroke))
                {
                    float   length = Mathf.Max(deltauv.magnitude * 2 * id.width / br.Size(false), 1);
                    Vector3 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(pntr, br, st);
            }
            else
            {
                pntr.AfterStroke(st);
            }
        }
        private RenderTexture CopyBuffer(Texture tex, RenderTexture onto, Material material, Shader shade)
        {
            if (!tex || !onto)
            {
                return(onto);
            }

            const float size = PainterCamera.OrthographicSize * 2;

            var aspectRatio = tex.width / (float)tex.height;

            var ar2 = onto.width / (float)onto.height;

            if (tex.GetType() == typeof(RenderTexture))
            {
                aspectRatio = ar2 / aspectRatio;
            }
            else
            {
                aspectRatio = 1;
            }

            TexMGMT.TargetTexture = onto;

            var tf = transform;

            tf.localScale    = new Vector3(size * aspectRatio, size, 0);
            tf.localPosition = Vector3.forward * 10;
            tf.localRotation = Quaternion.identity;
            meshFilter.mesh  = PainterCamera.BrushMeshGenerator.GetQuad();

            PainterShaderVariables.SourceTextureSize = tex;
            PainterShaderVariables.BufferCopyAspectRatio.GlobalValue = 1f / aspectRatio;

            if (material)
            {
                var tmpMat = meshRenderer.material;
                meshRenderer.material = material;
                if (tex)
                {
                    Set(tex);
                }
                TexMGMT.Render();
                meshRenderer.material = tmpMat;
            }
            else
            {
                if (!shade)
                {
                    shade = TexMgmtData.pixPerfectCopy;
                }

                Set(shade);
                Set(tex);
                TexMGMT.Render();
            }


            if (Math.Abs(aspectRatio - 1) > float.Epsilon)
            {
                PainterShaderVariables.BufferCopyAspectRatio.GlobalValue = 1;
            }

            return(onto);
        }