コード例 #1
0
        private void BeforeClosing()
        {
            DownloadManager.Dispose();

            #if UNITY_EDITOR
            EditorApplication.update -= CombinedUpdate;

            if (PlaytimePainter.previewHolderMaterial)
            {
                PlaytimePainter.CheckSetOriginalShader();
            }

            if (materialsUsingRenderTexture.Count > 0)
            {
                autodisabledBufferTarget = materialsUsingRenderTexture[0].painterTarget;
            }

            EmptyBufferTarget();
            #endif

            if (!CameraModuleBase.modules.IsNullOrEmpty())
            {
                foreach (var p in CameraModuleBase.modules)
                {
                    p?.Disable();
                }
            }

            if (Data)
            {
                Data.ManagedOnDisable();
            }

            RenderTextureBuffersManager.OnDisable();
        }
コード例 #2
0
        private Color SampleRenderTexture(Vector2 uv)
        {
            var curRt = RenderTexture.active;

            var rtp  = PainterCamera.Inst;
            int size = RenderTextureBuffersManager.renderBuffersSize / 4;

            RenderTexture.active = renderTexture ? renderTexture : RenderTextureBuffersManager.GetDownscaledBigRt(size, size);

            if (!_sampler)
            {
                _sampler = new Texture2D(8, 8);
            }

            UVto01(ref uv);

            if (!renderTexture)
            {
                uv.y = 1 - uv.y; // For some reason sampling is mirrored around Y axiz for BigRenderTexture (?)
            }
            uv *= RenderTexture.active.width;

            _sampler.ReadPixels(new Rect(uv.x, uv.y, 1, 1), 0, 0);

            RenderTexture.active = curRt;

            var pix = _sampler.GetPixel(0, 0);

            if (PainterCamera.Inst.IsLinearColorSpace)
            {
                pix = pix.linear;
            }

            return(pix);
        }
コード例 #3
0
        public void Resize(int newWight, int newHeight)
        {
            if (newHeight >= 8 && newHeight <= 4096 && newWight >= 8 && newWight <= 4096 && (newWight != width || newHeight != height) && texture2D)
            {
                var tmp = renderTexture;
                renderTexture = null;

                Texture2D_To_RenderTexture();

                texture2D.Resize(newWight, newHeight);

                width = newWight;

                height = newHeight;

                texture2D.CopyFrom(RenderTextureBuffersManager.GetDownscaledBigRt(width, height));

                PixelsFromTexture2D(texture2D);

                SetAndApply();

                renderTexture = tmp;

                Debug.Log("Resize Complete");
            }
        }
コード例 #4
0
        public bool PaintRenderTexture(BrushStrokePainterImage cfg)
        {
            var stroke  = cfg.stroke;
            var image   = cfg.image;
            var painter = cfg.painter;
            var bc      = cfg.brush;

            var vt = painter.GetVolumeTexture();

            stroke.posFrom = stroke.posTo;

            BrushTypeSphere.Inst.BeforeStroke(painter, bc, stroke);

            VOLUME_POSITION_N_SIZE_BRUSH.GlobalValue = vt.PosSize4Shader;
            VOLUME_H_SLICES_BRUSH.GlobalValue        = vt.Slices4Shader;
            VOLUME_BRUSH_DIRECTION.GlobalValue       = stroke.collisionNormal.ToVector4(0);

            image.useTexCoord2 = false;
            bool alphaBuffer;

            TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(bc, bc.Speed * 0.05f, image, stroke, painter, out alphaBuffer);

            stroke.SetWorldPosInShader();

            RenderTextureBuffersManager.Blit(null, image.CurrentRenderTexture(), TexMGMT.brushRenderer.meshRenderer.sharedMaterial.shader);

            BrushTypeSphere.Inst.AfterStroke_Painter(painter, bc, stroke, alphaBuffer, image);

            return(true);
        }
コード例 #5
0
        public void AfterCameraRender(RenderTexture texture)
        {
            var size = RenderTextureBuffersManager.tinyTextureSize;

            int pixelsCount = size * size;

            var tiny = RenderTextureBuffersManager.GetDownscaleOf(texture, RenderTextureBuffersManager.tinyTextureSize, true);

            var pix = RenderTextureBuffersManager.GetMinSizeTexture().CopyFrom(tiny).GetPixels();

            Color avg = Color.black;

            foreach (var p in pix)
            {
                avg += p;
            }

            var pcam = PainterCamera.GetProjectorCamera();

            GlobalBrush.Color = avg / (float)pixelsCount;

            PainterCamera.BrushColorProperty.GlobalValue = GlobalBrush.Color;

            PaintRenderTexture(delayedPaintingConfiguration);

            delayedPaintingConfiguration = null;
        }
コード例 #6
0
        private void BlitRt(Texture tex, Shader shader = null)
        {
            if (shader)
            {
                EffectMaterial.shader = shader;
            }

            if (IsUsingCrt)
            {
                _effetBuffer.material = EffectMaterial;
                _effetBuffer.Update();
            }
            else
            {
                if (shader)
                {
                    if (_postProcessMethod == PostProcessMethod.GlBlit)
                    {
                        RenderTextureBuffersManager.BlitGL(tex, MainTexture, EffectMaterial);
                    }
                    else
                    {
                        Graphics.Blit(tex, MainTexture, EffectMaterial);
                    }
                }
                else
                {
                    Graphics.Blit(tex, MainTexture);
                }
            }

            _onUpdated?.Invoke();
        }
コード例 #7
0
        public void SHADER_STROKE_SEGMENT_UPDATE(BrushConfig bc, float brushAlpha, TextureMeta id, StrokeVector stroke, out bool alphaBuffer, PlaytimePainter pntr = null)
        {
            CheckPaintingBuffers();

            var isDoubleBuffer = !id.renderTexture;

            var useSingle = !isDoubleBuffer || bc.IsSingleBufferBrush();

            var blitMode = bc.GetBlitMode(false);

            alphaBuffer = !useSingle && bc.useAlphaBuffer && bc.GetBrushType(false).SupportsAlphaBufferPainting&& blitMode.SupportsAlphaBufferPainting;

            Shader shd = null;

            if (pntr)
            {
                foreach (var pl in CameraModuleBase.BrushPlugins)
                {
                    var bs = useSingle ? pl.GetBrushShaderSingleBuffer(pntr) : pl.GetBrushShaderDoubleBuffer(pntr);
                    if (!bs)
                    {
                        continue;
                    }
                    shd = bs;
                    break;
                }
            }

            if (!shd)
            {
                if (alphaBuffer)
                {
                    shd = blitMode.ShaderForAlphaOutput;
                    AlphaBufferSetDirtyBeforeRender(id, blitMode.ShaderForAlphaBufferBlit);
                }
                else
                {
                    shd = useSingle ? blitMode.ShaderForSingleBuffer : blitMode.ShaderForDoubleBuffer;
                }
            }


            if (!useSingle && !RenderTextureBuffersManager.secondBufferUpdated)
            {
                RenderTextureBuffersManager.UpdateBufferTwo();
            }

            //if (stroke.firstStroke)
            SHADER_BRUSH_UPDATE(bc, brushAlpha, id, pntr);

            TargetTexture = alphaBuffer ? AlphaBuffer : id.CurrentRenderTexture();

            if (isDoubleBuffer)
            {
                PainterShaderVariables.DESTINATION_BUFFER.GlobalValue = BackBuffer;
            }

            CurrentShader = shd;
        }
コード例 #8
0
        public void Set(ImageMeta from, int globalOrder)
        {
            RenderTextureBuffersManager.Blit(from.CurrentRenderTexture(), rt);

            SetB(from, globalOrder);

            exclusive = from.renderTexture != null;
        }
コード例 #9
0
ファイル: BrushTypes.cs プロジェクト: NeatWolf/Tools
            public void BeforeStroke(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                var cam = TexMGMT;

                if (!RenderTextureBuffersManager.secondBufferUpdated)
                {
                    RenderTextureBuffersManager.UpdateBufferTwo();
                }

                foreach (var p in painter.Modules)
                {
                    p.BeforeGpuStroke(painter, br, st, this);
                }
            }
コード例 #10
0
        public void UpdateFromAlphaBuffer(RenderTexture rt, Shader shader)
        {
            if (rt)
            {
                PainterShaderVariables.AlphaPaintingBuffer.GlobalValue = AlphaBuffer;
                Render(AlphaBuffer, rt, shader);
            }

            DiscardAlphaBuffer();

            if (!RenderTextureBuffersManager.secondBufferUpdated)
            {
                RenderTextureBuffersManager.UpdateBufferTwo();
            }
        }
コード例 #11
0
        public override bool Inspect()
        {
            var changed = false;

            pegi.toggle(ref pauseAutoUpdates, icon.Play, icon.Pause,
                        pauseAutoUpdates ? "Resume Updates" : "Pause Updates").changes(ref changed);

            if (!_foldOut)
            {
                pegi.toggle(ref _projectFromMainCamera, icon.Link, icon.UnLinked, "Link Projector Camera to {0} camera".F(Application.isPlaying ? "Main Camera" : "Editor Camera")).changes(ref changed);
            }

            if ("Projector ".enter(ref _foldOut).nl_ifFoldedOut())
            {
                if (RenderTextureBuffersManager.InspectDepthTarget().nl(ref changed))
                {
                    UpdateDepthCamera();
                }

                if (_projectorCamera)
                {
                    "Project from Camera".toggleIcon("Will always project from Play or Editor Camera", ref _projectFromMainCamera).nl(ref changed);

                    if (_projectFromMainCamera)
                    {
                        "Follow the mouse".toggleIcon(ref _centerOnMousePosition).nl(ref changed);
                    }

                    var fov = _projectorCamera.fieldOfView;

                    if ("FOV".edit(30, ref fov, 0.1f, 180f).nl(ref changed))
                    {
                        _projectorCamera.fieldOfView = fov;
                    }
                }

                if (!PlaytimePainter.inspected)
                {
                    "Requested updates".edit_List(ref depthUsers, ref _inspectedUser).nl();
                }
            }
            else
            {
                this.ClickHighlight().nl();
            }

            return(changed);
        }
コード例 #12
0
ファイル: TextureMeta.cs プロジェクト: jjmac/Playtime-Painter
        private void RenderTexture_To_Texture2D(Texture2D tex)
        {
            if (!texture2D)
            {
                return;
            }

            var rt = renderTexture;

            TexMGMT.TryApplyBufferChangesTo(this);

            if (!rt && TexMGMT.imgMetaUsingRendTex == this)
            {
                rt = RenderTextureBuffersManager.GetDownscaledBigRt(width, height);
            }

            //Graphics.CopyTexture();

            if (!rt)
            {
                return;
            }

            tex.CopyFrom(rt);

            PixelsFromTexture2D(tex);

            var converted = false;

            if (PainterCamera.Inst.IsLinearColorSpace)
            {
                if (!tex.IsColorTexture())
                {
                    converted = true;
                    PixelsToLinear();
                }
            }

            if (converted)
            {
                SetAndApply();
            }
            else
            {
                texture2D.Apply(true);
            }
        }
コード例 #13
0
        private void OnEnable()
        {
            if (!_projectorCamera)
            {
                _projectorCamera = GetComponent <Camera>();

                if (!_projectorCamera)
                {
                    _projectorCamera = gameObject.AddComponent <Camera>();
                }
            }

            RenderTextureBuffersManager.UpdateDepthTarget();
            UpdateDepthCamera();

            PainterCamera.depthProjectorCamera = this;

            _painterDepthTexture.GlobalValue = RenderTextureBuffersManager.depthTarget;
        }
コード例 #14
0
        public override bool Inspect()
        {
            var changed = false;

            pegi.toggleDefaultInspector(this);

            if (icon.Delete.Click("Delete Projector Camera"))
            {
                gameObject.DestroyWhatever();
            }

            pegi.toggle(ref pauseAutoUpdates, icon.Play, icon.Pause,
                        pauseAutoUpdates ? "Resume Updates" : "Pause Updates").changes(ref changed);

            if (RenderTextureBuffersManager.InspectDepthTarget().nl(ref changed))
            {
                UpdateDepthCamera();
            }

            if (_projectorCamera)
            {
                "Project from Camera".toggleIcon("Will always project from Play or Editor Camera", ref _projectFromMainCamera).nl(ref changed);

                if (_projectFromMainCamera)
                {
                    "Follow the mouse".toggleIcon(ref _centerOnMousePosition).nl(ref changed);
                }

                var fov = _projectorCamera.fieldOfView;

                if ("FOV".edit(30, ref fov, 0.1f, 180f).nl(ref changed))
                {
                    _projectorCamera.fieldOfView = fov;
                }
            }

            "Requested updates".edit_List(ref depthUsers, ref _inspectedUser).nl();

            return(changed);
        }
コード例 #15
0
            public void BeforeStroke(PaintCommand.UV command)//Brush br, Stroke st, PlaytimePainter painter = null)
            {
                Brush  br = command.Brush;
                Stroke st = command.Stroke;

                PaintCommand.ForPainterComponent painterCommand = command as PaintCommand.ForPainterComponent;

                var cam = TexMGMT;

                if (!RenderTextureBuffersManager.secondBufferUpdated)
                {
                    RenderTextureBuffersManager.UpdateBufferTwo();
                }

                if (painterCommand != null)
                {
                    foreach (var p in painterCommand.painter.Modules)
                    {
                        p.BeforeGpuStroke(painterCommand);//br, st, this);
                    }
                }
            }
コード例 #16
0
        public void EmptyBufferTarget()
        {
            if (imgMetaUsingRendTex == null)
            {
                return;
            }

            if (imgMetaUsingRendTex.texture2D)
            {
                imgMetaUsingRendTex.RenderTexture_To_Texture2D();
            }

            imgMetaUsingRendTex.target = TexTarget.Texture2D;

            foreach (var m in materialsUsingRenderTexture)
            {
                m.SetTextureOnLastTarget(imgMetaUsingRendTex);
            }

            materialsUsingRenderTexture.Clear();
            imgMetaUsingRendTex = null;
            RenderTextureBuffersManager.DiscardPaintingBuffersContents();
        }
コード例 #17
0
        public virtual bool Inspect()
        {
            var p = PlaytimePainter.inspected;

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

            var id = p.TexMeta;

            var changed = false;
            var cpuBlit = id.target == TexTarget.Texture2D;

            if (id.texture2D)
            {
                if ((cpuBlit ? icon.CPU : icon.GPU).Click(cpuBlit ? "Switch to Render Texture" : "Switch to Texture2D", ref changed, 45))
                {
                    cpuBlit = !cpuBlit;

                    if (!cpuBlit && !PainterCamera.GotBuffers)
                    {
                        RenderTextureBuffersManager.RefreshPaintingBuffers();
                    }

                    p.UpdateOrSetTexTarget(cpuBlit ? TexTarget.Texture2D : TexTarget.RenderTexture);
                    SetSupportedFor(cpuBlit, !id.renderTexture);
                }
            }

            if (cpuBlit)
            {
                var smooth = _brushType(cpuBlit) != BrushTypes.Pixel.Inst.index;

                if (pegi.toggle(ref smooth, icon.Round, icon.Square, "Smooth/Pixels Brush", 45).changes(ref changed))
                {
                    SetBrushType(cpuBlit, smooth ? BrushTypes.Normal.Inst : BrushTypes.Pixel.Inst.AsBase);
                }
            }

            pegi.nl();

            if (showBrushDynamics)
            {
                if ("Brush Dynamic".selectType(90, ref brushDynamic, brushDynamicsConfigs).nl(ref changed))
                {
                    brushDynamic?.Nested_Inspect().nl(ref changed);
                }
            }
            else if (brushDynamic.GetType() != typeof(BrushDynamic.None))
            {
                brushDynamic = (BrushDynamic.None)Activator.CreateInstance(typeof(BrushDynamic.None));
            }

            if (Mode_Type_PEGI().changes(ref changed) && GetBrushType(cpuBlit) == BrushTypes.Decal.Inst)
            {
                MaskSet(ColorMask.A, true);
            }

            if (p.terrain)
            {
                if (p.TexMeta != null && p.IsTerrainHeightTexture && p.NotUsingPreview)
                {
                    "Preview Shader is needed to see changes to terrain height.".writeWarning();
                }

                pegi.nl();

                if (p.terrain && "Update Terrain".Click("Will Set Terrain texture as global shader values.").nl())
                {
                    p.UpdateModules();
                }
            }

            return(changed);
        }
コード例 #18
0
 public RenderTexture GetTargetTexture() => RenderTextureBuffersManager.GetRenderTextureWithDepth();
コード例 #19
0
 public RenderTexture GetTargetTexture() => RenderTextureBuffersManager.GetReusableDepthTarget();
コード例 #20
0
        public bool DependenciesInspect(bool showAll = false)
        {
            var changed = false;

            if (showAll)
            {
                pegi.nl();

                if ("Buffers".enter(ref _inspectedDependecy, 1).nl())
                {
                    RenderTextureBuffersManager.Inspect().nl(ref changed);

#if UNITY_EDITOR
                    "Disable Second Buffer Update (Debug Mode)".toggleIcon(ref disableSecondBufferUpdateDebug).nl();
#endif

                    return(changed);
                }

                pegi.nl();

                "Download Manager".enter_Inspect(DownloadManager, ref _inspectedDependecy, 0).nl(ref changed);

                if (_inspectedDependecy == -1)
                {
                    pegi.FullWindow.DocumentationClickOpen("You can enable URL field in the Optional UI elements to get texture directly from web");
                }


                if (_inspectedDependecy == -1)
                {
                    (IsLinearColorSpace ? "Linear" : "Gamma").nl();

                    "Main Directional Light".edit(ref mainDirectionalLight).nl(ref changed);

#if UNITY_EDITOR
                    if ("Refresh Brush Shaders".Click().nl())
                    {
                        Data.CheckShaders(true);
                        pegi.GameView.ShowNotification("Shaders Refreshed");
                    }
#endif

                    "Using layer:".editLayerMask(ref Data.playtimePainterLayer).nl(ref changed);
                }
            }

            bool showOthers = showAll && _inspectedDependecy == -1;

            #if UNITY_EDITOR
            if (!Data)
            {
                pegi.nl();
                "No data Holder".edit(60, ref dataHolder).nl(ref changed);

                if (icon.Refresh.Click("Try to find it"))
                {
                    PainterClass.applicationIsQuitting = false;
                    triedToFindPainterData             = false;
                }

                if ("Create".Click().nl())
                {
                    PainterClass.applicationIsQuitting = false;
                    triedToFindPainterData             = false;

                    if (!Data)
                    {
                        dataHolder = ScriptableObject.CreateInstance <PainterDataAndConfig>();

                        AssetDatabase.CreateAsset(dataHolder,
                                                  "Assets/Playtime-Painter/Resources/Painter_Data.asset");
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                    }
                }
            }
            #endif


            if (!painterCamera)
            {
                pegi.nl();
                "no painter camera".writeWarning();
                pegi.nl();
            }
            else
            {
                if (painterCamera.clearFlags != CameraClearFlags.Nothing)
                {
                    pegi.nl();
                    "Painter camera is not set to DontClear".writeWarning();
                    if ("Set to DontClear".Click().nl())
                    {
                        painterCamera.clearFlags = CameraClearFlags.Nothing;
                        painterCamera.SetToDirty();
                    }
                }
            }

            Camera depthCamera = depthProjectorCamera ? depthProjectorCamera._projectorCamera : null;

            bool depthAsMain = depthCamera && (depthCamera == MainCamera);

            if (showOthers || !MainCamera || depthAsMain)
            {
                pegi.nl();

                var cam = MainCamera;

                var cams = new List <Camera>(FindObjectsOfType <Camera>());

                if (painterCamera && cams.Contains(painterCamera))
                {
                    cams.Remove(painterCamera);
                }

                if (depthCamera && cams.Contains(depthCamera))
                {
                    cams.Remove(depthCamera);
                }

                if ("Main Camera".select(90, ref cam, cams).changes(ref changed))
                {
                    MainCamera = cam;
                }

                if (icon.Refresh.Click("Try to find camera tagged as Main Camera", ref changed))
                {
                    MainCamera = Camera.main;
                    if (!MainCamera)
                    {
                        pegi.GameView.ShowNotification("No camera is tagged as main");
                    }
                }

                pegi.nl();

                if (depthAsMain)
                {
                    "Depth projector camera is set as Main Camera - this is likely a mistake".writeWarning();
                    pegi.nl();
                }

                if (!cam)
                {
                    "No Main Camera found. Playtime Painting will not be possible".writeWarning();
                }

                pegi.nl();
            }

            return(changed);
        }
コード例 #21
0
        public void RenderTexture_To_Texture2D(Texture2D tex)
        {
            if (!texture2D)
            {
                return;
            }

            var rt = renderTexture;

            TexMGMT.TryApplyBufferChangesTo(this);

            if (!rt && TexMGMT.imgMetaUsingRendTex == this)
            {
                rt = RenderTextureBuffersManager.GetDownscaledBigRt(width, height);
            }

            if (!rt)
            {
                return;
            }

            tex.CopyFrom(rt);

            PixelsFromTexture2D(tex);

            var converted = false;

            /* MAC:
             *      Linear Space
             *          Big RT
             *              Editor
             *                  Linear Texture = To Linear
             *                  sRGB Texture =
             *              Playtime
             *                  Linear Texture = To Linear
             *                  sRGB Texture =
             *          Exclusive
             *              Editor
             *                  Linear Texture =
             *                  sRGB Texture =
             *              Playtime
             *                  Linear Texture
             *                  sRGB Texture =
             *      Gamma Space
             *          Big RT
             *              Editor
             *                  Linear Texture =
             *                  sRGB Texture =
             *              Playtime
             *                  Linear Texture
             *                  sRGB Texture =
             *          Exclusive
             *              Editor
             *                  Linear Texture =
             *                  sRGB Texture =
             *              Playtime
             *                  Linear Texture =
             *                  sRGB Texture =
             */


            if (PainterCamera.Inst.IsLinearColorSpace)
            {
                if (!tex.IsColorTexture())
                {
                    converted = true;
                    PixelsToLinear();
                }

#if UNITY_2017
                if (renderTexture != null)
                {
                    PixelsToGamma();
                    converted = true;
                }
#endif
            }


            //if (!RenderTexturePainter.inst.isLinearColorSpace)
            //pixelsToLinear ();

            if (converted)
            {
                SetAndApply();
            }
            else
            {
                texture2D.Apply(true);
            }
            //
        }
コード例 #22
0
        public void SHADER_STROKE_SEGMENT_UPDATE(PaintCommand.UV command)
        {
            Brush       bc     = command.Brush;
            TextureMeta id     = command.TextureData;
            Stroke      stroke = command.Stroke;

            var isDoubleBuffer = !id.renderTexture;

            var useSingle = !isDoubleBuffer || bc.IsSingleBufferBrush();

            var blitMode = bc.GetBlitMode(false);

            command.usedAlphaBuffer = !useSingle && bc.useAlphaBuffer && bc.GetBrushType(false).SupportsAlphaBufferPainting&& blitMode.SupportsAlphaBufferPainting;

            var painter = command.TryGetPainter();

            Shader shd = null;

            if (painter)
            {
                foreach (var pl in CameraModuleBase.BrushPlugins)
                {
                    var bs = useSingle ? pl.GetBrushShaderSingleBuffer(painter) : pl.GetBrushShaderDoubleBuffer(painter);
                    if (!bs)
                    {
                        continue;
                    }
                    shd = bs;
                    break;
                }
            }

            if (!shd)
            {
                if (command.usedAlphaBuffer)
                {
                    shd = blitMode.ShaderForAlphaOutput;
                    AlphaBufferSetDirtyBeforeRender(id, blitMode.ShaderForAlphaBufferBlit);
                }
                else
                {
                    shd = useSingle ? blitMode.ShaderForSingleBuffer : blitMode.ShaderForDoubleBuffer;
                }
            }


            if (!useSingle && !RenderTextureBuffersManager.secondBufferUpdated)
            {
                RenderTextureBuffersManager.UpdateBufferTwo();
            }

            SHADER_BRUSH_UPDATE(command);

            TargetTexture = command.usedAlphaBuffer ? AlphaBuffer : id.CurrentRenderTexture();

            if (isDoubleBuffer)
            {
                PainterShaderVariables.DESTINATION_BUFFER.GlobalValue = BackBuffer;
            }

            CurrentShader = shd;
        }
コード例 #23
0
            protected override bool Inspect()
            {
                var changed = base.Inspect().nl();

                var allCstm = Cfg.customBlitModes;

                if ("Config".select_Index(60, ref Cfg.selectedCustomBlitMode, allCstm))
                {
                    Cfg.SetToDirty();
                }

                var cfg = _customCfg;

                if (pegi.edit(ref cfg, 60).nl(ref changed) && cfg)
                {
                    if (allCstm.Contains(cfg))
                    {
                        Cfg.selectedCustomBlitMode = allCstm.IndexOf(cfg);
                    }
                    else
                    {
                        Cfg.customBlitModes.Add(cfg);
                        Cfg.selectedCustomBlitMode = Cfg.customBlitModes.Count - 1;
                    }
                }



                if (_customCfg)
                {
                    if (_customCfg.name.foldout(ref _showConfig).nl(ref changed))
                    {
                        _customCfg.Nested_Inspect(ref changed);
                    }
                }
                else
                {
                    ("Create a BlitModeCustom Scriptable Object and put your custom blit shader into it. " +
                     " Right mouse button in the Project view and select Create->Playtime Painter-> Blit Mode Custom ").writeHint();
                    pegi.nl();
                }

                if (IsBlitReady)
                {
                    if (PlaytimePainter.inspected)
                    {
                        var img = PlaytimePainter.inspected.TexMeta;
                        if (img != null)
                        {
                            var rt = img.CurrentRenderTexture();

                            if (rt)
                            {
                                if ("Grahics BLIT".Click().nl())
                                {
                                    RenderTextureBuffersManager.Blit(
                                        from: _customCfg.sourceTexture ? _customCfg.sourceTexture : rt,
                                        to: rt,
                                        shader: _customCfg.shader);
                                }

                                if ("Painter Camera Render".Click().nl())
                                {
                                    PainterCamera.Inst.Render(
                                        from: _customCfg.sourceTexture ? _customCfg.sourceTexture : rt,
                                        to: rt,
                                        shader: _customCfg.shader);
                                }
                            }
                        }
                    }
                }

                return(false);
            }
コード例 #24
0
 public void DiscardAlphaBuffer()
 {
     RenderTextureBuffersManager.ClearAlphaBuffer();
     alphaBufferDataTarget = null;
 }
コード例 #25
0
        public virtual bool Inspect()
        {
            var p = PlaytimePainter.inspected;

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

            pegi.nl();

            if (p.skinnedMeshRenderer)
            {
                if ("Update Collider from Skinned Mesh".Click())
                {
                    p.UpdateMeshCollider();
                }

                if (DocsEnabled && pegi.DocumentationClick("Why Update Collider from skinned mesh?"))
                {
                    pegi.FullWindwDocumentationOpen(
                        ("To paint an object a collision detection is needed. Mesh Collider is not being animated. To paint it, update Mesh Collider with Update Collider button." +
                         " For ingame painting it is preferable to use simple colliders like Speheres to avoid per frame updates for collider mesh."
                        ));
                }

                pegi.nl();
            }


            var id = p.ImgMeta;

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

            p.PreviewShaderToggleInspect().changes(ref changed);

            if (!PainterCamera.GotBuffers && icon.Refresh.Click("Refresh Main Camera Buffers"))
            {
                RenderTextureBuffersManager.RefreshPaintingBuffers();
            }

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

            if (cpuBlit)
            {
                var smooth = _brushType(cpuBlit) != BrushTypePixel.Inst.index;

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

            pegi.nl();

            if (showBrushDynamics)
            {
                if ("Brush Dynamic".selectType(90, ref brushDynamic, brushDynamicsConfigs, true).nl(ref changed))
                {
                    brushDynamic?.Nested_Inspect().nl(ref changed);
                }
            }
            else if (brushDynamic.GetType() != typeof(BrushDynamic_None))
            {
                brushDynamic = (BrushDynamic_None)Activator.CreateInstance(typeof(BrushDynamic_None));
            }

#if UNITY_EDITOR
#if !UNITY_2019_1_OR_NEWER
            if (Tools.current != Tool.None)
            {
                MsgPainter.LockToolToUseTransform.GetText().writeWarning();
                if (MsgPainter.HideTransformTool.GetText().Click().nl())
                {
                    UnityUtils.HideUnityTool();
                }
            }
#endif
#endif


            if (Mode_Type_PEGI().changes(ref changed) && GetBrushType(cpuBlit) == BrushTypeDecal.Inst)
            {
                MaskSet(BrushMask.A, true);
            }

            if (p.terrain)
            {
                if (p.ImgMeta != null && p.IsTerrainHeightTexture && p.NotUsingPreview)
                {
                    "Preview Shader is needed to see changes to terrain height.".writeWarning();
                }

                pegi.nl();

                if (p.terrain && "Update Terrain".Click("Will Set Terrain texture as global shader values.").nl())
                {
                    p.UpdateShaderGlobals();
                }
            }

            return(changed);
        }
コード例 #26
0
 public static bool IsBigRenderTexturePair(this Texture tex) => tex && (tex == RenderTextureBuffersManager.GetPaintingBufferIfExist(0));
コード例 #27
0
        public bool DependenciesInspect(bool showAll = false)
        {
            var changed = false;

            if (showAll)
            {
                "Download Manager".enter_Inspect(DownloadManager, ref _inspectedDependecy, 0).changes(ref changed);

                if (_inspectedDependecy == -1)
                {
                    "You can enable URL field in the Optional UI elements to get texture directly from web"
                    .fullWindowDocumentationClickOpen();
                }

                pegi.nl();

                if (_inspectedDependecy == -1)
                {
                    "Main Directional Light".edit(ref mainDirectionalLight).nl(ref changed);

#if UNITY_EDITOR
                    if ("Refresh Brush Shaders".Click(14).nl())
                    {
                        Data.CheckShaders(true);
                        "Shaders Refreshed".showNotificationIn3D_Views();
                    }
#endif

                    "Using layer:".editLayerMask(ref Data.playtimePainterLayer).nl(ref changed);
                }


                if ("Buffers".enter(ref _inspectedDependecy, 1).nl())
                {
                    RenderTextureBuffersManager.Inspect().nl(ref changed);

#if UNITY_EDITOR
                    "Disable Second Buffer Update (Debug Mode)".toggleIcon(ref disableSecondBufferUpdateDebug).nl();
#endif

                    return(changed);
                }
            }
#if UNITY_EDITOR
            if (!Data)
            {
                pegi.nl();
                "No data Holder".edit(60, ref dataHolder).nl(ref changed);

                if (icon.Refresh.Click("Try to find it"))
                {
                    PainterSystem.applicationIsQuitting = false;
                    triedToFindPainterData = false;
                }

                if ("Create".Click().nl())
                {
                    PainterSystem.applicationIsQuitting = false;
                    triedToFindPainterData = false;

                    if (!Data)
                    {
                        dataHolder = ScriptableObject.CreateInstance <PainterDataAndConfig>();

                        AssetDatabase.CreateAsset(dataHolder,
                                                  "Assets/Tools/Playtime Painter/Resources/Painter_Data.asset");
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                    }
                }
            }
            #endif

            if (showAll || !RenderTextureBuffersManager.GotPaintingBuffers)
            {
                (RenderTextureBuffersManager.GotPaintingBuffers ? "No buffers" : "Using HDR buffers " + ((!FrontBuffer) ? "uninitialized" : "initialized")).nl();
            }

            if (!painterCamera)
            {
                pegi.nl();
                "no painter camera".writeWarning();
                pegi.nl();
            }

            if (showAll || !MainCamera)
            {
                pegi.nl();

                var cam = MainCamera;

                if (!cam)
                {
                    icon.Warning.write("No Main Camera found. Playtime Painting will not be possible");
                }

                var cams = new List <Camera>(FindObjectsOfType <Camera>());

                if (painterCamera && cams.Contains(painterCamera))
                {
                    cams.Remove(painterCamera);
                }

                if ("Main Camera".select(60, ref cam, cams).changes(ref changed))
                {
                    MainCamera = cam;
                }

                if (icon.Refresh.Click("Try to find camera tagged as Main Camera", ref changed))
                {
                    MainCamera = Camera.main;
                    if (!MainCamera)
                    {
                        "No camera is tagged as main".showNotificationIn3D_Views();
                    }
                }

                pegi.nl();
            }

            return(changed);
        }