diff --git a/Assets/uLipSync/Editor/Preference.cs b/Assets/uLipSync/Editor/Preference.cs index d34794f..1f45968 100644 --- a/Assets/uLipSync/Editor/Preference.cs +++ b/Assets/uLipSync/Editor/Preference.cs @@ -8,12 +8,14 @@ internal class EditorPrefsStr { public const string DisplayWaveformOnTimeline = "uLipSync-Timeline-DisplayWaveform"; public const string MaxWidthOfWaveformTextureOnTimeline = "uLipSync-Timeline-MaxWidthOfWaveformTexture"; + public const string TextureSmoothOnTimeline = "uLipSync-Timeline-TextureSmooth"; } internal class EditorPrefsDefault { public const int MinWidthOfWaveformTextureOnTimeline = 32; public const int MaxWidthOfWaveformTextureOnTimeline = 2048; + public const float TextureSmoothOnTimeline = 0.85f; } public static class Preference @@ -31,6 +33,12 @@ public static int maxWidthOfWaveformTextureOnTimeline get => EditorPrefs.GetInt(EditorPrefsStr.MaxWidthOfWaveformTextureOnTimeline, EditorPrefsDefault.MaxWidthOfWaveformTextureOnTimeline); set => EditorPrefs.SetInt(EditorPrefsStr.MaxWidthOfWaveformTextureOnTimeline, value); } + + public static float textureSmoothOnTimeline + { + get => EditorPrefs.GetFloat(EditorPrefsStr.TextureSmoothOnTimeline, EditorPrefsDefault.TextureSmoothOnTimeline); + set => EditorPrefs.SetFloat(EditorPrefsStr.TextureSmoothOnTimeline, value); + } } public class PreferenceProvider : SettingsProvider @@ -72,6 +80,15 @@ public override void OnGUI(string searchContext) } } + { + float current = Preference.textureSmoothOnTimeline; + float result = EditorGUILayout.FloatField("Texture Smoothness On Timeline", current); + if (Math.Abs(current - result) > 0f) + { + Preference.textureSmoothOnTimeline = Math.Clamp(result, 0f, 1f); + } + } + --EditorGUI.indentLevel; EditorGUIUtility.labelWidth = defaultLabelWidth; diff --git a/Assets/uLipSync/Editor/Timeline/uLipSyncClipEditor.cs b/Assets/uLipSync/Editor/Timeline/uLipSyncClipEditor.cs index 6674924..4c28659 100644 --- a/Assets/uLipSync/Editor/Timeline/uLipSyncClipEditor.cs +++ b/Assets/uLipSync/Editor/Timeline/uLipSyncClipEditor.cs @@ -92,7 +92,8 @@ Texture2D CreateCachedTexture(uLipSyncClip clip, int width, int height) width, Preference.minWidthOfWaveformTextureOnTimeline, Preference.maxWidthOfWaveformTextureOnTimeline); - var tex = TextureCreator.CreateBakedDataWaveTexture(data, width, height); + var smooth = Preference.textureSmoothOnTimeline; + var tex = TextureCreator.CreateBakedDataWaveTexture(data, width, height, smooth); var cache = new TextureCache { texture = tex }; _textures.Add(clip, cache); diff --git a/Assets/uLipSync/Runtime/Core/TextureCreator.cs b/Assets/uLipSync/Runtime/Core/TextureCreator.cs index 2ad1d3e..897e899 100644 --- a/Assets/uLipSync/Runtime/Core/TextureCreator.cs +++ b/Assets/uLipSync/Runtime/Core/TextureCreator.cs @@ -1,3 +1,4 @@ +using System; using UnityEngine; using Unity.Burst; using Unity.Collections; @@ -55,7 +56,7 @@ public void Execute() targetColor += phonemeColors[colorIndex] * phonemeRatios[ratioIndex]; } - currentColor += (targetColor - currentColor) * smooth; + currentColor += (targetColor - currentColor) * (1f - smooth); for (int y = 0; y < height; ++y) { @@ -71,7 +72,7 @@ public void Execute() } } - public static Texture2D CreateBakedDataWaveTexture(BakedData data, int width, int height) + public static Texture2D CreateBakedDataWaveTexture(BakedData data, int width, int height, float smooth = 0.85f) { var tex = new Texture2D(width, height); @@ -104,7 +105,7 @@ public static Texture2D CreateBakedDataWaveTexture(BakedData data, int width, in width = width, height = height, phonemeCount = phonemeCount, - smooth = 0.15f, + smooth = Mathf.Clamp(smooth, 0f, 1f), }; job.Schedule().Complete();