public static bool IsNormalMap(Texture t)
        {
            TextureUsageMode usageMode = TextureUtil.GetUsageMode(t);

            if (usageMode != TextureUsageMode.NormalmapPlain)
            {
                return(usageMode == TextureUsageMode.NormalmapDXT5nm);
            }
            return(true);
        }
        public void OnPreviewSettings(Object[] targets)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return;
            }
            GUI.enabled = true;
            InitPreview();

            bool showMode  = true;
            bool alphaOnly = true;
            //@TODO: Share some code with texture inspector???
            bool hasAlpha = false;
            int  mipCount = 8;

            foreach (Texture t2 in targets)
            {
                mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(t2));

                Cubemap cubemap = t2 as Cubemap;
                if (cubemap)
                {
                    TextureFormat format = cubemap.format;
                    if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                    {
                        alphaOnly = false;
                    }
                    if (TextureUtil.HasAlphaTextureFormat(format))
                    {
                        TextureUsageMode mode = TextureUtil.GetUsageMode(t2);
                        if (mode == TextureUsageMode.Default) // all other texture usage modes don't displayable alpha
                        {
                            hasAlpha = true;
                        }
                    }
                }
                else
                {
                    hasAlpha  = true;
                    alphaOnly = false;
                }
            }

            if (alphaOnly)
            {
                m_PreviewType = PreviewType.Alpha;
                showMode      = false;
            }
            else if (!hasAlpha)
            {
                m_PreviewType = PreviewType.RGB;
                showMode      = false;
            }

            if (showMode)
            {
                GUIContent[] kPreviewIcons = { Styles.RGBIcon, Styles.alphaIcon };
                int          index         = (int)m_PreviewType;
                if (GUILayout.Button(kPreviewIcons[index], Styles.preButton))
                {
                    m_PreviewType = (PreviewType)(++index % kPreviewIcons.Length);
                }
            }

            GUI.enabled = (mipCount != 1);
            GUILayout.Box(Styles.smallZoom, Styles.preLabel);
            GUI.changed = false;
            m_MipLevel  = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, Styles.preSlider, Styles.preSliderThumb, GUILayout.MaxWidth(64)));
            GUILayout.Box(Styles.largeZoom, Styles.preLabel);
            GUI.enabled = true;
        }
Beispiel #3
0
        public static bool IsNormalMap(Texture t)
        {
            TextureUsageMode usageMode = TextureUtil.GetUsageMode(t);

            return(usageMode == TextureUsageMode.NormalmapPlain || usageMode == TextureUsageMode.NormalmapDXT5nm);
        }
        public override void OnPreviewSettings()
        {
            if (IsCubemap())
            {
                m_CubemapPreview.OnPreviewSettings(targets);
                return;
            }

            if (IsTexture2DArray() && !SystemInfo.supports2DArrayTextures)
            {
                return;
            }

            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            // TextureInspector code is reused for RenderTexture and Cubemap inspectors.
            // Make sure we can handle the situation where target is just a Texture and
            // not a Texture2D. It's also used for large popups for mini texture fields,
            // and while it's being shown the actual texture object might disappear --
            // make sure to handle null targets.
            Texture tex       = target as Texture;
            bool    alphaOnly = false;
            bool    hasAlpha  = true;
            int     mipCount  = 1;

            if (target is Texture2D)
            {
                alphaOnly = true;
                hasAlpha  = false;
            }

            foreach (Texture t in targets)
            {
                if (t == null) // texture might have disappeared while we're showing this in a preview popup
                {
                    continue;
                }
                TextureFormat format      = 0;
                bool          checkFormat = false;
                if (t is Texture2D)
                {
                    format      = (t as Texture2D).format;
                    checkFormat = true;
                }

                if (checkFormat)
                {
                    if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                    {
                        alphaOnly = false;
                    }
                    if (TextureUtil.HasAlphaTextureFormat(format))
                    {
                        TextureUsageMode mode = TextureUtil.GetUsageMode(t);
                        if (mode == TextureUsageMode.Default) // all other texture usage modes don't displayable alpha
                        {
                            hasAlpha = true;
                        }
                    }
                }

                mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(t));
            }


            List <PreviewMode> previewCandidates = new List <PreviewMode>(5);

            previewCandidates.Add(PreviewMode.RGB);
            previewCandidates.Add(PreviewMode.R);
            previewCandidates.Add(PreviewMode.G);
            previewCandidates.Add(PreviewMode.B);
            previewCandidates.Add(PreviewMode.A);

            if (alphaOnly)
            {
                previewCandidates.Clear();
                previewCandidates.Add(PreviewMode.A);
                m_PreviewMode = PreviewMode.A;
            }
            else if (!hasAlpha)
            {
                previewCandidates.Remove(PreviewMode.A);
            }


            if (previewCandidates.Count > 1 && tex != null && !IsNormalMap(tex))
            {
                int selectedIndex = previewCandidates.IndexOf(m_PreviewMode);
                if (selectedIndex == -1)
                {
                    selectedIndex = 0;
                }

                if (previewCandidates.Contains(PreviewMode.RGB))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.RGB, s_Styles.previewButtonContents[0], s_Styles.toolbarButton)
                        ? PreviewMode.RGB
                        : m_PreviewMode;
                }
                if (previewCandidates.Contains(PreviewMode.R))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.R, s_Styles.previewButtonContents[1], s_Styles.toolbarButton)
                        ? PreviewMode.R
                        : m_PreviewMode;
                }
                if (previewCandidates.Contains(PreviewMode.G))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.G, s_Styles.previewButtonContents[2], s_Styles.toolbarButton)
                        ? PreviewMode.G
                        : m_PreviewMode;
                }
                if (previewCandidates.Contains(PreviewMode.B))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.B, s_Styles.previewButtonContents[3], s_Styles.toolbarButton)
                        ? PreviewMode.B
                        : m_PreviewMode;
                }
                if (previewCandidates.Contains(PreviewMode.A))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.A, s_Styles.previewButtonContents[4], s_Styles.toolbarButton)
                        ? PreviewMode.A
                        : m_PreviewMode;
                }
            }

            if (mipCount > 1)
            {
                GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel);
                GUI.changed = false;
                m_MipLevel  = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.MaxWidth(64)));

                //For now, we don't have mipmaps smaller than the tile size when using VT.
                if (EditorGUI.UseVTMaterial(tex))
                {
                    int numMipsOfTile = (int)Mathf.Log(VirtualTexturing.EditorHelpers.tileSize, 2) + 1;
                    m_MipLevel = Mathf.Min(m_MipLevel, Mathf.Max(mipCount - numMipsOfTile, 0));
                }

                GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel);
            }
        }
 public static extern bool IsDoubleLDRUsageMode(TextureUsageMode usageMode);
 public static extern bool IsRGBMUsageMode(TextureUsageMode usageMode);
 public static extern bool IsNormalMapUsageMode(TextureUsageMode usageMode);
Beispiel #8
0
 public static bool IsNormalmap(this TextureUsageMode _this)
 {
     return(_this == TextureUsageMode.NormalmapDXT5nm || _this == TextureUsageMode.NormalmapPlain);
 }
Beispiel #9
0
        // Native NeedsExposureControl doesn't work for RenderTextures (they are hardcoded to return kTexFormatUnknown).
        protected bool NeedsExposureControl(Texture t)
        {
            TextureUsageMode usageMode = TextureUtil.GetUsageMode(t);

            return(GraphicsFormatUtility.IsHDRFormat(t.graphicsFormat) || TextureUtil.IsRGBMUsageMode(usageMode) || TextureUtil.IsDoubleLDRUsageMode(usageMode));
        }
Beispiel #10
0
        public static bool IsNormalMap(Texture t)
        {
            TextureUsageMode mode = TextureUtil.GetUsageMode(t);

            return(TextureUtil.IsNormalMapUsageMode(mode));
        }
Beispiel #11
0
        public override string GetInfoString()
        {
            // TextureInspector code is reused for RenderTexture and Cubemap inspectors.
            // Make sure we can handle the situation where target is just a Texture and
            // not a Texture2D.
            Texture         t  = target as Texture;
            Texture2D       t2 = target as Texture2D;
            TextureImporter textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(t)) as TextureImporter;
            string          info            = t.width + "x" + t.height;

            bool           showSize              = true;
            bool           isPackedSprite        = textureImporter && textureImporter.qualifiesForSpritePacking;
            bool           isNormalmap           = IsNormalMap(t);
            bool           stillNeedsCompression = textureImporter && textureImporter.textureStillNeedsToBeCompressed;
            bool           isNPOT = t2 != null && TextureUtil.IsNonPowerOfTwo(t2);
            GraphicsFormat format = t.graphicsFormat;

            showSize = !stillNeedsCompression;
            if (isNPOT)
            {
                info += " (NPOT)";
            }
            if (stillNeedsCompression)
            {
                info += " (Not yet compressed)";
            }
            else
            {
                if (isNormalmap)
                {
                    switch (format)
                    {
                    case GraphicsFormat.RGBA_DXT5_SRGB:
                    case GraphicsFormat.RGBA_DXT5_UNorm:
                        info += "  DXTnm";
                        break;

                    case GraphicsFormat.R8G8B8A8_SRGB:
                    case GraphicsFormat.R8G8B8A8_UNorm:
                    case GraphicsFormat.B8G8R8A8_SRGB:
                    case GraphicsFormat.B8G8R8A8_UNorm:
                        info += "  Nm 32 bit";
                        break;

                    case GraphicsFormat.R4G4B4A4_UNormPack16:
                    case GraphicsFormat.B4G4R4A4_UNormPack16:
                        info += "  Nm 16 bit";
                        break;

                    default:
                        info += "  " + GraphicsFormatUtility.GetFormatString(format);
                        break;
                    }
                }
                else if (isPackedSprite)
                {
                    TextureFormat desiredFormat;
                    ColorSpace    dummyColorSpace;
                    int           dummyComressionQuality;
                    textureImporter.ReadTextureImportInstructions(EditorUserBuildSettings.activeBuildTarget, out desiredFormat, out dummyColorSpace, out dummyComressionQuality);

                    info += "\n " + GraphicsFormatUtility.GetFormatString(format) + "(Original) " + GraphicsFormatUtility.GetFormatString(desiredFormat) + "(Atlas)";
                }
                else
                {
                    info += "  " + GraphicsFormatUtility.GetFormatString(format);
                }
            }

            if (showSize)
            {
                info += "\n" + EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySizeLong(t));
            }

            TextureUsageMode mode = TextureUtil.GetUsageMode(t);

            if (mode == TextureUsageMode.AlwaysPadded)
            {
                var glWidth  = TextureUtil.GetGPUWidth(t);
                var glHeight = TextureUtil.GetGPUHeight(t);
                if (t.width != glWidth || t.height != glHeight)
                {
                    info += UnityString.Format("\nPadded to {0}x{1}", glWidth, glHeight);
                }
            }
            else if (TextureUtil.IsRGBMUsageMode(mode))
            {
                info += "\nRGBM encoded";
            }
            else if (TextureUtil.IsDoubleLDRUsageMode(mode))
            {
                info += "\ndLDR encoded";
            }

            return(info);
        }
Beispiel #12
0
        public override void OnPreviewSettings()
        {
            if (IsCubemap())
            {
                //TODO perhaps support custom cubemap settings. Not currently!
                defaultEditor.OnPreviewSettings();
                return;
            }

            // TextureInspector code is reused for RenderTexture and Cubemap inspectors.
            // Make sure we can handle the situation where target is just a Texture and
            // not a Texture2D. It's also used for large popups for mini texture fields,
            // and while it's being shown the actual texture object might disappear --
            // make sure to handle null targets.
            Texture tex = target as Texture;

            if (tex == null)
            {
                return;
            }

            bool showMode  = true;
            bool alphaOnly = false;
            bool hasAlpha  = true;
            int  mipCount  = 1;

            if (target is Texture2D)
            {
                alphaOnly = true;
                hasAlpha  = false;
            }

            bool hasR = false, hasG = false, hasB = false;

            // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
            foreach (Texture t in targets)
            {
                if (t == null)                 // texture might have disappeared while we're showing this in a preview popup
                {
                    continue;
                }

                TextureFormat format      = 0;
                bool          checkFormat = false;
                if (t is Texture2D)
                {
                    format      = (t as Texture2D).format;
                    checkFormat = true;
                }

                if (checkFormat)
                {
                    if (!IsAlphaOnlyTextureFormat(format))
                    {
                        alphaOnly = false;
                    }
                    if (HasAlphaTextureFormat(format))
                    {
                        TextureUsageMode mode = GetUsageMode(t);
                        if (mode == TextureUsageMode.Default)                         // all other texture usage modes don't displayable alpha
                        {
                            hasAlpha = true;
                        }
                    }
                    bool _hasR, _hasG, _hasB;
                    CheckRGBFormats(format, out _hasR, out _hasG, out _hasB);
                    hasR = hasR || _hasR;
                    hasG = hasG || _hasG;
                    hasB = hasB || _hasB;
                }

                mipCount = Mathf.Max(mipCount, GetMipmapCount(t));

                if (!checkFormat)
                {
                    if (t is RenderTexture)
                    {
                        RenderTextureFormat renderTextureFormat = (t as RenderTexture).format;
                        bool _hasR, _hasG, _hasB;
                        CheckRGBFormats(renderTextureFormat, out _hasR, out _hasG, out _hasB);
                        hasR = hasR || _hasR;
                        hasG = hasG || _hasG;
                        hasB = hasB || _hasB;
                    }
                    else
                    {
                        //If we cannot validate whether the texture has RGB, lets assume it does by default.
                        hasR = true;
                        hasG = true;
                        hasB = true;
                    }
                }
            }

//			if (GUILayout.Button("PreviewColor2D.shader"))
//			{
//
//				Shader previewShader = (Shader)EditorGUIUtility.LoadRequired("Previews/PreviewColor2D.shader");
//				Selection.activeObject = previewShader;
//			}

            if (GUILayout.Button(s_Styles.scaleIcon, s_Styles.previewButton))
            {
                //Switch between the default % zoom, and 100% zoom
                float p100 = 1 / zoomLevel;
                if (Math.Abs(zoomMultiplier - p100) > 0.001f)
                {
                    int     texWidth      = Mathf.Max(tex.width, 1);
                    int     texHeight     = Mathf.Max(tex.height, 1);
                    Vector2 posNormalized = new Vector2(m_Pos.x / (texWidth * zoomLevel * zoomMultiplier), m_Pos.y / (texHeight * zoomLevel * zoomMultiplier));
                    //Zooms to 100
                    zoomMultiplier = p100;

                    //Focuses Center
                    Vector2 newPos = new Vector2(posNormalized.x * (texWidth * zoomLevel * zoomMultiplier), posNormalized.y * (texHeight * zoomLevel * zoomMultiplier));
                    m_Pos = newPos;
                }
                else
                {
                    //Zooms to default
                    zoomMultiplier = 1;
                    m_Pos          = Vector2.zero;
                }

                Repaint();
            }

            if (!alphaOnly)
            {
                DrawRGBToggles(hasR, hasG, hasB);
            }

            if (alphaOnly)
            {
                m_ShowAlpha = true;
                showMode    = false;
            }
            else if (!hasAlpha)
            {
                m_ShowAlpha = false;
                showMode    = false;
            }

            if (showMode && !IsNormalMap(tex))
            {
                m_ShowAlpha = GUILayout.Toggle(m_ShowAlpha, m_ShowAlpha ? s_Styles.alphaIcon : s_Styles.RGBIcon, s_Styles.previewButton);
            }

            if (mipCount > 1)
            {
                GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel);
                GUI.changed = false;
                using (EditorGUI.ChangeCheckScope changeCheckScope = new EditorGUI.ChangeCheckScope())
                {
                    m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.MaxWidth(64)));
                    if (changeCheckScope.changed)
                    {
                        rGBAMaterial.SetFloat("_Mip", m_MipLevel);
                        rGBATransparentMaterial.SetFloat("_Mip", m_MipLevel);
                        Repaint();
                    }
                }

                GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel);
            }
        }
Beispiel #13
0
        private static bool IsNormalMap(Texture t)
        {
            TextureUsageMode mode = GetUsageMode(t);

            return(mode == TextureUsageMode.NormalmapPlain || mode == TextureUsageMode.NormalmapDXT5nm);
        }
        public override void OnPreviewSettings()
        {
            if (IsCubemap())
            {
                m_CubemapPreview.OnPreviewSettings(targets);
                return;
            }


            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }


            // TextureInspector code is reused for RenderTexture and Cubemap inspectors.
            // Make sure we can handle the situation where target is just a Texture and
            // not a Texture2D. It's also used for large popups for mini texture fields,
            // and while it's being shown the actual texture object might disappear --
            // make sure to handle null targets.
            Texture tex       = target as Texture;
            bool    showMode  = true;
            bool    alphaOnly = false;
            bool    hasAlpha  = true;
            int     mipCount  = 1;

            if (target is Texture2D)
            {
                alphaOnly = true;
                hasAlpha  = false;
            }

            foreach (Texture t in targets)
            {
                if (t == null) // texture might have disappeared while we're showing this in a preview popup
                {
                    continue;
                }
                TextureFormat format      = 0;
                bool          checkFormat = false;
                if (t is Texture2D)
                {
                    format      = (t as Texture2D).format;
                    checkFormat = true;
                }

                if (checkFormat)
                {
                    if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                    {
                        alphaOnly = false;
                    }
                    if (TextureUtil.HasAlphaTextureFormat(format))
                    {
                        TextureUsageMode mode = TextureUtil.GetUsageMode(t);
                        if (mode == TextureUsageMode.Default) // all other texture usage modes don't displayable alpha
                        {
                            hasAlpha = true;
                        }
                    }
                }

                mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(t));
            }

            if (alphaOnly)
            {
                m_ShowAlpha = true;
                showMode    = false;
            }
            else if (!hasAlpha)
            {
                m_ShowAlpha = false;
                showMode    = false;
            }

            if (showMode && tex != null && !IsNormalMap(tex))
            {
                m_ShowAlpha = GUILayout.Toggle(m_ShowAlpha, m_ShowAlpha ? s_Styles.alphaIcon : s_Styles.RGBIcon, s_Styles.previewButton);
            }

            if (mipCount > 1)
            {
                GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel);
                GUI.changed = false;
                m_MipLevel  = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.MaxWidth(64)));
                GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel);
            }
        }