public override bool UpdateTilingFromMaterial(ShaderProperty.TextureValue fieldName, PlaytimePainter painter)
        {
            if (!painter.terrain)
            {
                return(false);
            }

            if (!fieldName.HasUsageTag(PainterDataAndConfig.TERRAIN_SPLAT_DIFFUSE))
            {
                return(false);
            }

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

            var ls = painter.terrain.terrainData.terrainLayers;


            if (ls.Length <= no)
            {
                return(true);
            }

            var l = ls.TryGet(no);

            var terrainData = painter.terrain.terrainData;
            var width       = terrainData.size.x / l.tileSize.x;
            var length      = terrainData.size.z / l.tileSize.y;

            var id = painter.TexMeta;

            id.tiling = new Vector2(width, length);
            id.offset = l.tileOffset;

            return(true);
        }
Example #2
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);
        }
Example #3
0
        public void ChangeBufferTarget(ImageMeta newTarget, MaterialMeta mat, ShaderProperty.TextureValue parameter, PlaytimePainter painter)
        {
            if (newTarget != imgMetaUsingRendTex)
            {
                if (materialsUsingRenderTexture.Count > 0)
                {
                    PlaytimePainter.SetOriginalShader();
                }

                if (imgMetaUsingRendTex != null)
                {
                    if (imgMetaUsingRendTex.texture2D)
                    {
                        imgMetaUsingRendTex.RenderTexture_To_Texture2D();
                    }

                    imgMetaUsingRendTex.destination = TexTarget.Texture2D;

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

                materialsUsingRenderTexture.Clear();
                autodisabledBufferTarget = null;
                imgMetaUsingRendTex      = newTarget;
            }

            mat.bufferParameterTarget = parameter;
            mat.painterTarget         = painter;
            materialsUsingRenderTexture.Add(mat);
        }
Example #4
0
 public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex, PlaytimePainter painter)
 {
     if (!painter.terrain || !field.HasUsageTag(PainterDataAndConfig.TERRAIN_CONTROL_TEXTURE))
     {
         return(false);
     }
     tex = painter.terrain.terrainData.alphamapTextures[field.NameForDisplayPEGI[0].CharToInt()];
     return(true);
 }
 public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex)
 {
     if (!CorrectField(field, painter))
     {
         return(false);
     }
     tex = painter.terrainHeightTexture;
     return(true);
 }
Example #6
0
        public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex)
        {
            if (!painter.terrain || !field.Equals(PainterShaderVariables.TerrainLight))
            {
                return(false);
            }

            tex = mergingTerrain.lightTexture;
            return(true);
        }
Example #7
0
        public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex, PlaytimePainter painter)
        {
            if (!painter.terrain || !field.Equals(PainterDataAndConfig.TerrainLight))
            {
                return(false);
            }

            tex = mergingTerrain.lightTexture;
            return(true);
        }
Example #8
0
            public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex)
            {
                if (volumeTexture && field.Equals(volumeTexture.TextureInShaderProperty))
                {
                    tex = volumeTexture.Texture;
                    return(true);
                }

                return(false);
            }
Example #9
0
        public static bool IsGlobalVolume(this ShaderProperty.TextureValue field)
        {
            string name = field.NameForDisplayPEGI;

            if (name.Contains(PainterDataAndConfig.GlobalPropertyPrefix) &&
                name.Contains(VolumePaintingModule.VolumeTextureTag))
            {
                return(true);
            }
            return(false);
        }
 public void AddTargets(FieldAtlas at, ShaderProperty.TextureValue target)
 {
     if (!atlasFields.Contains(at.atlasedField))
     {
         atlasFields.Add(at.atlasedField);
     }
     if (!targetFields.Contains(target))
     {
         targetFields.Add(target);
     }
 }
        public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex)
        {
            var sp = GetSprite(field);

            if (!sp)
            {
                return(false);
            }

            tex = sp.texture;

            return(true);
        }
Example #12
0
        public static VolumeTexture GetGlobal(ShaderProperty.TextureValue propertyName)
        {
            foreach (var v in currentlyActiveVolumes)
            {
                var val = v.Value;
                if (val && val.MaterialPropertyNameGlobal.Equals(propertyName))
                {
                    return(val);
                }
            }

            return(null);
        }
Example #13
0
            public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta id)
            {
                if (!volumeTexture)
                {
                    return(false);
                }

                if (field.ToString() == volumeTexture.name)
                {
                    volumeTexture.ImageMeta = id;
                    return(true);
                }

                return(false);
            }
Example #14
0
        public override bool UpdateTilingFromMaterial(ShaderProperty.TextureValue fieldName, PlaytimePainter painter)
        {
            if (!fieldName.IsGlobalVolume())
            {
                return(false);
            }
            var id = painter.ImgMeta;

            if (id == null)
            {
                return(true);
            }
            id.tiling = Vector2.one;
            id.offset = Vector2.zero;
            return(true);
        }
Example #15
0
        private void OnEnable()
        {
            if (!Application.isPlaying)
            {
                Refresh();
            }

            if (Application.isPlaying && originalTexture && texture && (texture.GetType() == typeof(RenderTexture)))
            {
                RenderTextureBuffersManager.Blit(originalTexture, (RenderTexture)texture);
            }

            if (Material && !Material.Has(TextureId))
            {
                _textureProperty = null;
            }
        }
Example #16
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);
        }
Example #17
0
        public static bool edit(this Material mat, ShaderProperty.TextureValue property, string name = null)
        {
            var val = mat.Get(property);

            if (name.IsNullOrEmpty())
            {
                name = property.NameForDisplayPEGI;
            }

            if (name.edit(name.Length * letterSizeInPixels, ref val))
            {
                mat.Set(property, val);
                return(true);
            }

            return(false);
        }
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta id)
        {
            if (!CorrectField(field, painter))
            {
                return(false);
            }

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

            var tex = id.CurrentTexture();

            PainterShaderVariables.TerrainHeight.GlobalValue = tex;
            return(true);
        }
        public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex, PlaytimePainter painter)
        {
            if (!painter.terrain || (!field.HasUsageTag(PainterDataAndConfig.TERRAIN_SPLAT_DIFFUSE)))
            {
                return(false);
            }
            var no = field.NameForDisplayPEGI()[0].CharToInt();

            var l = painter.terrain.terrainData.terrainLayers;

            if (l.Length > no)
            {
                tex = l[no].diffuseTexture;
            }

            return(true);
        }
Example #20
0
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, ImageMeta id, PlaytimePainter painter)
        {
            if (!field.IsGlobalVolume())
            {
                return(false);
            }

            var gl = VolumeTexture.GetGlobal(field);

            if (gl != null)
            {
                gl.ImageMeta = id;
                gl.UpdateMaterials();
            }

            return(true);
        }
        public override bool UpdateTilingFromMaterial(ShaderProperty.TextureValue field)
        {
            if (!CorrectField(field, painter))
            {
                return(false);
            }

            var id = painter.TexMeta;

            if (id == null)
            {
                return(true);
            }
            id.tiling = Vector2.one;
            id.offset = Vector2.zero;
            return(true);
        }
Example #22
0
            public override bool UpdateTilingFromMaterial(ShaderProperty.TextureValue fieldName)
            {
                if (!volumeTexture)
                {
                    return(false);
                }

                var id = painter.TexMeta;

                if (id == null || !id.isAVolumeTexture)
                {
                    return(false);
                }
                id.tiling = Vector2.one;
                id.offset = Vector2.zero;
                return(true);
            }
        public override bool UpdateTilingFromMaterial(ShaderProperty.TextureValue fieldName)
        {
            if (!painter.terrain)
            {
                return(false);
            }

            if (!fieldName.HasUsageTag(PainterShaderVariables.TERRAIN_SPLAT_DIFFUSE))
            {
                return(false);
            }

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

            var id = painter.TexMeta;

            var terrainData = painter.terrain.terrainData;

#if UNITY_2019_1_OR_NEWER
            var ls = painter.terrain.terrainData.terrainLayers;


            if (ls.Length <= no)
            {
                return(true);
            }

            var l = ls.TryGet(no);
#else
            var l = parentComponent.terrain.terrainData.splatPrototypes.TryGet(no);
            if (l == null)
            {
                return(true);
            }
#endif

            var width  = terrainData.size.x / l.tileSize.x;
            var length = terrainData.size.z / l.tileSize.y;


            id.tiling = new Vector2(width, length);
            id.offset = l.tileOffset;

            return(true);
        }
Example #24
0
        public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex)
        {
            if (!field.Equals(textureName))
            {
                return(false);
            }

            var tmp = GetTexture();

            if (!tmp)
            {
                return(false);
            }

            tex = tmp;

            return(true);
        }
Example #25
0
        public override bool UpdateTilingFromMaterial(ShaderProperty.TextureValue fieldName, PlaytimePainter painter)
        {
            if (!painter.terrain || fieldName == null ||
                !fieldName.Equals(PainterDataAndConfig.TerrainLight))
            {
                return(false);
            }

            var id = painter.TexMeta;

            if (id == null)
            {
                return(true);
            }
            id.tiling = Vector2.one;
            id.offset = Vector2.zero;
            return(true);
        }
Example #26
0
        public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex, PlaytimePainter painter)
        {
            if (!field.IsGlobalVolume())
            {
                return(false);
            }

            var gl = VolumeTexture.GetGlobal(field);

            if (gl != null)
            {
                tex = gl.ImageMeta.CurrentTexture();
            }
            else
            {
                tex = null;
            }

            return(true);
        }
        public override bool GetTexture(ShaderProperty.TextureValue field, ref Texture tex)
        {
            if (!painter.terrain || (!field.HasUsageTag(PainterShaderVariables.TERRAIN_SPLAT_DIFFUSE)))
            {
                return(false);
            }
            var no = field.NameForDisplayPEGI()[0].CharToInt();

#if UNITY_2019_1_OR_NEWER
            var l = painter.terrain.terrainData.terrainLayers;

            if (l.Length > no)
            {
                tex = l[no].diffuseTexture;
            }
#else
            tex = parentComponent.terrain.GetSplashPrototypeTexture(no);
#endif

            return(true);
        }
Example #28
0
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta 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);
        }
Example #29
0
        public void ChangeDestination(TexTarget changeTo, MaterialMeta mat, ShaderProperty.TextureValue parameter, PlaytimePainter painter)
        {
            if (changeTo != destination)
            {
                if (changeTo == TexTarget.RenderTexture)
                {
                    if (!renderTexture)
                    {
                        PainterCamera.Inst.ChangeBufferTarget(this, mat, parameter, painter);
                    }
                    TextureToRenderTexture(texture2D);
                }
                else
                {
                    if (!texture2D)
                    {
                        return;
                    }

                    if (!renderTexture)
                    {
                        PainterCamera.Inst.EmptyBufferTarget();
                        PainterCamera.Inst.DiscardAlphaBuffer();
                    }
                    else if (painter.initialized && !painter.isBeingDisabled)
                    {
                        // To avoid Clear to black when exiting playmode
                        RenderTexture_To_Texture2D();
                        Debug.Log("Is being switched to Tex2D");
                    }
                }
                destination = changeTo;
                painter.SetTextureOnMaterial(this);
            }
            else
            {
                Debug.Log("Destination already Set");
            }
        }
Example #30
0
        public override bool UpdateTilingFromMaterial(ShaderProperty.TextureValue fieldName, PlaytimePainter painter)
        {
            if (!painter.terrain)
            {
                return(false);
            }
            if (!fieldName.HasUsageTag(PainterDataAndConfig.TERRAIN_CONTROL_TEXTURE))
            {
                return(false);
            }
            var id = painter.ImgMeta;

            if (id == null)
            {
                return(true);
            }

            id.tiling = Vector2.one;
            id.offset = Vector2.zero;

            return(true);
        }