示例#1
0
 public Texture2DBackup(Color[] texturePixels, ImageData from, int globalOrder)
 {
     Set(texturePixels, from, globalOrder);
 }
示例#2
0
 protected virtual void SetB(ImageData from, int globalOrder)
 {
     order        = globalOrder;
     strokeRecord = from.recordedStrokes_forUndoRedo;
     from.recordedStrokes_forUndoRedo = new List <string>();
 }
示例#3
0
 public void Set(Color[] texturePixels, ImageData from, int globalOrder)
 {
     SetB(from, globalOrder);
     pixels = texturePixels;
 }
示例#4
0
        public virtual bool PEGI()
        {
            PlaytimePainter p = PlaytimePainter.inspectedPainter;

            if (p == null)
            {
                "No Painter Detected".nl(); return(false);
            }



            if ((p.skinnedMeshRendy != null) && (pegi.Click("Update Collider from Skinned Mesh")))
            {
                p.UpdateColliderForSkinnedMesh();
            }
            pegi.newLine();


            ImageData id = p.ImgData;

            bool changed = false;
            bool cpuBlit = id.destination == TexTarget.Texture2D;

            pegi.newLine();

            changed |= p.PreviewShaderToggle_PEGI();

            if ((PainterCamera.GotBuffers() || (id.renderTexture != null)) && (id.texture2D != null))
            {
                if ((cpuBlit ? icon.CPU : icon.GPU).Click(
                        cpuBlit ? "Switch to Render Texture" : "Switch to Texture2D", 45))
                {
                    p.UpdateOrSetTexTarget(cpuBlit ? TexTarget.RenderTexture : TexTarget.Texture2D);
                    SetSupportedFor(cpuBlit, id.renderTexture == null);
                    changed = true;
                }
            }


            if (cpuBlit)
            {
                bool smooth = _type(cpuBlit) != BrushTypePixel.Inst.index;

                if (pegi.toggle(ref smooth, icon.Round, icon.Square, "Smooth/Pixels Brush", 45))
                {
                    changed = true;
                    TypeSet(cpuBlit, smooth ? (BrushType)BrushTypeNormal.Inst : (BrushType)BrushTypePixel.Inst);
                }
            }

            pegi.newLine();
#if UNITY_EDITOR
            if (Tools.current != Tool.None)
            {
                Msg.LockToolToUseTransform.Get().writeWarning();
                if (Msg.HideTransformTool.Get().Click().nl())
                {
                    PlaytimePainter.HideUnityTool();
                }
            }
#endif

            if                    //(
            (!p.IsOriginalShader) // && (cfg.moreOptions))
            {
                changed |= pegi.toggle(ref Cfg.previewAlphaChanel, "Preview Enabled Chanels", 130);
            }



            if (Mode_Type_PEGI())
            {
                if (Type(cpuBlit) == BrushTypeDecal.Inst)
                {
                    MaskSet(BrushMask.A, true);
                }

                changed = true;
            }

            if (p.terrain != null)
            {
                if ((p.ImgData != null) && ((p.IsTerrainHeightTexture())) && (p.IsOriginalShader))
                {
                    pegi.writeWarning(" You need to use Preview Shader to see changes");
                }

                pegi.newLine();

                if ((p.terrain != null) && (pegi.Click("Update Terrain").nl()))
                {
                    p.UpdateShaderGlobals();
                }
            }

            return(changed);
        }
示例#5
0
        public void ApplyTo(ImageData id)
        {
            bool fromRT = (tex2D.Count == 0) || ((rtex.Count > 0) && (tex2D [tex2D.Count - 1].order < rtex [rtex.Count - 1].order));

            bool toRT = id.destination == TexTarget.RenderTexture;

            int toClear = id.recordedStrokes_forUndoRedo.Count;

            if (toRT)
            {
                otherDirection.backupRenderTexture(int.MaxValue, id);
            }
            else
            {
                otherDirection.backupTexture2D(int.MaxValue, id);
            }


            RenderTextureBackup rtBackup  = fromRT ? takeRenderTexture() : null;
            Texture2DBackup     pixBackup = fromRT ? null : takeTexture2D();
            TextureBackup       backup    = fromRT ? (TextureBackup)rtBackup : (TextureBackup)pixBackup;



            if (!isUndo)
            {
                id.recordedStrokes.AddRange(backup.strokeRecord);
            }
            else
            {
                id.recordedStrokes.RemoveLast(toClear);
            }

            id.recordedStrokes_forUndoRedo = backup.strokeRecord;

            /*  if (isUndo) {
             *
             *
             * } else {
             *    id.recordedStrokes.AddRange(backup.strokeRecord);
             *    id.recordedStrokes_forUndoRedo.AddRange(backup.strokeRecord);
             * }*/


            if (!fromRT)
            {
                id.Pixels = (Color[])pixBackup.pixels;//.Clone();
                id.SetAndApply(true);
            }

            if (toRT)
            {
                if (fromRT)
                {
                    rtp.Render(rtBackup.rt, id);
                }
                else
                {
                    rtp.Render(id.texture2D, id);
                }
            }
            else if (fromRT)
            {
                id.texture2D.CopyFrom(rtBackup.rt);
                id.PixelsFromTexture2D(id.texture2D);

                bool converted = false;

                if ((PainterCamera.Inst.isLinearColorSpace) && (!rtBackup.exclusive))
                {
                    converted = true;
                    id.PixelsToGamma();
                }
                //else
                //   id.pixelsToLinear();
                // if (!RenderTexturePainter.inst.isLinearColorSpace)
                //{
                //  Debug.Log("Pixels to lnear");

                //   id.pixelsToLinear();
                //}

                // In Linear dont turn to gamma if saved from Exclusive Render Texture
                if (converted)
                {
                    id.SetAndApply(true);
                }
                else
                {
                    id.texture2D.Apply(true);
                }
            }

            if (fromRT)
            {
                rtBackup.DestroyRtex();
            }
        }
示例#6
0
        public bool PaintTexture2D(StrokeVector stroke, float brushAlpha, ImageData image, BrushConfig bc, PlaytimePainter pntr)
        {
            int slices;

            slices = image.texture2D.VolumeSlices();

            if (slices > 1)
            {
                var volume = image.texture2D.GetVolumeTextureData();

                if (volume == null)
                {
                    return(false);
                }

                float volumeScale = volume.size;

                Vector3 pos = (stroke.posFrom - volume.transform.position) / volumeScale + 0.5f * Vector3.one;

                int height   = volume.Height;
                int texWidth = image.width;

                Blit_Functions.brAlpha = brushAlpha;
                bc.PrepareCPUBlit();
                Blit_Functions.half = bc.Size(true) / volumeScale;

                var pixels = image.Pixels;

                int  ihalf  = (int)(Blit_Functions.half - 0.5f);
                bool smooth = bc.Type(true) != BrushTypePixel.Inst;
                if (smooth)
                {
                    ihalf += 1;
                }

                Blit_Functions._alphaMode = Blit_Functions.SphereAlpha;

                int sliceWidth = texWidth / slices;

                int hw = sliceWidth / 2;

                int y = (int)pos.y;        // (int)Mathf.Clamp(pos.y, 0, height - 1);
                int z = (int)(pos.z + hw); // (int)Mathf.Clamp(pos.z + hw, 0, hw - 1);
                int x = (int)(pos.x + hw); // (int)Mathf.Clamp(pos.x + hw, 0, hw - 1);


                for (Blit_Functions.y = -ihalf; Blit_Functions.y < ihalf + 1; Blit_Functions.y++)
                {
                    int h = y + Blit_Functions.y;

                    if (h >= height)
                    {
                        return(true);
                    }

                    if (h >= 0)
                    {
                        int hy         = h / slices;
                        int hx         = h % slices;
                        int hTex_index = (hy * texWidth + hx) * sliceWidth;

                        for (Blit_Functions.z = -ihalf; Blit_Functions.z < ihalf + 1; Blit_Functions.z++)
                        {
                            int trueZ = z + Blit_Functions.z;

                            if (trueZ >= 0 && trueZ < sliceWidth)
                            {
                                int yTex_index = hTex_index + trueZ * texWidth;

                                for (Blit_Functions.x = -ihalf; Blit_Functions.x < ihalf + 1; Blit_Functions.x++)
                                {
                                    int trueX = x + Blit_Functions.x;

                                    if (trueX >= 0 && trueX < sliceWidth)
                                    {
                                        int texIndex = yTex_index + trueX;

                                        if (Blit_Functions._alphaMode())
                                        {
                                            Blit_Functions._blitMode(ref pixels[texIndex]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(true);
            }
            return(false);
        }
 public virtual bool PaintRenderTexture(StrokeVector stroke, ImageData image, BrushConfig bc, PlaytimePainter pntr)
 {
     return(false);
 }
        public bool PaintTexture2D(StrokeVector stroke, float brushAlpha, ImageData image, BrushConfig bc, PlaytimePainter pntr)
        {
            if (pntr.IsAtlased())
            {
                Vector2 uvCoords = stroke.uvFrom;

                Vector2 AtlasedSection = GetAtlasedSection();

                sectorSize = image.width / atlasRows;
                atlasSector.From(AtlasedSection * sectorSize);

                Blit_Functions.brAlpha = brushAlpha;

                Blit_Functions.half = (bc.Size(false)) / 2;
                int ihalf = Mathf.FloorToInt(Blit_Functions.half - 0.5f);

                bool smooth = bc.Type(true) != BrushTypePixel.Inst;

                if (smooth)
                {
                    Blit_Functions._alphaMode = Blit_Functions.circleAlpha;
                }
                else
                {
                    Blit_Functions._alphaMode = Blit_Functions.noAlpha;
                }

                Blit_Functions._blitMode = bc.BlitMode.BlitFunctionTex2D;

                if (smooth)
                {
                    ihalf += 1;
                }

                Blit_Functions.alpha = 1;

                Blit_Functions.r = bc.mask.GetFlag(BrushMask.R);
                Blit_Functions.g = bc.mask.GetFlag(BrushMask.G);
                Blit_Functions.b = bc.mask.GetFlag(BrushMask.B);
                Blit_Functions.a = bc.mask.GetFlag(BrushMask.A);

                Blit_Functions.csrc = bc.colorLinear.ToGamma();

                MyIntVec2 tmp = image.UvToPixelNumber(uvCoords);//new myIntVec2 (pixIndex);

                int fromx = tmp.x - ihalf;

                tmp.y -= ihalf;


                var pixels = image.Pixels;

                for (Blit_Functions.y = -ihalf; Blit_Functions.y < ihalf + 1; Blit_Functions.y++)
                {
                    tmp.x = fromx;

                    for (Blit_Functions.x = -ihalf; Blit_Functions.x < ihalf + 1; Blit_Functions.x++)
                    {
                        if (Blit_Functions._alphaMode())
                        {
                            int sx = tmp.x - atlasSector.x;
                            int sy = tmp.y - atlasSector.y;

                            sx %= sectorSize;
                            if (sx < 0)
                            {
                                sx += sectorSize;
                            }
                            sy %= sectorSize;
                            if (sy < 0)
                            {
                                sy += sectorSize;
                            }

                            Blit_Functions._blitMode(ref pixels[((atlasSector.y + sy)) * image.width + (atlasSector.x + sx)]);
                        }

                        tmp.x += 1;
                    }

                    tmp.y += 1;
                }
                return(true);
            }

            return(false);
        }
示例#9
0
 public RenderTexture Render(Texture from, ImageData to) => Render(from, to.CurrentRenderTexture(), Data.brushRendy_bufferCopy);
示例#10
0
 public RenderTexture Render(ImageData from, RenderTexture to) => Render(from.CurrentTexture(), to, Data.brushRendy_bufferCopy);