IsNormalMap() public static method

public static IsNormalMap ( Texture t ) : bool
t UnityEngine.Texture
return bool
示例#1
0
        private void RenderCubemap(Texture t, Vector2 previewDir, float previewDistance, float exposure)
        {
            m_PreviewUtility.camera.transform.position = -Vector3.forward * previewDistance;
            m_PreviewUtility.camera.transform.rotation = Quaternion.identity;
            Quaternion rot = Quaternion.Euler(previewDir.y, 0, 0) * Quaternion.Euler(0, previewDir.x, 0);

            m_Material.mainTexture = t;

            m_Material.SetMatrix(s_ShaderCubemapRotation, Matrix4x4.TRS(Vector3.zero, rot, Vector3.one));

            // -1 indicates "use regular sampling"; mips 0 and larger sample only that mip level for preview
            float mipLevel = GetMipLevelForRendering(t);

            m_Material.SetFloat(s_ShaderMip, mipLevel);
            m_Material.SetFloat(s_ShaderAlpha, (m_PreviewType == PreviewType.Alpha) ? 1.0f : 0.0f);
            m_Material.SetFloat(s_ShaderIntensity, m_Intensity);
            m_Material.SetFloat(s_ShaderIsNormalMap, TextureInspector.IsNormalMap(t) ? 1.0f : 0.0f);
            m_Material.SetFloat(s_ShaderExposure, exposure);

            if (PlayerSettings.colorSpace == ColorSpace.Linear)
            {
                m_Material.SetInt("_ColorspaceIsGamma", 0);
            }
            else
            {
                m_Material.SetInt("_ColorspaceIsGamma", 1);
            }

            m_PreviewUtility.DrawMesh(m_Mesh, Vector3.zero, rot, m_Material, 0);
            m_PreviewUtility.Render();
        }
        public void OnPreviewGUI(Texture t, Rect r, GUIStyle background, float exposure, TextureInspector.PreviewMode previewMode, float mipLevel)
        {
            if (t == null)
            {
                return;
            }

            if (!SystemInfo.supports2DArrayTextures)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "2D texture array preview not supported");
                return;
            }

            InitPreviewMaterialIfNeeded();
            m_Material.mainTexture = t;

            int effectiveSlice = GetEffectiveSlice(t);

            m_Material.SetFloat(s_ShaderSliceIndex, (float)effectiveSlice);
            m_Material.SetFloat(s_ShaderToSrgb, QualitySettings.activeColorSpace == ColorSpace.Linear ? 1.0f : 0.0f);
            m_Material.SetFloat(s_ShaderIsNormalMap, TextureInspector.IsNormalMap(t) ? 1.0f : 0.0f);

            SetShaderColorMask(previewMode);

            int texWidth  = Mathf.Max(t.width, 1);
            int texHeight = Mathf.Max(t.height, 1);

            float effectiveMipLevel = GetMipLevelForRendering(t, mipLevel);
            float zoomLevel         = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
            Rect  wantedRect        = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);

            PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar",
                                       "PreHorizontalScrollbarThumb");
            FilterMode oldFilter = t.filterMode;

            TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point);

            EditorGUI.DrawPreviewTexture(wantedRect, t, m_Material, ScaleMode.StretchToFill, 0, effectiveMipLevel, UnityEngine.Rendering.ColorWriteMask.All, exposure);

            TextureUtil.SetFilterModeNoDirty(t, oldFilter);

            m_Pos = PreviewGUI.EndScrollView();
            if (effectiveSlice != 0 || (int)effectiveMipLevel != 0)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 30),
                                          "Slice " + effectiveSlice + "\nMip " + effectiveMipLevel);
            }
        }
        public Texture2D RenderStaticPreview(Texture target, string assetPath, Object[] subAssets, int width, int height)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture || !SystemInfo.supports2DArrayTextures)
            {
                return(null);
            }

            var texture = target as Texture2DArray;

            if (texture == null)
            {
                return(null);
            }

            var previewUtility = new PreviewRenderUtility();

            previewUtility.BeginStaticPreview(new Rect(0, 0, width, height));

            InitPreviewMaterialIfNeeded();
            m_Material.mainTexture = texture;
            m_Material.SetFloat(s_ShaderColorMask, 15.0f);
            m_Material.SetFloat(s_ShaderMip, 0);
            m_Material.SetFloat(s_ShaderToSrgb, 0.0f);
            m_Material.SetFloat(s_ShaderIsNormalMap, TextureInspector.IsNormalMap(texture) ? 1.0f : 0.0f);

            int  sliceDistance = previewUtility.renderTexture.width / 12;
            var  elementCount = Mathf.Min(texture.depth, 6);
            Rect screenRect = new Rect(), sourceRect = new Rect();
            var  subRect = new Rect(0, 0, previewUtility.renderTexture.width - sliceDistance * (elementCount - 1), previewUtility.renderTexture.height - sliceDistance * (elementCount - 1));

            for (var el = elementCount - 1; el >= 0; --el)
            {
                m_Material.SetFloat(s_ShaderSliceIndex, (float)el);

                subRect.x = sliceDistance * el;
                subRect.y = previewUtility.renderTexture.height - subRect.height - sliceDistance * el;

                var aspect = texture.width / (float)texture.height;
                GUI.CalculateScaledTextureRects(subRect, ScaleMode.ScaleToFit, aspect, ref screenRect, ref sourceRect);
                Graphics.DrawTexture(screenRect, texture, sourceRect, 0, 0, 0, 0, Color.white, m_Material);
            }

            var res = previewUtility.EndStaticPreview();

            previewUtility.Cleanup();
            return(res);
        }
示例#4
0
        private void RenderCubemap(Texture t, Vector2 previewDir, float previewDistance)
        {
            m_PreviewUtility.camera.transform.position = -Vector3.forward * previewDistance;
            m_PreviewUtility.camera.transform.rotation = Quaternion.identity;
            Quaternion rot = Quaternion.Euler(previewDir.y, 0, 0) * Quaternion.Euler(0, previewDir.x, 0);

            var mat = EditorGUIUtility.LoadRequired("Previews/PreviewCubemapMaterial.mat") as Material;

            mat.mainTexture = t;

            mat.SetMatrix(s_ShaderCubemapRotation, Matrix4x4.TRS(Vector3.zero, rot, Vector3.one));

            // -1 indicates "use regular sampling"; mips 0 and larger sample only that mip level for preview
            float mipLevel = GetMipLevelForRendering(t);

            mat.SetFloat(s_ShaderMip, mipLevel);
            mat.SetFloat(s_ShaderAlpha, (m_PreviewType == PreviewType.Alpha) ? 1.0f : 0.0f);
            mat.SetFloat(s_ShaderIntensity, m_Intensity);
            mat.SetInt(s_ShaderIsNormalMap, TextureInspector.IsNormalMap(t) ? 1 : 0);
            mat.SetFloat(s_ShaderExposure, GetExposureValueForTexture(t));

            m_PreviewUtility.DrawMesh(m_Mesh, Vector3.zero, rot, mat, 0);
            m_PreviewUtility.Render();
        }
示例#5
0
        public override string GetInfoString()
        {
            Texture         texture         = base.target as Texture;
            Texture2D       texture2D       = base.target as Texture2D;
            TextureImporter textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter;
            string          text            = texture.width.ToString() + "x" + texture.height.ToString();

            if (QualitySettings.desiredColorSpace == ColorSpace.Linear)
            {
                text = text + " " + TextureUtil.GetTextureColorSpaceString(texture);
            }
            bool          flag          = textureImporter && textureImporter.qualifiesForSpritePacking;
            bool          flag2         = TextureInspector.IsNormalMap(texture);
            bool          flag3         = TextureUtil.DoesTextureStillNeedToBeCompressed(AssetDatabase.GetAssetPath(texture));
            bool          flag4         = texture2D != null && TextureUtil.IsNonPowerOfTwo(texture2D);
            TextureFormat textureFormat = TextureUtil.GetTextureFormat(texture);
            bool          flag5         = !flag3;

            if (flag4)
            {
                text += " (NPOT)";
            }
            if (flag3)
            {
                text += " (Not yet compressed)";
            }
            else if (flag2)
            {
                switch (textureFormat)
                {
                case TextureFormat.ARGB4444:
                    text += "  Nm 16 bit";
                    goto IL_176;

                case TextureFormat.RGB24:
IL_11D:
                    if (textureFormat != TextureFormat.DXT5)
                    {
                        text = text + "  " + TextureUtil.GetTextureFormatString(textureFormat);
                        goto IL_176;
                    }
                    text += "  DXTnm";
                    goto IL_176;

                case TextureFormat.RGBA32:
                case TextureFormat.ARGB32:
                    text += "  Nm 32 bit";
                    goto IL_176;
                }
                goto IL_11D;
                IL_176 :;
            }
            else if (flag)
            {
                TextureFormat format;
                ColorSpace    colorSpace;
                int           num;
                textureImporter.ReadTextureImportInstructions(EditorUserBuildSettings.activeBuildTarget, out format, out colorSpace, out num);
                string text2 = text;
                text = string.Concat(new string[]
                {
                    text2,
                    "\n ",
                    TextureUtil.GetTextureFormatString(textureFormat),
                    "(Original) ",
                    TextureUtil.GetTextureFormatString(format),
                    "(Atlas)"
                });
            }
            else
            {
                text = text + "  " + TextureUtil.GetTextureFormatString(textureFormat);
            }
            if (flag5)
            {
                text = text + "\n" + EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySizeLong(texture));
            }
            if (TextureUtil.GetUsageMode(texture) == TextureUsageMode.AlwaysPadded)
            {
                int gPUWidth  = TextureUtil.GetGPUWidth(texture);
                int gPUHeight = TextureUtil.GetGPUHeight(texture);
                if (texture.width != gPUWidth || texture.height != gPUHeight)
                {
                    text += string.Format("\nPadded to {0}x{1}", gPUWidth, gPUHeight);
                }
            }
            return(text);
        }
示例#6
0
 public override void OnPreviewSettings()
 {
     if (this.IsCubemap())
     {
         this.m_CubemapPreview.OnPreviewSettings(base.targets);
     }
     else
     {
         if (TextureInspector.s_Styles == null)
         {
             TextureInspector.s_Styles = new TextureInspector.Styles();
         }
         Texture texture = base.target as Texture;
         bool    flag    = true;
         bool    flag2   = false;
         bool    flag3   = true;
         int     num     = 1;
         if (base.target is Texture2D || base.target is ProceduralTexture)
         {
             flag2 = true;
             flag3 = false;
         }
         UnityEngine.Object[] targets = base.targets;
         for (int i = 0; i < targets.Length; i++)
         {
             Texture texture2 = (Texture)targets[i];
             if (!(texture2 == null))
             {
                 TextureFormat format = (TextureFormat)0;
                 bool          flag4  = false;
                 if (texture2 is Texture2D)
                 {
                     format = (texture2 as Texture2D).format;
                     flag4  = true;
                 }
                 else if (texture2 is ProceduralTexture)
                 {
                     format = (texture2 as ProceduralTexture).format;
                     flag4  = true;
                 }
                 if (flag4)
                 {
                     if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                     {
                         flag2 = false;
                     }
                     if (TextureUtil.HasAlphaTextureFormat(format))
                     {
                         if (TextureUtil.GetUsageMode(texture2) == TextureUsageMode.Default)
                         {
                             flag3 = true;
                         }
                     }
                 }
                 num = Mathf.Max(num, TextureUtil.GetMipmapCount(texture2));
             }
         }
         if (flag2)
         {
             this.m_ShowAlpha = true;
             flag             = false;
         }
         else if (!flag3)
         {
             this.m_ShowAlpha = false;
             flag             = false;
         }
         if (flag && texture != null && !TextureInspector.IsNormalMap(texture))
         {
             this.m_ShowAlpha = GUILayout.Toggle(this.m_ShowAlpha, (!this.m_ShowAlpha) ? TextureInspector.s_Styles.RGBIcon : TextureInspector.s_Styles.alphaIcon, TextureInspector.s_Styles.previewButton, new GUILayoutOption[0]);
         }
         GUI.enabled = (num != 1);
         GUILayout.Box(TextureInspector.s_Styles.smallZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.changed     = false;
         this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(num - 1), 0f, TextureInspector.s_Styles.previewSlider, TextureInspector.s_Styles.previewSliderThumb, new GUILayoutOption[]
         {
             GUILayout.MaxWidth(64f)
         }));
         GUILayout.Box(TextureInspector.s_Styles.largeZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.enabled = true;
     }
 }
示例#7
0
        public override string GetInfoString()
        {
            Texture   texture   = this.target as Texture;
            Texture2D texture2D = this.target as Texture2D;
            string    text      = texture.width.ToString() + "x" + texture.height.ToString();

            if (QualitySettings.desiredColorSpace == ColorSpace.Linear)
            {
                text = text + " " + TextureUtil.GetTextureColorSpaceString(texture);
            }
            bool          flag          = TextureInspector.IsNormalMap(texture);
            bool          flag2         = TextureUtil.DoesTextureStillNeedToBeCompressed(AssetDatabase.GetAssetPath(texture));
            bool          flag3         = texture2D != null && TextureUtil.IsNonPowerOfTwo(texture2D);
            TextureFormat textureFormat = TextureUtil.GetTextureFormat(texture);
            bool          flag4         = !flag2;

            if (flag3)
            {
                text += " (NPOT)";
            }
            if (flag2)
            {
                text += " (Not yet compressed)";
            }
            else
            {
                if (flag)
                {
                    TextureFormat textureFormat2 = textureFormat;
                    switch (textureFormat2)
                    {
                    case TextureFormat.ARGB4444:
                        text += "  Nm 16 bit";
                        goto IL_142;

                    case TextureFormat.RGB24:
                    case TextureFormat.RGBA32:
IL_E9:
                        if (textureFormat2 != TextureFormat.DXT5)
                        {
                            text = text + "  " + TextureUtil.GetTextureFormatString(textureFormat);
                            goto IL_142;
                        }
                        text += "  DXTnm";
                        goto IL_142;

                    case TextureFormat.ARGB32:
                        text += "  Nm 32 bit";
                        goto IL_142;
                    }
                    goto IL_E9;
                    IL_142 :;
                }
                else
                {
                    text = text + "  " + TextureUtil.GetTextureFormatString(textureFormat);
                }
            }
            if (flag4)
            {
                text = text + "\n" + EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySize(texture));
            }
            if (TextureUtil.GetUsageMode(texture) == TextureUsageMode.AlwaysPadded)
            {
                int gLWidth  = TextureUtil.GetGLWidth(texture);
                int gLHeight = TextureUtil.GetGLHeight(texture);
                if (texture.width != gLWidth || texture.height != gLHeight)
                {
                    text += string.Format("\nPadded to {0}x{1}", gLWidth, gLHeight);
                }
            }
            return(text);
        }
        public override string GetInfoString()
        {
            Texture         target1 = this.target as Texture;
            Texture2D       target2 = this.target as Texture2D;
            TextureImporter atPath  = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath((UnityEngine.Object)target1)) as TextureImporter;
            string          str1    = target1.width.ToString() + "x" + target1.height.ToString();

            if (QualitySettings.desiredColorSpace == ColorSpace.Linear)
            {
                str1 = str1 + " " + TextureUtil.GetTextureColorSpaceString(target1);
            }
            bool          flag1          = (bool)((UnityEngine.Object)atPath) && atPath.qualifiesForSpritePacking;
            bool          flag2          = TextureInspector.IsNormalMap(target1);
            bool          beCompressed   = TextureUtil.DoesTextureStillNeedToBeCompressed(AssetDatabase.GetAssetPath((UnityEngine.Object)target1));
            bool          flag3          = (UnityEngine.Object)target2 != (UnityEngine.Object)null && TextureUtil.IsNonPowerOfTwo(target2);
            TextureFormat textureFormat1 = TextureUtil.GetTextureFormat(target1);
            bool          flag4          = !beCompressed;

            if (flag3)
            {
                str1 += " (NPOT)";
            }
            string str2;

            if (beCompressed)
            {
                str2 = str1 + " (Not yet compressed)";
            }
            else if (flag2)
            {
                TextureFormat textureFormat2 = textureFormat1;
                switch (textureFormat2)
                {
                case TextureFormat.ARGB4444:
                    str2 = str1 + "  Nm 16 bit";
                    break;

                case TextureFormat.ARGB32:
                    str2 = str1 + "  Nm 32 bit";
                    break;

                default:
                    str2 = textureFormat2 == TextureFormat.DXT5 ? str1 + "  DXTnm" : str1 + "  " + TextureUtil.GetTextureFormatString(textureFormat1);
                    break;
                }
            }
            else if (flag1)
            {
                TextureFormat desiredFormat;
                ColorSpace    colorSpace;
                int           compressionQuality;
                atPath.ReadTextureImportInstructions(EditorUserBuildSettings.activeBuildTarget, out desiredFormat, out colorSpace, out compressionQuality);
                str2 = str1 + "\n " + TextureUtil.GetTextureFormatString(textureFormat1) + "(Original) " + TextureUtil.GetTextureFormatString(desiredFormat) + "(Atlas)";
            }
            else
            {
                str2 = str1 + "  " + TextureUtil.GetTextureFormatString(textureFormat1);
            }
            if (flag4)
            {
                str2 = str2 + "\n" + EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySize(target1));
            }
            if (TextureUtil.GetUsageMode(target1) == TextureUsageMode.AlwaysPadded)
            {
                int glWidth  = TextureUtil.GetGLWidth(target1);
                int glHeight = TextureUtil.GetGLHeight(target1);
                if (target1.width != glWidth || target1.height != glHeight)
                {
                    str2 += string.Format("\nPadded to {0}x{1}", (object)glWidth, (object)glHeight);
                }
            }
            return(str2);
        }
 public override void OnPreviewSettings()
 {
     if (this.IsCubemap())
     {
         this.m_CubemapPreview.OnPreviewSettings(this.targets);
     }
     else
     {
         if (TextureInspector.s_Styles == null)
         {
             TextureInspector.s_Styles = new TextureInspector.Styles();
         }
         Texture target1 = this.target as Texture;
         bool    flag1   = true;
         bool    flag2   = false;
         bool    flag3   = true;
         int     a       = 1;
         if (this.target is Texture2D || this.target is ProceduralTexture)
         {
             flag2 = true;
             flag3 = false;
         }
         foreach (Texture target2 in this.targets)
         {
             TextureFormat format = (TextureFormat)0;
             bool          flag4  = false;
             if (target2 is Texture2D)
             {
                 format = (target2 as Texture2D).format;
                 flag4  = true;
             }
             else if (target2 is ProceduralTexture)
             {
                 format = (target2 as ProceduralTexture).format;
                 flag4  = true;
             }
             if (flag4)
             {
                 if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                 {
                     flag2 = false;
                 }
                 if (TextureUtil.HasAlphaTextureFormat(format) && TextureUtil.GetUsageMode(target2) == TextureUsageMode.Default)
                 {
                     flag3 = true;
                 }
             }
             a = Mathf.Max(a, TextureUtil.CountMipmaps(target2));
         }
         if (flag2)
         {
             this.m_ShowAlpha = true;
             flag1            = false;
         }
         else if (!flag3)
         {
             this.m_ShowAlpha = false;
             flag1            = false;
         }
         if (flag1 && !TextureInspector.IsNormalMap(target1))
         {
             this.m_ShowAlpha = GUILayout.Toggle(this.m_ShowAlpha, !this.m_ShowAlpha ? TextureInspector.s_Styles.RGBIcon : TextureInspector.s_Styles.alphaIcon, TextureInspector.s_Styles.previewButton, new GUILayoutOption[0]);
         }
         GUI.enabled = a != 1;
         GUILayout.Box(TextureInspector.s_Styles.smallZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.changed     = false;
         this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(a - 1), 0.0f, TextureInspector.s_Styles.previewSlider, TextureInspector.s_Styles.previewSliderThumb, GUILayout.MaxWidth(64f)));
         GUILayout.Box(TextureInspector.s_Styles.largeZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.enabled = true;
     }
 }