GetLinearSampled() private méthode

private GetLinearSampled ( Texture t ) : bool
t UnityEngine.Texture
Résultat bool
 public static UnityEngine.Texture2D CreateTemporaryDuplicate(UnityEngine.Texture2D original, int width, int height)
 {
     UnityEngine.Texture2D result;
     if (!ShaderUtil.hardwareSupportsRectRenderTexture || !original)
     {
         result = null;
     }
     else
     {
         RenderTexture active          = RenderTexture.active;
         Rect          rawViewportRect = ShaderUtil.rawViewportRect;
         bool          flag            = !TextureUtil.GetLinearSampled(original);
         RenderTexture temporary       = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, (!flag) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB);
         GL.sRGBWrite = (flag && QualitySettings.activeColorSpace == ColorSpace.Linear);
         Graphics.Blit(original, temporary);
         GL.sRGBWrite         = false;
         RenderTexture.active = temporary;
         bool flag2 = width >= SystemInfo.maxTextureSize || height >= SystemInfo.maxTextureSize;
         UnityEngine.Texture2D texture2D = new UnityEngine.Texture2D(width, height, TextureFormat.RGBA32, original.mipmapCount > 1 || flag2);
         texture2D.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
         texture2D.Apply();
         RenderTexture.ReleaseTemporary(temporary);
         EditorGUIUtility.SetRenderTextureNoViewport(active);
         ShaderUtil.rawViewportRect    = rawViewportRect;
         texture2D.alphaIsTransparency = original.alphaIsTransparency;
         result = texture2D;
     }
     return(result);
 }
Exemple #2
0
        public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height)
        {
            Texture2D textured;

            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return(null);
            }
            Texture target = this.target as Texture;

            if (this.IsCubemap())
            {
                return(this.m_CubemapPreview.RenderStaticPreview(target, width, height));
            }
            PreviewHelpers.AdjustWidthAndHeightForStaticPreview(target.width, target.height, ref width, ref height);
            EditorUtility.SetTemporarilyAllowIndieRenderTexture(true);
            RenderTexture active                    = RenderTexture.active;
            Rect          rawViewportRect           = ShaderUtil.rawViewportRect;
            bool          flag                      = !TextureUtil.GetLinearSampled(target);
            RenderTexture dest                      = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, !flag ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB);
            Material      materialForSpecialTexture = EditorGUI.GetMaterialForSpecialTexture(target);

            GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
            if (materialForSpecialTexture != null)
            {
                if (Unsupported.IsDeveloperBuild())
                {
                    materialForSpecialTexture = new Material(materialForSpecialTexture);
                }
                Graphics.Blit(target, dest, materialForSpecialTexture);
            }
            else
            {
                Graphics.Blit(target, dest);
            }
            GL.sRGBWrite         = false;
            RenderTexture.active = dest;
            Texture2D textured2 = this.target as Texture2D;

            if ((textured2 != null) && textured2.alphaIsTransparency)
            {
                textured = new Texture2D(width, height, TextureFormat.ARGB32, false);
            }
            else
            {
                textured = new Texture2D(width, height, TextureFormat.RGB24, false);
            }
            textured.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
            textured.Apply();
            RenderTexture.ReleaseTemporary(dest);
            EditorGUIUtility.SetRenderTextureNoViewport(active);
            ShaderUtil.rawViewportRect = rawViewportRect;
            EditorUtility.SetTemporarilyAllowIndieRenderTexture(false);
            if ((materialForSpecialTexture != null) && Unsupported.IsDeveloperBuild())
            {
                UnityEngine.Object.DestroyImmediate(materialForSpecialTexture);
            }
            return(textured);
        }
        public override void OnInspectorGUI()
        {
            if (this.m_Images == null)
            {
                this.InitTexturesFromCubemap();
            }
            EditorGUIUtility.labelWidth = 50f;
            Cubemap cubemap = this.target as Cubemap;

            if (cubemap == null)
            {
                return;
            }
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.ShowFace("Right\n(+X)", CubemapFace.PositiveX);
            this.ShowFace("Left\n(-X)", CubemapFace.NegativeX);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.ShowFace("Top\n(+Y)", CubemapFace.PositiveY);
            this.ShowFace("Bottom\n(-Y)", CubemapFace.NegativeY);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.ShowFace("Front\n(+Z)", CubemapFace.PositiveZ);
            this.ShowFace("Back\n(-Z)", CubemapFace.NegativeZ);
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            EditorGUIUtility.labelWidth = 0f;
            EditorGUILayout.Space();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.HelpBox("Lowering face size is a destructive operation, you might need to re-assign the textures later to fix resolution issues. It's preferable to use Cubemap texture import type instead of Legacy Cubemap assets.", MessageType.Warning);
            int num = TextureUtil.GetGLWidth(cubemap);

            num = EditorGUILayout.IntPopup("Face size", num, CubemapInspector.kSizes, CubemapInspector.kSizesValues, new GUILayoutOption[0]);
            int  num2      = TextureUtil.CountMipmaps(cubemap);
            bool useMipmap = EditorGUILayout.Toggle("MipMaps", num2 > 1, new GUILayoutOption[0]);
            bool flag      = TextureUtil.GetLinearSampled(cubemap);

            flag = EditorGUILayout.Toggle("Linear", flag, new GUILayoutOption[0]);
            bool flag2 = TextureUtil.IsCubemapReadable(cubemap);

            flag2 = EditorGUILayout.Toggle("Readable", flag2, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                if (TextureUtil.ReformatCubemap(ref cubemap, num, num, cubemap.format, useMipmap, flag))
                {
                    this.InitTexturesFromCubemap();
                }
                TextureUtil.MarkCubemapReadable(cubemap, flag2);
                cubemap.Apply();
            }
        }
Exemple #4
0
        public override void OnInspectorGUI()
        {
            if (this.m_Images == null)
            {
                this.InitTexturesFromCubemap();
            }
            EditorGUIUtility.labelWidth = 50f;
            Cubemap cubemap = this.target as Cubemap;

            if (cubemap == null)
            {
                return;
            }
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.ShowFace("Right\n(+X)", CubemapFace.PositiveX);
            this.ShowFace("Left\n(-X)", CubemapFace.NegativeX);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.ShowFace("Top\n(+Y)", CubemapFace.PositiveY);
            this.ShowFace("Bottom\n(-Y)", CubemapFace.NegativeY);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.ShowFace("Front\n(+Z)", CubemapFace.PositiveZ);
            this.ShowFace("Back\n(-Z)", CubemapFace.NegativeZ);
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            EditorGUIUtility.labelWidth = 0f;
            EditorGUILayout.Space();
            EditorGUI.BeginChangeCheck();
            int num = TextureUtil.GetGLWidth(cubemap);

            num = EditorGUILayout.IntPopup("Face size", num, CubemapInspector.kSizes, CubemapInspector.kSizesValues, new GUILayoutOption[0]);
            int  num2      = TextureUtil.CountMipmaps(cubemap);
            bool useMipmap = EditorGUILayout.Toggle("MipMaps", num2 > 1, new GUILayoutOption[0]);
            bool flag      = TextureUtil.GetLinearSampled(cubemap);

            flag = EditorGUILayout.Toggle("Linear", flag, new GUILayoutOption[0]);
            bool flag2 = TextureUtil.IsCubemapReadable(cubemap);

            flag2 = EditorGUILayout.Toggle("Readable", flag2, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                if (TextureUtil.ReformatCubemap(ref cubemap, num, num, cubemap.format, useMipmap, flag))
                {
                    this.InitTexturesFromCubemap();
                }
                TextureUtil.MarkCubemapReadable(cubemap, flag2);
                cubemap.Apply();
            }
        }
        public override void OnInspectorGUI()
        {
            if (this.m_Images == null)
            {
                this.InitTexturesFromCubemap();
            }
            EditorGUIUtility.labelWidth = 50f;
            Cubemap target = base.target as Cubemap;

            if (target != null)
            {
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                this.ShowFace("Right\n(+X)", CubemapFace.PositiveX);
                this.ShowFace("Left\n(-X)", CubemapFace.NegativeX);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                this.ShowFace("Top\n(+Y)", CubemapFace.PositiveY);
                this.ShowFace("Bottom\n(-Y)", CubemapFace.NegativeY);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                this.ShowFace("Front\n(+Z)", CubemapFace.PositiveZ);
                this.ShowFace("Back\n(-Z)", CubemapFace.NegativeZ);
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
                EditorGUIUtility.labelWidth = 0f;
                EditorGUILayout.Space();
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.HelpBox("Lowering face size is a destructive operation, you might need to re-assign the textures later to fix resolution issues. It's preferable to use Cubemap texture import type instead of Legacy Cubemap assets.", MessageType.Warning);
                int gPUWidth = TextureUtil.GetGPUWidth(target);
                gPUWidth = EditorGUILayout.IntPopup("Face size", gPUWidth, kSizes, kSizesValues, new GUILayoutOption[0]);
                int  mipmapCount   = TextureUtil.GetMipmapCount(target);
                bool useMipmap     = EditorGUILayout.Toggle("MipMaps", mipmapCount > 1, new GUILayoutOption[0]);
                bool linearSampled = TextureUtil.GetLinearSampled(target);
                linearSampled = EditorGUILayout.Toggle("Linear", linearSampled, new GUILayoutOption[0]);
                bool flag3 = TextureUtil.IsCubemapReadable(target);
                flag3 = EditorGUILayout.Toggle("Readable", flag3, new GUILayoutOption[0]);
                if (EditorGUI.EndChangeCheck())
                {
                    if (TextureUtil.ReformatCubemap(ref target, gPUWidth, gPUWidth, target.format, useMipmap, linearSampled))
                    {
                        this.InitTexturesFromCubemap();
                    }
                    TextureUtil.MarkCubemapReadable(target, flag3);
                    target.Apply();
                }
            }
        }