diff --git a/Editor/SmartTextureImporter.cs b/Editor/SmartTextureImporter.cs index f479a4d..bacfe57 100644 --- a/Editor/SmartTextureImporter.cs +++ b/Editor/SmartTextureImporter.cs @@ -1,21 +1,40 @@ -using System.IO; +using System; +using System.IO; +using System.Linq; using UnityEditor; -using UnityEditor.Experimental.AssetImporters; + using UnityEngine; +using UnityEngine.Rendering; using Object = UnityEngine.Object; -[ScriptedImporter(k_SmartTextureVersion, k_SmartTextureExtesion)] -public class SmartTextureImporter : ScriptedImporter +[UnityEditor.AssetImporters.ScriptedImporter(k_SmartTextureVersion, k_SmartTextureExtesion)] +public class SmartTextureImporter : UnityEditor.AssetImporters.ScriptedImporter { public const string k_SmartTextureExtesion = "smartex"; public const int k_SmartTextureVersion = 1; public const int k_MenuPriority = 320; + [Serializable] internal class InputProperty { public string propertyName; } + [Serializable] class InputTexture : InputProperty { public Texture value; } + [Serializable] class InputFloat : InputProperty { public float value; } + [Serializable] class InputColor : InputProperty { [ColorUsage(true, true)] public Color value; } + [Serializable] class InputVector : InputProperty { public Vector4 value; } + + [Serializable] class Inputs { + public InputTexture[] m_Textures; + public InputFloat[] m_Floats; + public InputColor[] m_Colors; + public InputVector[] m_Vectors; + + } // Input Texture Settings - [SerializeField] Texture2D[] m_InputTextures = new Texture2D[4]; - [SerializeField] TexturePackingSettings[] m_InputTextureSettings = new TexturePackingSettings[4]; - + [SerializeField] Material m_BlitMaterial; + [SerializeField] Vector2Int m_OutputSize; + [SerializeField] bool m_Preview; + [SerializeField] Inputs m_Inputs; + // Output Texture Settings + [SerializeField] bool m_HasAlpha = false; [SerializeField] bool m_IsReadable = false; [SerializeField] bool m_sRGBTexture = false; @@ -66,20 +85,27 @@ static void CreateSmartTextureMenuItem() "Smart Texture Asset for Unity. Allows to channel pack textures by using a ScriptedImporter. Requires Smart Texture Package from https://github.com/phi-lira/SmartTexture. Developed by Felipe Lira."); } - public override void OnImportAsset(AssetImportContext ctx) + public override void OnImportAsset(UnityEditor.AssetImporters.AssetImportContext ctx) { int width = m_TexturePlatformSettings.maxTextureSize; int height = m_TexturePlatformSettings.maxTextureSize; - Texture2D[] textures = m_InputTextures; - TexturePackingSettings[] settings = m_InputTextureSettings; - - var canGenerateTexture = GetOuputTextureSize(textures, out var inputW, out var inputH); + var maxSize = m_OutputSize; + + foreach (var t in m_Inputs.m_Textures) + { + if (t.value == null) continue; + if (m_OutputSize.x == 0 && t.value.width > maxSize.x) maxSize.x = t.value.width; + if (m_OutputSize.y == 0 && t.value.height > maxSize.y) maxSize.y = t.value.height; + } + var canGenerateTexture = maxSize != default; + maxSize.x = Mathf.Max(maxSize.x, 1); + maxSize.y = Mathf.Max(maxSize.y, 1); + //Mimic default importer. We use max size unless assets are smaller - width = width < inputW ? width : inputW; - height = height < inputH ? height : inputH; + width = width < maxSize.x ? width : maxSize.x; + height = height < maxSize.y ? height : maxSize.y; - bool hasAlpha = textures[3] != null; - Texture2D texture = new Texture2D(width, height, hasAlpha ? TextureFormat.ARGB32 : TextureFormat.RGB24, m_EnableMipMap, m_sRGBTexture) + Texture2D texture = new Texture2D(width, height, m_HasAlpha ? TextureFormat.ARGB32 : TextureFormat.RGB24, m_EnableMipMap, m_sRGBTexture) { filterMode = m_FilterMode, wrapMode = m_WrapMode, @@ -90,15 +116,15 @@ public override void OnImportAsset(AssetImportContext ctx) { //Only attempt to apply any settings if the inputs exist - texture.PackChannels(textures, settings); + PackChannels(m_BlitMaterial, texture, m_Inputs); // Mark all input textures as dependency to the texture array. // This causes the texture array to get re-generated when any input texture changes or when the build target changed. - foreach (Texture2D t in textures) + foreach (var t in m_Inputs.m_Textures) { - if (t != null) + if (t.value != null) { - var path = AssetDatabase.GetAssetPath(t); + var path = AssetDatabase.GetAssetPath(t.value); ctx.DependsOnSourceAsset(path); } } @@ -117,10 +143,37 @@ public override void OnImportAsset(AssetImportContext ctx) //If we pass the tex to the 3rd arg we can have it show in an Icon as normal, maybe configurable? //ctx.AddObjectToAsset("mask", texture, texture); - ctx.AddObjectToAsset("mask", texture); + ctx.AddObjectToAsset("mask", texture, texture); ctx.SetMainObject(texture); } + static void PackChannels(Material mat, Texture2D mask, Inputs inputs) + { + int width = mask.width; + int height = mask.height; + + mat = new Material(mat); + + foreach (var i in inputs.m_Textures) mat.SetTexture(i.propertyName, i.value); + foreach (var i in inputs.m_Floats) mat.SetFloat(i.propertyName, i.value); + foreach (var i in inputs.m_Colors) mat.SetColor(i.propertyName, i.value); + foreach (var i in inputs.m_Vectors) mat.SetVector(i.propertyName, i.value); + + var rt = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); + RenderTexture previous = RenderTexture.active; + RenderTexture.active = rt; + + CommandBuffer cmd = new CommandBuffer(); + cmd.Blit(null, rt, mat); + cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); + Graphics.ExecuteCommandBuffer(cmd); + mask.ReadPixels(new Rect(0, 0, width, height), 0, 0); + mask.Apply(); + + RenderTexture.active = previous; + RenderTexture.ReleaseTemporary(rt); + } + void ApplyPropertiesViaSerializedObj(Texture tex) { var so = new SerializedObject(tex); @@ -133,33 +186,4 @@ void ApplyPropertiesViaSerializedObj(Texture tex) so.ApplyModifiedPropertiesWithoutUndo(); } - - bool GetOuputTextureSize(Texture2D[] textures, out int width, out int height) - { - Texture2D masterTexture = null; - foreach (Texture2D t in textures) - { - if (t != null) - { - //Previously we only read the first readable asset - //but we can get the width&height of unreadable textures. - //May need more complex selection as now Red channel dictates minimum size - //Should we try and find the smallest? - masterTexture = t; - break; - } - } - - if (masterTexture == null) - { - var defaultTexture = Texture2D.blackTexture; - width = defaultTexture.width; - height = defaultTexture.height; - return false; - } - - width = masterTexture.width; - height = masterTexture.height; - return true; - } } diff --git a/Editor/SmartTextureImporterEditor.cs b/Editor/SmartTextureImporterEditor.cs index a313cab..fbc8b2d 100644 --- a/Editor/SmartTextureImporterEditor.cs +++ b/Editor/SmartTextureImporterEditor.cs @@ -1,22 +1,43 @@ -using System; +#if UNITY_EDITOR +using System; using UnityEditor; -using UnityEditor.Experimental.AssetImporters; using UnityEngine; + [CustomEditor(typeof(SmartTextureImporter), true)] -public class SmartTextureImporterEditor : ScriptedImporterEditor +class SmartTextureImporterEditor : UnityEditor.AssetImporters.ScriptedImporterEditor { - internal static class Styles + [CustomPropertyDrawer(typeof(SmartTextureImporter.InputProperty), true)] + class InputPropertyDrawer : PropertyDrawer { - public static readonly GUIContent[] labelChannels = + GUIContent temp = new GUIContent(); + + public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { - EditorGUIUtility.TrTextContent("Red Channel", "This texture source channel will be packed into the Output texture red channel"), - EditorGUIUtility.TrTextContent("Green Channel", "This texture source channel will be packed into the Output texture green channel"), - EditorGUIUtility.TrTextContent("Blue Channel", "This texture source channel will be packed into the Output texture blue channel"), - EditorGUIUtility.TrTextContent("Alpha Channel", "This texture source channel will be packed into the Output texture alpha channel"), - }; + var name = property.FindPropertyRelative("propertyName"); + var value = property.FindPropertyRelative("value"); + + rect.width /= 2; + EditorGUI.PropertyField(rect, name, GUIContent.none); + + EditorGUIUtility.labelWidth = 15; + rect.x += rect.width; + if (value.propertyType == SerializedPropertyType.Vector4){ + rect.width /= 4; + temp.text = " x"; EditorGUI.PropertyField(rect, value.FindPropertyRelative("x"), temp); rect.x += rect.width; + temp.text = " y"; EditorGUI.PropertyField(rect, value.FindPropertyRelative("y"), temp); rect.x += rect.width; + temp.text = " z"; EditorGUI.PropertyField(rect, value.FindPropertyRelative("z"), temp); rect.x += rect.width; + temp.text = " w"; EditorGUI.PropertyField(rect, value.FindPropertyRelative("w"), temp); + } + else{ + temp.text = " "; + EditorGUI.PropertyField(rect, value, temp); + } + } + } - public static readonly GUIContent invertColor = EditorGUIUtility.TrTextContent("Invert Color", "If enabled outputs the inverted color (1.0 - color)"); + internal static class Styles + { public static readonly GUIContent readWrite = EditorGUIUtility.TrTextContent("Read/Write Enabled", "Enable to be able to access the raw pixel data from code."); public static readonly GUIContent generateMipMaps = EditorGUIUtility.TrTextContent("Generate Mip Maps"); public static readonly GUIContent streamingMipMaps = EditorGUIUtility.TrTextContent("Streaming Mip Maps"); @@ -40,13 +61,16 @@ internal static class Styles public static readonly string[] resizeAlgorithmOptions = Enum.GetNames(typeof(TextureResizeAlgorithm)); } - SerializedProperty[] m_InputTextures = new SerializedProperty[4]; - SerializedProperty[] m_InputTextureSettings = new SerializedProperty[4]; + SerializedProperty m_Inputs; + SerializedProperty m_BlitMaterial; + SerializedProperty m_OutputSize; + SerializedProperty m_Preview; SerializedProperty m_IsReadableProperty; SerializedProperty m_sRGBTextureProperty; + SerializedProperty m_HasAlpha; - SerializedProperty m_EnableMipMapProperty; + SerializedProperty m_EnableMipMap; SerializedProperty m_StreamingMipMaps; SerializedProperty m_StreamingMipMapPriority; @@ -54,7 +78,7 @@ internal static class Styles SerializedProperty m_WrapModeProperty; SerializedProperty m_AnisotropiceLevelPropery; - SerializedProperty m_TexturePlatformSettingsProperty; + SerializedProperty m_TexturePlatformSettings; SerializedProperty m_TextureFormat; SerializedProperty m_UseExplicitTextureFormat; @@ -75,22 +99,30 @@ public override void OnInspectorGUI() m_ShowAdvanced = EditorPrefs.GetBool(k_AdvancedTextureSettingName, m_ShowAdvanced); - EditorGUILayout.Space(); - EditorGUILayout.LabelField("Input Textures", EditorStyles.boldLabel); - using (new EditorGUI.IndentLevelScope()) - { - DrawInputTexture(0); - DrawInputTexture(1); - DrawInputTexture(2); - DrawInputTexture(3); - } - EditorGUILayout.Space(); - EditorGUILayout.Space(); + EditorGUI.BeginChangeCheck(); + + EditorGUILayout.BeginHorizontal(); + ApplyRevertGUI(); + if (GUILayout.Button("Repack")) + ApplyAndImport(); + GUILayout.FlexibleSpace(); + EditorGUILayout.EndHorizontal(); + GUILayout.Space(5); + + EditorGUILayout.PropertyField(m_BlitMaterial); + EditorGUILayout.PropertyField(m_OutputSize); + + EditorGUILayout.PropertyField(m_Inputs); - EditorGUILayout.LabelField("Output Texture", EditorStyles.boldLabel); - using (new EditorGUI.IndentLevelScope()) + if (m_EnableMipMap.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_EnableMipMap.isExpanded, "Output Texture")) { - EditorGUILayout.PropertyField(m_EnableMipMapProperty, Styles.generateMipMaps); + // TODO: Figure out how to apply TextureImporterSettings on ScriptedImporter + EditorGUILayout.PropertyField(m_HasAlpha); + EditorGUILayout.PropertyField(m_IsReadableProperty, Styles.readWrite); + EditorGUILayout.PropertyField(m_sRGBTextureProperty, Styles.sRGBTexture); + EditorGUILayout.Space(); + + EditorGUILayout.PropertyField(m_EnableMipMap, Styles.generateMipMaps); EditorGUILayout.PropertyField(m_StreamingMipMaps, Styles.streamingMipMaps); EditorGUILayout.PropertyField(m_StreamingMipMapPriority, Styles.streamingMipMapsPrio); EditorGUILayout.Space(); @@ -100,46 +132,25 @@ public override void OnInspectorGUI() EditorGUILayout.IntSlider(m_AnisotropiceLevelPropery, 0, 16, Styles.textureAnisotropicLevel); EditorGUILayout.Space(); - - // TODO: Figure out how to apply TextureImporterSettings on ScriptedImporter - EditorGUILayout.PropertyField(m_IsReadableProperty, Styles.readWrite); - EditorGUILayout.PropertyField(m_sRGBTextureProperty, Styles.sRGBTexture); } - EditorGUILayout.Space(); - EditorGUILayout.Space(); + EditorGUILayout.EndFoldoutHeaderGroup(); // TODO: Figure out how to apply PlatformTextureImporterSettings on ScriptedImporter DrawTextureImporterSettings(); - EditorGUILayout.Space(); - EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); - ApplyRevertGUI(); - } - - void DrawInputTexture(int index) - { - if (index < 0 || index >= 4) - return; - - EditorGUILayout.PropertyField(m_InputTextures[index], Styles.labelChannels[index]); - - SerializedProperty invertColor = m_InputTextureSettings[index].FindPropertyRelative("invertColor"); - invertColor.boolValue = EditorGUILayout.Toggle(Styles.invertColor, invertColor.boolValue); - EditorGUILayout.Space(); } void DrawTextureImporterSettings() { - SerializedProperty maxTextureSize = m_TexturePlatformSettingsProperty.FindPropertyRelative("m_MaxTextureSize"); + SerializedProperty maxTextureSize = m_TexturePlatformSettings.FindPropertyRelative("m_MaxTextureSize"); SerializedProperty resizeAlgorithm = - m_TexturePlatformSettingsProperty.FindPropertyRelative("m_ResizeAlgorithm"); + m_TexturePlatformSettings.FindPropertyRelative("m_ResizeAlgorithm"); SerializedProperty textureCompression = - m_TexturePlatformSettingsProperty.FindPropertyRelative("m_TextureCompression"); + m_TexturePlatformSettings.FindPropertyRelative("m_TextureCompression"); SerializedProperty textureCompressionCrunched = - m_TexturePlatformSettingsProperty.FindPropertyRelative("m_CrunchedCompression"); + m_TexturePlatformSettings.FindPropertyRelative("m_CrunchedCompression"); - EditorGUILayout.LabelField("Texture Platform Settings", EditorStyles.boldLabel); - using (new EditorGUI.IndentLevelScope()) + if (m_TexturePlatformSettings.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_TexturePlatformSettings.isExpanded, "Texture Platform Settings")) { EditorGUI.BeginChangeCheck(); int sizeOption = EditorGUILayout.Popup("Texture Size", (int)Mathf.Log(maxTextureSize.intValue, 2) - 5, Styles.textureSizeOptions); @@ -151,8 +162,8 @@ void DrawTextureImporterSettings() if (EditorGUI.EndChangeCheck()) resizeAlgorithm.intValue = resizeOption; - EditorGUILayout.LabelField("Compression", EditorStyles.boldLabel); - using (new EditorGUI.IndentLevelScope()) + //EditorGUILayout.LabelField("Compression", EditorStyles.boldLabel); + //using (new EditorGUI.IndentLevelScope()) { EditorGUI.BeginChangeCheck(); bool explicitFormat = EditorGUILayout.Toggle(Styles.useExplicitTextureFormat, m_UseExplicitTextureFormat.boolValue); @@ -186,22 +197,21 @@ void DrawTextureImporterSettings() } } } + EditorGUILayout.EndFoldoutHeaderGroup(); } void CacheSerializedProperties() { - SerializedProperty texturesProperty = serializedObject.FindProperty("m_InputTextures"); - SerializedProperty settingsProperty = serializedObject.FindProperty("m_InputTextureSettings"); - for (int i = 0; i < 4; ++i) - { - m_InputTextures[i] = texturesProperty.GetArrayElementAtIndex(i); - m_InputTextureSettings[i] = settingsProperty.GetArrayElementAtIndex(i); - } + m_BlitMaterial = serializedObject.FindProperty("m_BlitMaterial"); + m_OutputSize = serializedObject.FindProperty("m_OutputSize"); + m_Inputs = serializedObject.FindProperty("m_Inputs"); + m_Preview = serializedObject.FindProperty("m_Preview"); m_IsReadableProperty = serializedObject.FindProperty("m_IsReadable"); m_sRGBTextureProperty = serializedObject.FindProperty("m_sRGBTexture"); + m_HasAlpha = serializedObject.FindProperty("m_HasAlpha"); - m_EnableMipMapProperty = serializedObject.FindProperty("m_EnableMipMap"); + m_EnableMipMap = serializedObject.FindProperty("m_EnableMipMap"); m_StreamingMipMaps = serializedObject.FindProperty("m_StreamingMipMaps"); m_StreamingMipMapPriority = serializedObject.FindProperty("m_StreamingMipMapPriority"); @@ -209,8 +219,9 @@ void CacheSerializedProperties() m_WrapModeProperty = serializedObject.FindProperty("m_WrapMode"); m_AnisotropiceLevelPropery = serializedObject.FindProperty("m_AnisotricLevel"); - m_TexturePlatformSettingsProperty = serializedObject.FindProperty("m_TexturePlatformSettings"); + m_TexturePlatformSettings = serializedObject.FindProperty("m_TexturePlatformSettings"); m_TextureFormat = serializedObject.FindProperty("m_TextureFormat"); m_UseExplicitTextureFormat = serializedObject.FindProperty("m_UseExplicitTextureFormat"); } } +#endif \ No newline at end of file diff --git a/Editor/Philira.SmartTexture.Editor.asmdef b/Philira.SmartTexture.Editor.asmdef similarity index 100% rename from Editor/Philira.SmartTexture.Editor.asmdef rename to Philira.SmartTexture.Editor.asmdef diff --git a/Editor/Philira.SmartTexture.Editor.asmdef.meta b/Philira.SmartTexture.Editor.asmdef.meta similarity index 76% rename from Editor/Philira.SmartTexture.Editor.asmdef.meta rename to Philira.SmartTexture.Editor.asmdef.meta index d2d514e..9f9fdcb 100644 --- a/Editor/Philira.SmartTexture.Editor.asmdef.meta +++ b/Philira.SmartTexture.Editor.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 447a42f34d7589946b8de01d4e806a77 +guid: 73270a5d45254f640ba02b1830980ad4 AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Runtime/Philira.SmartTexture.Runtime.asmdef b/Runtime/Philira.SmartTexture.Runtime.asmdef deleted file mode 100644 index 0cea08b..0000000 --- a/Runtime/Philira.SmartTexture.Runtime.asmdef +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "Philira.SmartTexture.Runtime", - "references": [], - "includePlatforms": [ - "Android", - "Editor", - "iOS", - "LinuxStandalone64", - "Lumin", - "macOSStandalone", - "PS4", - "Stadia", - "Switch", - "tvOS", - "WSA", - "WebGL", - "WindowsStandalone32", - "WindowsStandalone64", - "XboxOne" - ], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": false, - "precompiledReferences": [], - "autoReferenced": true, - "defineConstraints": [], - "versionDefines": [], - "noEngineReferences": false -} \ No newline at end of file diff --git a/Runtime/Philira.SmartTexture.Runtime.asmdef.meta b/Runtime/Philira.SmartTexture.Runtime.asmdef.meta deleted file mode 100644 index 3dd3456..0000000 --- a/Runtime/Philira.SmartTexture.Runtime.asmdef.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 9e705d6a72d9a354b810376671ddb3ac -AssemblyDefinitionImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/TextureChannelPacker.cs b/Runtime/TextureChannelPacker.cs deleted file mode 100644 index 20cd558..0000000 --- a/Runtime/TextureChannelPacker.cs +++ /dev/null @@ -1,147 +0,0 @@ -using UnityEngine; -using UnityEngine.Rendering; - -// TODO: Add option to pack using compute shader -// TODO: Convert from sRGB to linear color space if necessary. -// TODO: Texture compression / Format -// TODO: Mipmaps - -[System.Serializable] -/// -/// Containts settings that apply color modifiers to each channel. -/// -public struct TexturePackingSettings -{ - /// - /// Outputs the inverted color (1.0 - color) - /// - public bool invertColor; -} - -public static class TextureExtension -{ - static Material s_PackChannelMaterial = null; - - private static Material packChannelMaterial - { - get - { - if (s_PackChannelMaterial == null) - { - Shader packChannelShader = Shader.Find("Hidden/PackChannel"); - if (packChannelShader == null) - return null; - - s_PackChannelMaterial = new Material(packChannelShader); - } - - return s_PackChannelMaterial; - } - } - - public static void PackChannels(this Texture2D mask, Texture2D[] textures, TexturePackingSettings[] settings = null, bool generateOnGPU = true) - { - if (textures == null || textures.Length != 4) - { - Debug.LogError("Invalid parameter to PackChannels. An array of 4 textures is expected"); - } - - if (settings == null) - { - settings = new TexturePackingSettings[4]; - for (int i = 0; i < settings.Length; ++i) - { - settings[i].invertColor = false; - } - } - - int width = mask.width; - int height = mask.height; - int pixelCount = width * height; - - foreach (Texture2D t in textures) - { - if (t != null) - { - if (!generateOnGPU && !t.isReadable) - { - Debug.LogError(t + " texture is not readable. Toogle Read/Write Enable in texture importer. "); - return; - } - - if (t.width != width || t.height != height) - { - Debug.LogError(t + " input textures must have the same size."); - return; - } - } - } - - if (generateOnGPU) - { - float[] invertColor = - { - settings[0].invertColor ? 1.0f : 0.0f, - settings[1].invertColor ? 1.0f : 0.0f, - settings[2].invertColor ? 1.0f : 0.0f, - settings[3].invertColor ? 1.0f : 0.0f, - }; - packChannelMaterial.SetTexture("_RedChannel", textures[0] != null ? textures[0] : Texture2D.blackTexture); - packChannelMaterial.SetTexture("_GreenChannel", textures[1] != null ? textures[1] : Texture2D.blackTexture); - packChannelMaterial.SetTexture("_BlueChannel", textures[2] != null ? textures[2] : Texture2D.blackTexture); - packChannelMaterial.SetTexture("_AlphaChannel", textures[3] != null ? textures[3] : Texture2D.blackTexture); - packChannelMaterial.SetVector("_InvertColor", new Vector4(invertColor[0], invertColor[1], invertColor[2], invertColor[3])); - - var rt = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, - RenderTextureReadWrite.Linear); - RenderTexture previous = RenderTexture.active; - RenderTexture.active = rt; - - CommandBuffer cmd = new CommandBuffer(); - cmd.Blit(null, rt, packChannelMaterial); - cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); - Graphics.ExecuteCommandBuffer(cmd); - mask.ReadPixels(new Rect(0, 0, width, height), 0, 0); - mask.Apply(); - - RenderTexture.active = previous; - RenderTexture.ReleaseTemporary(rt); - } - else - { - Color[][] pixels = - { - textures[0] != null ? textures[0].GetPixels(0) : null, - textures[1] != null ? textures[1].GetPixels(0) : null, - textures[2] != null ? textures[2].GetPixels(0) : null, - textures[3] != null ? textures[3].GetPixels(0) : null, - }; - - Color[] maskPixels = new Color[pixelCount]; - for (int i = 0; i < pixelCount; ++i) - { - float r = (textures[0] != null) ? pixels[0][i].r : 0.0f; - float g = (textures[1] != null) ? pixels[1][i].r : 0.0f; - float b = (textures[2] != null) ? pixels[2][i].r : 0.0f; - float a = (textures[3] != null) ? pixels[3][i].r : 0.0f; - - if (settings[0].invertColor) - r = 1.0f - r; - - if (settings[1].invertColor) - g = 1.0f - g; - - if (settings[2].invertColor) - b = 1.0f - b; - - if (settings[3].invertColor) - a = 1.0f - a; - - maskPixels[i] = new Color(r, g, b, a); - } - - mask.SetPixels(maskPixels, 0); - mask.Apply(); - } - } -} diff --git a/Runtime/TextureChannelPacker.cs.meta b/Runtime/TextureChannelPacker.cs.meta deleted file mode 100644 index 5d82aac..0000000 --- a/Runtime/TextureChannelPacker.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d8c40e436475247d587a32d3a1d49cec -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Shaders/PackShader.mat b/Shaders/PackShader.mat new file mode 100644 index 0000000..606df70 --- /dev/null +++ b/Shaders/PackShader.mat @@ -0,0 +1,140 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &-7177970478230962508 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 4 +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: PackShader + m_Shader: {fileID: 4800000, guid: 7301b3a1d9d6947099451599aba74fde, type: 3} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _AlphaChannel: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlueChannel: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _GreenChannel: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _RedChannel: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _AlphaClip: 0 + - _Blend: 0 + - _BumpScale: 1 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _EnvironmentReflections: 1 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.005 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _Smoothness: 0.5 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _Surface: 0 + - _WorkflowMode: 1 + - _ZWrite: 1 + m_Colors: + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _InvertColor: {r: 0, g: 0, b: 0, a: 0} + - _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1} + m_BuildTextureStacks: [] diff --git a/Runtime.meta b/Shaders/PackShader.mat.meta similarity index 52% rename from Runtime.meta rename to Shaders/PackShader.mat.meta index 3b8bb22..b87dc49 100644 --- a/Runtime.meta +++ b/Shaders/PackShader.mat.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: 683872b7a9e58404d86a72f64355a908 -folderAsset: yes -DefaultImporter: +guid: c1fe2aa9e1273b148a173ec79df93dc7 +NativeFormatImporter: externalObjects: {} + mainObjectFileID: 2100000 userData: assetBundleName: assetBundleVariant: diff --git a/Shaders/PackShader.shader b/Shaders/PackShader.shader index 0c8410c..fb3ce2e 100644 --- a/Shaders/PackShader.shader +++ b/Shaders/PackShader.shader @@ -1,4 +1,4 @@ -Shader "Hidden/PackChannel" +Shader "Blit/PackChannel" { Properties { diff --git a/Tests.meta b/Tests.meta deleted file mode 100644 index d0b2bed..0000000 --- a/Tests.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b06745750b9594648ae6e8a52b3dcf9e -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Tests/Editor.meta b/Tests/Editor.meta deleted file mode 100644 index 50420cc..0000000 --- a/Tests/Editor.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 8b831c344cdf9f14ab95279309d511a5 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Tests/Editor/Philira.SmartTexture.Editor.Tests.asmdef b/Tests/Editor/Philira.SmartTexture.Editor.Tests.asmdef deleted file mode 100644 index 67ff65d..0000000 --- a/Tests/Editor/Philira.SmartTexture.Editor.Tests.asmdef +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "Philira.SmartTexture.Editor.Tests", - "references": [ - "GUID:27619889b8ba8c24980f49ee34dbb44a", - "GUID:0acc523941302664db1f4e527237feb3", - "GUID:9e705d6a72d9a354b810376671ddb3ac" - ], - "includePlatforms": [ - "Editor" - ], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": true, - "precompiledReferences": [ - "nunit.framework.dll" - ], - "autoReferenced": false, - "defineConstraints": [ - "UNITY_INCLUDE_TESTS" - ], - "versionDefines": [], - "noEngineReferences": false -} \ No newline at end of file diff --git a/Tests/Editor/Philira.SmartTexture.Editor.Tests.asmdef.meta b/Tests/Editor/Philira.SmartTexture.Editor.Tests.asmdef.meta deleted file mode 100644 index 2568858..0000000 --- a/Tests/Editor/Philira.SmartTexture.Editor.Tests.asmdef.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 4d7bdb677fe99a24bb5c724d97ffd1c3 -AssemblyDefinitionImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: