Пример #1
0
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, ImageMeta id, PlaytimePainter painter)
        {
            var tex = id.CurrentTexture();

            if (!painter.terrain)
            {
                return(false);
            }

            if (!field.HasUsageTag(PainterDataAndConfig.TERRAIN_CONTROL_TEXTURE))
            {
                return(false);
            }

            var no = field.NameForDisplayPEGI[0].CharToInt();

            if (no == 0)
            {
                PainterDataAndConfig.TerrainControlMain.GlobalValue = tex;
            }

            painter.terrain.terrainData.alphamapTextures[no] = id.texture2D;

            return(true);
        }
Пример #2
0
 public void SetTextureOnLastTarget(ImageMeta id)
 {
     if (painterTarget)
     {
         painterTarget.SetTextureOnMaterial(bufferParameterTarget, id.CurrentTexture(), material);
     }
 }
Пример #3
0
        public virtual void UpdateMaterials()
        {
            materials.SetVolumeTexture(this);

            if (!setForGlobal)
            {
                return;
            }

            PositionAndScaleProperty.SetGlobal(PosSize4Shader);
            SlicesShadeProperty.SetGlobal(Slices4Shader);
            TextureInShaderProperty.SetGlobal(ImageMeta.CurrentTexture());
        }
Пример #4
0
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, ImageMeta id, PlaytimePainter painter)
        {
            if (!CorrectField(field, painter))
            {
                return(false);
            }

            if (id != null && id.texture2D)
            {
                painter.terrainHeightTexture = id.texture2D;
            }

            var tex = id.CurrentTexture();

            PainterDataAndConfig.TerrainHeight.GlobalValue = tex;
            return(true);
        }
Пример #5
0
        public virtual void UpdateMaterials()
        {
            materials.SetVolumeTexture(this);

            if (!setForGlobal)
            {
                return;
            }

            if (PositionAndScaleProperty.GlobalValue != PosSize4Shader)
            {
                // Debug.Log("Updating pos n shader during move " +Time.frameCount );
                PositionAndScaleProperty.SetGlobal(PosSize4Shader);
            }

            SlicesShadeProperty.SetGlobal(Slices4Shader);
            TextureInShaderProperty.SetGlobal(ImageMeta.CurrentTexture());
        }
Пример #6
0
        public virtual void Update()
        {
            var currentTexture = ImageMeta.CurrentTexture();

            if (currentTexture != _previousTarget)
            {
                _previousTarget = currentTexture;

                UpdateMaterials();
            }

            if (_previousWorldPosition == transform.position)
            {
                return;
            }

            _previousWorldPosition = transform.position;

            UpdateMaterials();
        }
Пример #7
0
        public virtual void UpdateMaterials()
        {
            materials.SetVolumeTexture(this);

            if (!setForGlobal)
            {
                return;
            }

            if (!CurrentGlobal)
            {
                CurrentGlobal = this;
            }

            if (CurrentGlobal == this)
            {
                VolumePaintingModule.VOLUME_POSITION_N_SIZE_Global.SetGlobal(PosSize4Shader);
                VolumePaintingModule.VOLUME_H_SLICES_Global.SetGlobal(Slices4Shader);
                MaterialPropertyNameGlobal.SetGlobal(ImageMeta.CurrentTexture());
            }
        }
Пример #8
0
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, ImageMeta id, PlaytimePainter painter)
        {
            var tex = id.CurrentTexture();

            if (!painter.terrain || !field.Equals(PainterDataAndConfig.TerrainLight))
            {
                return(false);
            }

            FindMergingTerrain(painter);
            if (mergingTerrain && id != null)
            {
                mergingTerrain.lightTexture = id.texture2D;
            }

#if UNITY_EDITOR
            var t2D = tex as Texture2D;

            if (t2D)
            {
                var importer = (t2D).GetTextureImporter();
                if (importer != null)
                {
                    var needReimport = importer.WasClamped();
                    needReimport |= importer.HadNoMipmaps();

                    if (needReimport)
                    {
                        importer.SaveAndReimport();
                    }
                }
            }
#endif

            PainterDataAndConfig.TerrainLight.GlobalValue = tex;



            return(true);
        }
Пример #9
0
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, ImageMeta id, PlaytimePainter painter)
        {
            var tex = id.CurrentTexture();

            if (!painter.terrain)
            {
                return(false);
            }
            if (!field.HasUsageTag(PainterDataAndConfig.TERRAIN_SPLAT_DIFFUSE))
            {
                return(false);
            }
            var no = field.NameForDisplayPEGI[0].CharToInt();

            painter.terrain.SetSplashPrototypeTexture(id.texture2D, no);
            if (tex.GetType() != typeof(Texture2D))
            {
                Debug.Log("Can only use Texture2D for Splat Prototypes. If using regular terrain may not see changes.");
            }
            else
            {
            #if UNITY_EDITOR
                var texImporter = ((Texture2D)tex).GetTextureImporter();
                if (texImporter == null)
                {
                    return(true);
                }
                var needReimport = texImporter.WasClamped();
                needReimport |= texImporter.HadNoMipmaps();

                if (needReimport)
                {
                    texImporter.SaveAndReimport();
                }
            #endif
            }
            return(true);
        }
Пример #10
0
        public override bool Inspect()
        {
            var changed = false;

            pegi.toggleDefaultInspector(this);

            if (_textureInShaderr != null)
            {
                if (icon.Delete.Click())
                {
                    _textureInShaderr = null;
                }

                _textureInShaderr.GetNameForInspector().nl();
            }

            if (searchedForPainter)
            {
                _painter = GetComponent <PlaytimePainter>();
            }

            if (!_painter)
            {
                "Painter [None]".write();
                if ("Search".Click())
                {
                    _painter = GetComponent <PlaytimePainter>();
                }

                if (icon.Add.Click())
                {
                    _painter = GetComponent <PlaytimePainter>();
                    if (!_painter)
                    {
                        _painter = gameObject.AddComponent <PlaytimePainter>();
                    }
                }

                pegi.nl();
            }
            else
            {
                if (_painter.gameObject != gameObject)
                {
                    "Painter is on a different Game Object".writeWarning();
                    if ("Disconnect".Click())
                    {
                        _painter = null;
                    }
                }

                var mod = _painter.GetModule <VolumeTextureComponentModule>();
                if (!mod.volumeTexture && "Assign volume texture to painter".Click().nl())
                {
                    mod.volumeTexture = this;
                }

                if (mod.volumeTexture)
                {
                    if (mod.volumeTexture == this)
                    {
                        "This volume texture is attached".write();
                    }

                    if (icon.UnLinked.Click("Unlink"))
                    {
                        mod.volumeTexture = null;
                    }
                }

                pegi.nl();
            }

            pegi.fullWindowDocumentationClickOpen(VolumeDocumentation);

            if (inspectedElement == -1)
            {
                "Also set for Global shader parameters".toggleIcon(ref setForGlobal).changes(ref changed);

                pegi.nl();
            }

            if ("Volume Texture".enter(ref inspectedElement, 1).nl())
            {
                var n = NameForPEGI;
                if ("Name".editDelayed(50, ref n).nl(ref changed))
                {
                    NameForPEGI = n;
                }

                if (setForGlobal)
                {
                    "FOR GLOBAL ONLY:".nl();

                    PositionAndScaleProperty.NameForDisplayPEGI().write_ForCopy().nl();

                    SlicesShadeProperty.NameForDisplayPEGI().write_ForCopy().nl();
                }

                var tex = ImageMeta.CurrentTexture();

                if (tex == null)
                {
                    ImageMeta = null;
                }

                if ("Texture".edit(60, ref tex).nl(ref changed))
                {
                    ImageMeta = tex ? tex.GetTextureMeta() : null;
                }

                "Volume Scale".edit(70, ref size).nl(ref changed);
                size = Mathf.Max(0.0001f, size);

                if (ImageMeta == null)
                {
                    if (!TexturesPool.inst)
                    {
                        pegi.nl();
                        "Texture Width".edit(90, ref _tmpWidth).changes(ref changed);

                        if ("Create Pool".Click().nl(ref changed))
                        {
                            _tmpWidth = Mathf.ClosestPowerOfTwo(Mathf.Clamp(_tmpWidth, 128, 2048));
                            TexturesPool.GetOrCreateInstance.width = _tmpWidth;
                        }
                    }
                    else
                    {
                        if ("Get From Pool".Click().nl(ref changed))
                        {
                            ImageMeta = TexturesPool.inst.GetTexture2D().GetTextureMeta();
                        }

                        TexturesPool.inst.Nested_Inspect().nl();
                    }
                }
                pegi.nl();

                "Slices:".edit("How texture will be sliced for height", 80, ref hSlices, 1, 8).nl(ref changed);

                if (changed)
                {
                    UpdateImageMeta();
                }

                var w = Width;
                ("Will result in X:" + w + " Z:" + w + " Y:" + Height + "volume").nl();
            }

            if ("Materials [{0}]".F(materials.Count).enter(ref inspectedElement, 2).nl_ifFoldedOut())
            {
                "Materials".edit_List_UObj(ref materials, ref inspectedMaterial);

                if (inspectedMaterial == -1 && InspectedPainter)
                {
                    var pMat = InspectedPainter.Material;
                    if (pMat != null && materials.Contains(pMat) && "Remove This Material".Click().nl(ref changed))
                    {
                        materials.Remove(pMat);
                    }
                }
            }

            if (changed || icon.Refresh.Click("Update Materials"))
            {
                UpdateMaterials();
            }

            pegi.nl();

            return(changed);
        }
Пример #11
0
        public override bool Inspect()
        {
            var changed = false;

            pegi.fullWindowDocumentationClickOpen(VolumeDocumentation);

            if (inspectedElement == -1)
            {
                "Also set for Global shader parameters".toggleIcon(ref setForGlobal, true).changes(ref changed);
                if (setForGlobal)
                {
                    "Current for {0} is {1}".F(MaterialPropertyNameGlobal, CurrentGlobal).nl();
                    if (this != CurrentGlobal && "Clear".Click(ref changed))
                    {
                        CurrentGlobal = null;
                    }
                }

                pegi.nl();
            }

            if ("Volume Texture".enter(ref inspectedElement, 1).nl())
            {
                var n = name;

                if ("Name".editDelayed(50, ref n).nl(ref changed))
                {
                    name = n;
                }

                var tex = ImageMeta.CurrentTexture();

                if (tex == null)
                {
                    ImageMeta = null;
                }

                if ("Texture".edit(60, ref tex).nl(ref changed))
                {
                    ImageMeta = tex ? tex.GetTextureData() : null;
                }

                "Volume Scale".edit(70, ref size).nl(ref changed);
                size = Mathf.Max(0.0001f, size);

                if (ImageMeta == null)
                {
                    if (!TexturesPool.inst)
                    {
                        pegi.nl();
                        "Texture Width".edit(90, ref _tmpWidth).changes(ref changed);

                        if ("Create Pool".Click().nl(ref changed))
                        {
                            _tmpWidth = Mathf.ClosestPowerOfTwo(Mathf.Clamp(_tmpWidth, 128, 2048));
                            TexturesPool.Inst.width = _tmpWidth;
                        }
                    }
                    else if ("Get From Pool".Click().nl(ref changed))
                    {
                        ImageMeta = TexturesPool.inst.GetTexture2D().GetTextureData();
                    }
                }
                pegi.nl();

                "Slices:".edit("How texture will be sliced for height", 80, ref hSlices, 1, 8).nl(ref changed);

                if (changed)
                {
                    UpdateTextureName();
                }

                var w = Width;
                ("Will result in X:" + w + " Z:" + w + " Y:" + Height + "volume").nl();
            }

            if ("Materials".enter(ref inspectedElement, 2).nl_ifFoldedOut())
            {
                "Materials".edit_List_UObj(ref materials, ref inspectedMaterial);

                if (inspectedMaterial == -1 && InspectedPainter)
                {
                    var pMat = InspectedPainter.Material;
                    if (pMat != null && materials.Contains(pMat) && "Remove This Material".Click().nl(ref changed))
                    {
                        materials.Remove(pMat);
                    }
                }

                if (changed || (inspectedMaterial == -1 && "Update Materials".Click().nl(ref changed)))
                {
                    UpdateMaterials();
                }
            }

            if (inspectedElement == -1 && icon.Refresh.Click("Update Materials"))
            {
                UpdateMaterials();
            }

            pegi.nl();

            return(changed);
        }
Пример #12
0
 public RenderTexture Render(ImageMeta from, RenderTexture to) => Render(from.CurrentTexture(), to, Data.brushBufferCopy);