diff --git a/Assets/Effekseer/Editor/EffekseerAssetPostProcessor.cs b/Assets/Effekseer/Editor/EffekseerAssetPostProcessor.cs index 3c899d1..e75397b 100644 --- a/Assets/Effekseer/Editor/EffekseerAssetPostProcessor.cs +++ b/Assets/Effekseer/Editor/EffekseerAssetPostProcessor.cs @@ -69,7 +69,7 @@ static void OnPostprocessAllAssets( EffekseerMaterialAsset.ImportingAsset importingAsset = new EffekseerMaterialAsset.ImportingAsset(); importingAsset.Data = System.IO.File.ReadAllBytes(assetPath); importingAsset.UserTextureSlotMax = EffekseerTool.Constant.UserTextureSlotCount; - var info = new EffekseerTool.Utl.MaterialInformation(); + var info = new Effekseer.Editor.Utils.MaterialInformation(); info.Load(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), assetPath)); importingAsset.CustomData1Count = info.CustomData1Count; @@ -95,9 +95,68 @@ static void OnPostprocessAllAssets( importingAsset.Textures.Add(tp); } + // TODO : Refactor + foreach (var g in info.FixedGradients) + { + var gp = new EffekseerMaterialAsset.GradientProperty(); + gp.Name = g.Name; + gp.UniformName = g.UniformName; + + gp.ColorMarkers = new EffekseerMaterialAsset.GradientProperty.ColorMarker[g.Data.ColorMarkers.Length]; + for (int i = 0; i < g.Data.ColorMarkers.Length; i++) + { + gp.ColorMarkers[i].ColorR = g.Data.ColorMarkers[i].ColorR; + gp.ColorMarkers[i].ColorG = g.Data.ColorMarkers[i].ColorG; + gp.ColorMarkers[i].ColorB = g.Data.ColorMarkers[i].ColorB; + gp.ColorMarkers[i].Intensity = g.Data.ColorMarkers[i].Intensity; + gp.ColorMarkers[i].Position = g.Data.ColorMarkers[i].Position; + } + + gp.AlphaMarkers = new EffekseerMaterialAsset.GradientProperty.AlphaMarker[g.Data.AlphaMarkers.Length]; + for (int i = 0; i < g.Data.AlphaMarkers.Length; i++) + { + gp.AlphaMarkers[i].Alpha = g.Data.AlphaMarkers[i].Alpha; + gp.AlphaMarkers[i].Position = g.Data.AlphaMarkers[i].Position; + } + + importingAsset.FixedGradients.Add(gp); + } + + foreach (var g in info.Gradients) + { + var gp = new EffekseerMaterialAsset.GradientProperty(); + gp.Name = g.Name; + gp.UniformName = g.UniformName; + + gp.ColorMarkers = new EffekseerMaterialAsset.GradientProperty.ColorMarker[g.Data.ColorMarkers.Length]; + for (int i = 0; i < g.Data.ColorMarkers.Length; i++) + { + gp.ColorMarkers[i].ColorR = g.Data.ColorMarkers[i].ColorR; + gp.ColorMarkers[i].ColorG = g.Data.ColorMarkers[i].ColorG; + gp.ColorMarkers[i].ColorB = g.Data.ColorMarkers[i].ColorB; + gp.ColorMarkers[i].Intensity = g.Data.ColorMarkers[i].Intensity; + gp.ColorMarkers[i].Position = g.Data.ColorMarkers[i].Position; + } + + gp.AlphaMarkers = new EffekseerMaterialAsset.GradientProperty.AlphaMarker[g.Data.AlphaMarkers.Length]; + for (int i = 0; i < g.Data.AlphaMarkers.Length; i++) + { + gp.AlphaMarkers[i].Alpha = g.Data.AlphaMarkers[i].Alpha; + gp.AlphaMarkers[i].Position = g.Data.AlphaMarkers[i].Position; + } + + importingAsset.Gradients.Add(gp); + } + importingAsset.IsCacheFile = false; importingAsset.Code = info.Code; + importingAsset.MaterialRequiredFunctionTypes = new EffekseerMaterialAsset.MaterialRequiredFunctionType[info.RequiredFunctionTypes.Length]; + for (int i = 0; i < importingAsset.MaterialRequiredFunctionTypes.Length; i++) + { + importingAsset.MaterialRequiredFunctionTypes[i] = (EffekseerMaterialAsset.MaterialRequiredFunctionType)info.RequiredFunctionTypes[i]; + } + EffekseerMaterialAsset.CreateAsset(assetPath, importingAsset); } if (Path.GetExtension(assetPath) == ".efkmatd") diff --git a/Assets/Effekseer/Editor/EffekseerEmitterEditor.cs b/Assets/Effekseer/Editor/EffekseerEmitterEditor.cs index d0bdb4f..73e8771 100644 --- a/Assets/Effekseer/Editor/EffekseerEmitterEditor.cs +++ b/Assets/Effekseer/Editor/EffekseerEmitterEditor.cs @@ -221,6 +221,27 @@ void CallSceneGUI() emitter.speed = Mathf.Clamp(emitter.speed, 0, 2); GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(); + GUILayout.Label("Trigger", GUILayout.Width(50)); + if (GUILayout.Button("0")) + { + emitter.SendTrigger(0); + } + if (GUILayout.Button("1")) + { + emitter.SendTrigger(1); + } + if (GUILayout.Button("2")) + { + emitter.SendTrigger(2); + } + if (GUILayout.Button("3")) + { + emitter.SendTrigger(3); + } + GUILayout.EndHorizontal(); + + GUILayout.BeginHorizontal(); GUILayout.Label("Instance", GUILayout.Width(80)); GUILayout.Label(emitter.instanceCount.ToString()); diff --git a/Assets/Effekseer/Editor/EffekseerMaterialInformation.cs b/Assets/Effekseer/Editor/EffekseerMaterialInformation.cs new file mode 100644 index 0000000..35b2b30 --- /dev/null +++ b/Assets/Effekseer/Editor/EffekseerMaterialInformation.cs @@ -0,0 +1,1033 @@ +using System; +using System.Text; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +// Copy and edit from EffekseerEditor + +#if UNITY_EDITOR +using UnityEditor; + +namespace Effekseer.Editor.Utils +{ + public enum Language + { + Japanese, + English, + } + + public enum CompiledMaterialPlatformType : int + { + DirectX9 = 0, + // DirectX10 = 1, + DirectX11 = 2, + DirectX12 = 3, + OpenGL = 10, + Metal = 20, + Vulkan = 30, + PS4 = 40, + Switch = 50, + XBoxOne = 60, + PS5 = 70, + } + + public enum TextureType : int + { + Color, + Value, + } + + public enum CompiledMaterialInformationErrorCode + { + OK, + TooOldFormat, + TooNewFormat, + NotFound, + FailedToOpen, + InvalidFormat, + } + + public enum MaterialVersion : int + { + Version0 = 0, + Version15 = 3, + Version16 = 1610, + Version17Alpha2 = 1700, + Version17Alpha4 = 1703, + } + + public enum CompiledMaterialVersion : int + { + Version0 = 0, + Version15 = 1, + Version16 = 1610, + Version162 = 1612, + } + + public enum MaterialRequiredFunctionType : int + { + Gradient = 0, + Noise = 1, + Light = 2, + } + + public class Gradient + { + public unsafe struct ColorMarker + { + public float Position; + public float ColorR; + public float ColorG; + public float ColorB; + public float Intensity; + } + + public struct AlphaMarker + { + public float Position; + public float Alpha; + } + + public class State : ICloneable + { + public ColorMarker[] ColorMarkers; + public AlphaMarker[] AlphaMarkers; + + public unsafe byte[] ToBinary() + { + List data = new List(); + data.Add(BitConverter.GetBytes(ColorMarkers.Length)); + + for (int i = 0; i < ColorMarkers.Length; i++) + { + data.Add(BitConverter.GetBytes(ColorMarkers[i].Position)); + data.Add(BitConverter.GetBytes(ColorMarkers[i].ColorR)); + data.Add(BitConverter.GetBytes(ColorMarkers[i].ColorG)); + data.Add(BitConverter.GetBytes(ColorMarkers[i].ColorB)); + data.Add(BitConverter.GetBytes(ColorMarkers[i].Intensity)); + } + + data.Add(BitConverter.GetBytes(AlphaMarkers.Length)); + + for (int i = 0; i < AlphaMarkers.Length; i++) + { + data.Add(BitConverter.GetBytes(AlphaMarkers[i].Position)); + data.Add(BitConverter.GetBytes(AlphaMarkers[i].Alpha)); + } + + return data.SelectMany(_ => _).ToArray(); + } + + public object Clone() + { + var state = new State(); + + state.ColorMarkers = (ColorMarker[])ColorMarkers.Clone(); + state.AlphaMarkers = (AlphaMarker[])AlphaMarkers.Clone(); + + return state; + } + + public unsafe override bool Equals(object obj) + { + var o = (State)obj; + if (o == null) + { + return false; + } + + if (ColorMarkers.Count() != o.ColorMarkers.Count() || AlphaMarkers.Count() != o.AlphaMarkers.Count()) + { + return false; + } + + for (int i = 0; i < ColorMarkers.Count(); i++) + { + if (ColorMarkers[i].ColorR != o.ColorMarkers[i].ColorR || + ColorMarkers[i].ColorG != o.ColorMarkers[i].ColorG || + ColorMarkers[i].ColorB != o.ColorMarkers[i].ColorB || + ColorMarkers[i].Intensity != o.ColorMarkers[i].Intensity || + ColorMarkers[i].Position != o.ColorMarkers[i].Position) + { + return false; + } + } + + for (int i = 0; i < AlphaMarkers.Count(); i++) + { + if ( + AlphaMarkers[i].Alpha != o.AlphaMarkers[i].Alpha || + AlphaMarkers[i].Position != o.AlphaMarkers[i].Position) + { + return false; + } + } + + return true; + } + } + + State _value = null; + + public State Value + { + get; + } + + public State DefaultValue + { + get; + set; + } + + public unsafe byte[] ToBinary() + { + return _value.ToBinary(); + } + + static Gradient() + { + } + + public unsafe static State CreateDefault() + { + var value = new State(); + value.ColorMarkers = new ColorMarker[2]; + value.ColorMarkers[0].Position = 0; + value.ColorMarkers[0].Intensity = 1; + value.ColorMarkers[0].ColorR = 1.0f; + value.ColorMarkers[0].ColorG = 1.0f; + value.ColorMarkers[0].ColorB = 1.0f; + + value.ColorMarkers[1].Position = 1; + value.ColorMarkers[1].Intensity = 1; + value.ColorMarkers[1].ColorR = 1.0f; + value.ColorMarkers[1].ColorG = 1.0f; + value.ColorMarkers[1].ColorB = 1.0f; + + value.AlphaMarkers = new AlphaMarker[2]; + value.AlphaMarkers[0].Position = 0.0f; + value.AlphaMarkers[0].Alpha = 1.0f; + value.AlphaMarkers[1].Position = 1.0f; + value.AlphaMarkers[1].Alpha = 1.0f; + return value; + } + + public unsafe Gradient() + { + _value = CreateDefault(); + DefaultValue = CreateDefault(); + } + + public State GetValue() + { + return _value; + } + } + + class BinaryReader + { + byte[] buffer = null; + int offset = 0; + + public BinaryReader(byte[] buffer) + { + this.buffer = buffer; + this.offset = 0; + } + + public void Get(ref int value) + { + value = BitConverter.ToInt32(buffer, offset); + offset += 4; + } + + public void Get(ref UInt16 value) + { + value = BitConverter.ToUInt16(buffer, offset); + offset += 2; + } + + public void Get(ref Int16 value) + { + value = BitConverter.ToInt16(buffer, offset); + offset += 2; + } + + public void Get(ref Byte value) + { + value = buffer[offset]; + offset += 1; + } + + public void Get(ref float value) + { + value = BitConverter.ToSingle(buffer, offset); + offset += 4; + } + + public void Get(ref bool value) + { + value = BitConverter.ToInt32(buffer, offset) > 0; + offset += 4; + } + + public void Get(ref string value, Encoding encoding, bool zeroEnd = true, int bufLenSize = 4) + { + int length = 0; + + if (bufLenSize == 4) + { + int length4 = 0; + Get(ref length4); + length = length4; + } + else if (bufLenSize == 2) + { + UInt16 length2 = 0; + Get(ref length2); + length = length2; + } + else if (bufLenSize == 1) + { + Byte length1 = 0; + Get(ref length1); + length = length1; + } + + int readLength = length; + + if (zeroEnd) + { + if (encoding == Encoding.Unicode) + { + readLength -= 2; + } + else if (encoding == Encoding.UTF8) + { + readLength -= 1; + } + else + { + throw new NotImplementedException(); + } + } + + if (encoding == Encoding.Unicode) + { + readLength *= 2; + } + + value = encoding.GetString(buffer, offset, readLength); + offset += length; + } + } + + class BinaryWriter + { + List buffers = new List(); + + public BinaryWriter() + { + } + + public byte[] GetBinary() + { + return buffers.SelectMany(_ => _).ToArray(); + } + + public void Push(int value) + { + buffers.Add(BitConverter.GetBytes(value)); + } + + public void Push(UInt32 value) + { + buffers.Add(BitConverter.GetBytes(value)); + } + public void Push(Int16 value) + { + buffers.Add(BitConverter.GetBytes(value)); + } + + public void Push(UInt16 value) + { + buffers.Add(BitConverter.GetBytes(value)); + } + + public void Push(UInt64 value) + { + buffers.Add(BitConverter.GetBytes(value)); + } + + public void Push(bool value) + { + buffers.Add(BitConverter.GetBytes(value ? 1 : 0)); + } + + public void Push(byte[] buffer) + { + Push(buffer.Count()); + buffers.Add((byte[])buffer.Clone()); + } + + public void Push(float value) + { + buffers.Add(BitConverter.GetBytes(value)); + } + + public void Push(string value, Encoding encoding, bool zeroEnd = true, int bufLenSize = 4) + { + var strBuf = encoding.GetBytes(value); + var length = strBuf.Count(); + + if (zeroEnd) + { + if (encoding == Encoding.Unicode) + { + length += 2; + } + else if (encoding == Encoding.UTF8) + { + length += 1; + } + else + { + throw new NotImplementedException(); + } + } + + if (encoding == Encoding.Unicode) + { + length /= 2; + } + + if (bufLenSize == 4) + { + buffers.Add(BitConverter.GetBytes(length)); + } + else if (bufLenSize == 2) + { + buffers.Add(BitConverter.GetBytes((UInt16)length)); + } + else if (bufLenSize == 1) + { + buffers.Add(new[] { (Byte)length }); + } + + buffers.Add(strBuf); + + if (zeroEnd) + { + if (encoding == Encoding.Unicode) + { + buffers.Add(new byte[] { 0, 0 }); + } + else if (encoding == Encoding.UTF8) + { + buffers.Add(new byte[] { 0 }); + } + else + { + throw new NotImplementedException(); + } + } + } + + public void PushDirectly(byte[] buffer) + { + buffers.Add((byte[])buffer.Clone()); + } + } + + + /// + /// An information of file of compiled material's header + /// + public class CompiledMaterialInformation + { + const CompiledMaterialVersion LatestSupportVersion = CompiledMaterialVersion.Version162; + const CompiledMaterialVersion OldestSupportVersion = CompiledMaterialVersion.Version162; + + public UInt64 GUID; + public int Version; + public HashSet Platforms = new HashSet(); + + public CompiledMaterialInformationErrorCode Load(string path) + { + if (string.IsNullOrEmpty(path)) + return CompiledMaterialInformationErrorCode.NotFound; + + System.IO.FileStream fs = null; + if (!System.IO.File.Exists(path)) return CompiledMaterialInformationErrorCode.NotFound; + + try + { + fs = System.IO.File.Open(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); + } + catch + { + return CompiledMaterialInformationErrorCode.FailedToOpen; + } + + + var br = new System.IO.BinaryReader(fs); + + var buf = new byte[1024]; + + + if (br.Read(buf, 0, 20) != 20) + { + fs.Dispose(); + br.Close(); + return CompiledMaterialInformationErrorCode.InvalidFormat; + } + + if (buf[0] != 'e' || + buf[1] != 'M' || + buf[2] != 'C' || + buf[3] != 'B') + { + fs.Dispose(); + br.Close(); + return CompiledMaterialInformationErrorCode.InvalidFormat; + } + + Version = BitConverter.ToInt32(buf, 4); + + // bacause of camera position node, structure of uniform is changed + if (Version < (int)OldestSupportVersion) + { + fs.Dispose(); + br.Close(); + return CompiledMaterialInformationErrorCode.TooOldFormat; + } + + if (Version > (int)LatestSupportVersion) + { + fs.Dispose(); + br.Close(); + return CompiledMaterialInformationErrorCode.TooNewFormat; + } + + int fversion = BitConverter.ToInt32(buf, 4); + + GUID = BitConverter.ToUInt64(buf, 8); + + var platformCount = BitConverter.ToInt32(buf, 16); + + for (int i = 0; i < platformCount; i++) + { + if (br.Read(buf, 0, 4) != 4) + { + fs.Dispose(); + br.Close(); + return CompiledMaterialInformationErrorCode.InvalidFormat; + } + + var type = (CompiledMaterialPlatformType)BitConverter.ToInt32(buf, 0); + Platforms.Add(type); + } + + fs.Dispose(); + br.Close(); + return CompiledMaterialInformationErrorCode.OK; + } + } + + public class MaterialInformation + { + const MaterialVersion LatestSupportVersion = MaterialVersion.Version17Alpha4; + + public MaterialVersion Version = MaterialVersion.Version17Alpha4; + + public TextureInformation[] Textures = new TextureInformation[0]; + + public UniformInformation[] Uniforms = new UniformInformation[0]; + + public GradientInformation[] Gradients = new GradientInformation[0]; + + public GradientInformation[] FixedGradients = new GradientInformation[0]; + + public CustomDataInformation[] CustomData = new CustomDataInformation[0]; + + public MaterialRequiredFunctionType[] RequiredFunctionTypes = new MaterialRequiredFunctionType[0]; + + public UInt64 GUID; + + public int CustomData1Count = 0; + + public int CustomData2Count = 0; + + public bool HasNormal = false; + + public bool HasRefraction = false; + + public Dictionary Names = new Dictionary(); + + public Dictionary Descriptions = new Dictionary(); + + public string Code = string.Empty; + + public int ShadingModel = 0; + + public bool Load(string path) + { + if (string.IsNullOrEmpty(path)) + return false; + + byte[] file = null; + + if (!System.IO.File.Exists(path)) return false; + + try + { + file = System.IO.File.ReadAllBytes(path); + } + catch + { + return false; + } + + return Load(file); + } + + public bool Load(byte[] file) + { + var br = new System.IO.BinaryReader(new System.IO.MemoryStream(file)); + var buf = new byte[1024]; + + if (br.Read(buf, 0, 16) != 16) + { + br.Close(); + return false; + } + + if (buf[0] != 'E' || + buf[1] != 'F' || + buf[2] != 'K' || + buf[3] != 'M') + { + return false; + } + + int version = BitConverter.ToInt32(buf, 4); + + if (version > (int)LatestSupportVersion) + { + return false; + } + + GUID = BitConverter.ToUInt64(buf, 8); + + while (true) + { + if (br.Read(buf, 0, 8) != 8) + { + br.Close(); + break; + } + + if (buf[0] == 'D' && + buf[1] == 'E' && + buf[2] == 'S' && + buf[3] == 'C') + { + var temp = new byte[BitConverter.ToInt32(buf, 4)]; + if (br.Read(temp, 0, temp.Length) != temp.Length) return false; + + var reader = new BinaryReader(temp); + + int count = 0; + reader.Get(ref count); + + for (int i = 0; i < count; i++) + { + int lang = 0; + string name = null; + string desc = null; + reader.Get(ref lang); + reader.Get(ref name, Encoding.UTF8); + reader.Get(ref desc, Encoding.UTF8); + Names.Add((Language)lang, name); + Descriptions.Add((Language)lang, desc); + } + } + + if (buf[0] == 'P' && + buf[1] == 'R' && + buf[2] == 'M' && + buf[3] == '_') + { + var temp = new byte[BitConverter.ToInt32(buf, 4)]; + if (br.Read(temp, 0, temp.Length) != temp.Length) return false; + + var reader = new BinaryReader(temp); + + reader.Get(ref ShadingModel); + + reader.Get(ref HasNormal); + + reader.Get(ref HasRefraction); + + reader.Get(ref CustomData1Count); + + reader.Get(ref CustomData2Count); + + if (version >= (int)MaterialVersion.Version17Alpha4) + { + int requiredCount = 0; + reader.Get(ref requiredCount); + + RequiredFunctionTypes = new MaterialRequiredFunctionType[requiredCount]; + + for (int i = 0; i < requiredCount; i++) + { + int temp2 = 0; + reader.Get(ref temp2); + RequiredFunctionTypes[i] = (MaterialRequiredFunctionType)temp2; + } + } + + int textureCount = 0; + reader.Get(ref textureCount); + + List textures = new List(); + + for (int i = 0; i < textureCount; i++) + { + TextureInformation info = new TextureInformation(); + + reader.Get(ref info.Name, Encoding.UTF8); + + // name is for human, uniformName is a variable name after 3 + if (version >= 3) + { + reader.Get(ref info.UniformName, Encoding.UTF8); + } + else + { + info.UniformName = info.Name; + } + + reader.Get(ref info.DefaultPath, Encoding.UTF8); + reader.Get(ref info.Index); + reader.Get(ref info.Priority); + reader.Get(ref info.IsParam); + int textureType = 0; + reader.Get(ref textureType); + info.Type = (TextureType)textureType; + reader.Get(ref info.Sampler); + + // convert a path into absolute + if (string.IsNullOrEmpty(info.DefaultPath)) + { + info.DefaultPath = string.Empty; + } + + textures.Add(info); + } + + Textures = textures.ToArray(); + + int uniformCount = 0; + reader.Get(ref uniformCount); + + List uniforms = new List(); + + for (int i = 0; i < uniformCount; i++) + { + UniformInformation info = new UniformInformation(); + + reader.Get(ref info.Name, Encoding.UTF8); + + // name is for human, uniformName is a variable name after 3 + if (version >= 3) + { + reader.Get(ref info.UniformName, Encoding.UTF8); + } + else + { + info.UniformName = info.Name; + } + + reader.Get(ref info.Offset); + reader.Get(ref info.Priority); + reader.Get(ref info.Type); + reader.Get(ref info.DefaultValues[0]); + reader.Get(ref info.DefaultValues[1]); + reader.Get(ref info.DefaultValues[2]); + reader.Get(ref info.DefaultValues[3]); + uniforms.Add(info); + } + + Uniforms = uniforms.ToArray(); + + if (version >= (int)MaterialVersion.Version17Alpha4) + { + GradientInformation[] LoadGradient() + { + int gradientCount = 0; + reader.Get(ref gradientCount); + + var gradients = new List(); + + for (int i = 0; i < gradientCount; i++) + { + var info = new GradientInformation(); + info.Data = new Gradient.State(); + + reader.Get(ref info.Name, Encoding.UTF8); + reader.Get(ref info.UniformName, Encoding.UTF8); + reader.Get(ref info.Offset); + reader.Get(ref info.Priority); + + int colorCount = 0; + reader.Get(ref colorCount); + + info.Data.ColorMarkers = new Gradient.ColorMarker[colorCount]; + for (int j = 0; j < colorCount; j++) + { + reader.Get(ref info.Data.ColorMarkers[j].Position); + reader.Get(ref info.Data.ColorMarkers[j].ColorR); + reader.Get(ref info.Data.ColorMarkers[j].ColorG); + reader.Get(ref info.Data.ColorMarkers[j].ColorB); + reader.Get(ref info.Data.ColorMarkers[j].Intensity); + } + + int alphaCount = 0; + reader.Get(ref alphaCount); + + info.Data.AlphaMarkers = new Gradient.AlphaMarker[alphaCount]; + for (int j = 0; j < alphaCount; j++) + { + reader.Get(ref info.Data.AlphaMarkers[j].Position); + reader.Get(ref info.Data.AlphaMarkers[j].Alpha); + } + + gradients.Add(info); + } + + return gradients.ToArray(); + } + + Gradients = LoadGradient(); + FixedGradients = LoadGradient(); + } + } + + if (buf[0] == 'P' && + buf[1] == 'R' && + buf[2] == 'M' && + buf[3] == '2') + { + var temp = new byte[BitConverter.ToInt32(buf, 4)]; + if (br.Read(temp, 0, temp.Length) != temp.Length) return false; + + var reader = new BinaryReader(temp); + + if (version >= 2) + { + int customDataCount = 0; + reader.Get(ref customDataCount); + AllocateCustomData(customDataCount); + + for (int j = 0; j < customDataCount; j++) + { + int count = 0; + reader.Get(ref count); + + for (int i = 0; i < count; i++) + { + int lang = 0; + string name = null; + string desc = null; + reader.Get(ref lang); + reader.Get(ref name, Encoding.UTF8); + reader.Get(ref desc, Encoding.UTF8); + CustomData[j].Summaries.Add((Language)lang, name); + CustomData[j].Descriptions.Add((Language)lang, desc); + } + } + } + + int textureCount = 0; + reader.Get(ref textureCount); + + for (int j = 0; j < textureCount; j++) + { + int count = 0; + reader.Get(ref count); + + for (int i = 0; i < count; i++) + { + int lang = 0; + string name = null; + string desc = null; + reader.Get(ref lang); + reader.Get(ref name, Encoding.UTF8); + reader.Get(ref desc, Encoding.UTF8); + Textures[j].Summaries.Add((Language)lang, name); + Textures[j].Descriptions.Add((Language)lang, desc); + } + } + + int uniformCount = 0; + reader.Get(ref uniformCount); + + for (int j = 0; j < uniformCount; j++) + { + int count = 0; + reader.Get(ref count); + + for (int i = 0; i < count; i++) + { + int lang = 0; + string name = null; + string desc = null; + reader.Get(ref lang); + reader.Get(ref name, Encoding.UTF8); + reader.Get(ref desc, Encoding.UTF8); + Uniforms[j].Summaries.Add((Language)lang, name); + Uniforms[j].Descriptions.Add((Language)lang, desc); + } + } + + if (version >= (int)MaterialVersion.Version17Alpha4) + { + int gradientCount = 0; + reader.Get(ref gradientCount); + + for (int j = 0; j < gradientCount; j++) + { + int count = 0; + reader.Get(ref count); + + for (int i = 0; i < count; i++) + { + int lang = 0; + string name = null; + string desc = null; + reader.Get(ref lang); + reader.Get(ref name, Encoding.UTF8); + reader.Get(ref desc, Encoding.UTF8); + Gradients[j].Summaries.Add((Language)lang, name); + Gradients[j].Descriptions.Add((Language)lang, desc); + } + } + } + } + + if (buf[0] == 'E' && + buf[1] == '_' && + buf[2] == 'C' && + buf[3] == 'D') + { + var temp = new byte[BitConverter.ToInt32(buf, 4)]; + if (br.Read(temp, 0, temp.Length) != temp.Length) return false; + + var reader = new BinaryReader(temp); + + int customDataCount = 0; + reader.Get(ref customDataCount); + AllocateCustomData(customDataCount); + + for (int j = 0; j < customDataCount; j++) + { + reader.Get(ref CustomData[j].DefaultValues[0]); + reader.Get(ref CustomData[j].DefaultValues[1]); + reader.Get(ref CustomData[j].DefaultValues[2]); + reader.Get(ref CustomData[j].DefaultValues[3]); + } + } + + if (buf[0] == 'G' && + buf[1] == 'E' && + buf[2] == 'N' && + buf[3] == 'E') + { + var temp = new byte[BitConverter.ToInt32(buf, 4)]; + if (br.Read(temp, 0, temp.Length) != temp.Length) return false; + + var reader = new BinaryReader(temp); + + reader.Get(ref Code, Encoding.UTF8); + } + + if (buf[0] == 'D' && + buf[1] == 'A' && + buf[2] == 'T' && + buf[3] == 'A') + { + } + } + + return true; + } + + private void AllocateCustomData(int customDataCount) + { + if (CustomData.Count() == 0) + { + CustomData = new CustomDataInformation[customDataCount]; + for (int j = 0; j < customDataCount; j++) + { + CustomData[j] = new CustomDataInformation(); + } + } + } + + public class CustomDataInformation + { + public Dictionary Summaries = new Dictionary(); + public Dictionary Descriptions = new Dictionary(); + public float[] DefaultValues = new float[4]; + } + + + public class TextureInformation + { + public string Name; + public string UniformName; + public int Index; + public string DefaultPath; + public bool IsParam; + public int Sampler; + public TextureType Type = TextureType.Color; + public int Priority = 1; + + public Dictionary Summaries = new Dictionary(); + public Dictionary Descriptions = new Dictionary(); + } + + public class UniformInformation + { + public string Name; + public string UniformName; + public int Offset; + public int Type = 0; + public float[] DefaultValues = new float[4]; + public int Priority = 1; + + public Dictionary Summaries = new Dictionary(); + public Dictionary Descriptions = new Dictionary(); + } + + public class GradientInformation + { + public string Name; + public string UniformName; + public int Offset; + + public Gradient.State Data; + public int Priority = 1; + + public Dictionary Summaries = new Dictionary(); + public Dictionary Descriptions = new Dictionary(); + } + } +} + +#endif \ No newline at end of file diff --git a/Assets/Effekseer/Editor/EffekseerMaterialInformation.cs.meta b/Assets/Effekseer/Editor/EffekseerMaterialInformation.cs.meta new file mode 100644 index 0000000..efd26e9 --- /dev/null +++ b/Assets/Effekseer/Editor/EffekseerMaterialInformation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 77f164a1d8d2e124ea7ddd6b150457b8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Effekseer/External/HDRP/EffekseerRendererHDRP.cs b/Assets/Effekseer/External/HDRP/EffekseerRendererHDRP.cs index 14d375a..2f779e1 100644 --- a/Assets/Effekseer/External/HDRP/EffekseerRendererHDRP.cs +++ b/Assets/Effekseer/External/HDRP/EffekseerRendererHDRP.cs @@ -1,8 +1,8 @@ #if EFFEKSEER_HDRP_SUPPORT +using Effekseer.Internal; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; -using Effekseer.Internal; namespace Effekseer { diff --git a/Assets/Effekseer/External/URP/EffekseerURPRenderPassFeature.cs b/Assets/Effekseer/External/URP/EffekseerURPRenderPassFeature.cs index 02b190b..fbf28d1 100644 --- a/Assets/Effekseer/External/URP/EffekseerURPRenderPassFeature.cs +++ b/Assets/Effekseer/External/URP/EffekseerURPRenderPassFeature.cs @@ -27,19 +27,6 @@ public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetI cmd.SetGlobalTexture(sourceTex, source); cmd.DrawProcedural(Matrix4x4.identity, blitMaterial, 0, MeshTopology.Quads, 4); } - - public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, Material material) - { - CoreUtils.SetRenderTarget( - cmd, - dest, - RenderBufferLoadAction.Load, - RenderBufferStoreAction.Store, - ClearFlag.None, - Color.black); - cmd.SetGlobalTexture(sourceTex, source); - cmd.DrawProcedural(Matrix4x4.identity, material, 0, MeshTopology.Quads, 4); - } } public class EffekseerURPRenderPassFeature : ScriptableRendererFeature diff --git a/Assets/Effekseer/Materials/EffekseerShaderAdDistortionPS.cginc b/Assets/Effekseer/Materials/EffekseerShaderAdDistortionPS.cginc index e1471a2..714fafb 100644 --- a/Assets/Effekseer/Materials/EffekseerShaderAdDistortionPS.cginc +++ b/Assets/Effekseer/Materials/EffekseerShaderAdDistortionPS.cginc @@ -77,7 +77,7 @@ float4 frag(const PS_Input Input) Output.a = Output.a * Input.Color.a; - ApplyFlipbook(Output, _colorTex, sampler_colorTex, fFlipbookParameter, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, advancedParam.FlipbookRate, false); + ApplyFlipbook(Output, _colorTex, sampler_colorTex, flipbookParameter1, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, advancedParam.FlipbookRate, false); // apply alpha texture float4 AlphaTexColor = _alphaTex.Sample(sampler_alphaTex, advancedParam.AlphaUV + UVOffset); diff --git a/Assets/Effekseer/Materials/EffekseerShaderAdLitUnlitPS.cginc b/Assets/Effekseer/Materials/EffekseerShaderAdLitUnlitPS.cginc index e6c6d69..6d9f363 100644 --- a/Assets/Effekseer/Materials/EffekseerShaderAdLitUnlitPS.cginc +++ b/Assets/Effekseer/Materials/EffekseerShaderAdLitUnlitPS.cginc @@ -131,7 +131,7 @@ float4 frag(const PS_Input Input) half3x3((half3)Input.WorldT, (half3)Input.WorldB, (half3)Input.WorldN))); #endif - ApplyFlipbook(Output, _colorTex, sampler_colorTex, fFlipbookParameter, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, advancedParam.FlipbookRate, convColorSpace); + ApplyFlipbook(Output, _colorTex, sampler_colorTex, flipbookParameter1, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, advancedParam.FlipbookRate, convColorSpace); // apply alpha texture float4 AlphaTexColor = ConvertFromSRGBTexture(_alphaTex.Sample(sampler_alphaTex, advancedParam.AlphaUV + UVOffset), convColorSpace); diff --git a/Assets/Effekseer/Materials/EffekseerShaderAdVS.cginc b/Assets/Effekseer/Materials/EffekseerShaderAdVS.cginc index 0d30064..04540ee 100644 --- a/Assets/Effekseer/Materials/EffekseerShaderAdVS.cginc +++ b/Assets/Effekseer/Materials/EffekseerShaderAdVS.cginc @@ -78,7 +78,7 @@ float2 GetFlipbookOneSizeUV(float DivideX, float DivideY) return (float2(1.0, 1.0) / float2(DivideX, DivideY)); } -float2 GetFlipbookOriginUV(float2 FlipbookUV, float FlipbookIndex, float DivideX, float DivideY) +float2 GetFlipbookOriginUV(float2 FlipbookUV, float FlipbookIndex, float DivideX, float2 flipbookOneSize, float2 flipbookOffset) { float2 DivideIndex; @@ -89,16 +89,11 @@ float2 GetFlipbookOriginUV(float2 FlipbookUV, float FlipbookIndex, float DivideX #endif DivideIndex.y = int(FlipbookIndex) / int(DivideX); - float2 FlipbookOneSize = GetFlipbookOneSizeUV(DivideX, DivideY); - float2 UVOffset = DivideIndex * FlipbookOneSize; - - float2 OriginUV = FlipbookUV - UVOffset; - OriginUV *= float2(DivideX, DivideY); - - return OriginUV; + float2 UVOffset = DivideIndex * flipbookOneSize + flipbookOffset; + return FlipbookUV - UVOffset; } -float2 GetFlipbookUVForIndex(float2 OriginUV, float Index, float DivideX, float DivideY) +float2 GetFlipbookUVForIndex(float2 OriginUV, float Index, float DivideX, float2 flipbookOneSize, float2 flipbookOffset) { float2 DivideIndex; #ifdef __OPENGL2__ @@ -108,14 +103,20 @@ float2 GetFlipbookUVForIndex(float2 OriginUV, float Index, float DivideX, float #endif DivideIndex.y = int(Index) / int(DivideX); - float2 FlipbookOneSize = GetFlipbookOneSizeUV(DivideX, DivideY); - - return (OriginUV * FlipbookOneSize) + (DivideIndex * FlipbookOneSize); + return OriginUV + DivideIndex * flipbookOneSize + flipbookOffset; } -void ApplyFlipbookVS(inout float flipbookRate, inout float2 flipbookUV, float4 flipbookParameter, float flipbookIndex, float2 uv, float2 uvInversed) +void ApplyFlipbookVS(inout float flipbookRate, inout float2 flipbookUV, float4 flipbookParameter1, float4 flipbookParameter2, float flipbookIndex, float2 uv, float2 uvInversed) { - if (flipbookParameter.x > 0) + const float flipbookEnabled = flipbookParameter1.x; + const float flipbookLoopType = flipbookParameter1.y; + const float divideX = flipbookParameter1.z; + const float divideY = flipbookParameter1.w; + + const float2 flipbookOneSize = flipbookParameter2.xy; + const float2 flipbookOffset = flipbookParameter2.zw; + + if (flipbookEnabled > 0) { flipbookRate = frac(flipbookIndex); @@ -124,10 +125,10 @@ void ApplyFlipbookVS(inout float flipbookRate, inout float2 flipbookUV, float4 f float NextIndex = Index + IndexOffset; - float FlipbookMaxCount = (flipbookParameter.z * flipbookParameter.w); + float FlipbookMaxCount = (divideX * divideY); // loop none - if (flipbookParameter.y == 0) + if (flipbookLoopType == 0) { if (NextIndex >= FlipbookMaxCount) { @@ -136,13 +137,13 @@ void ApplyFlipbookVS(inout float flipbookRate, inout float2 flipbookUV, float4 f } } // loop - else if (flipbookParameter.y == 1) + else if (flipbookLoopType == 1) { Index %= FlipbookMaxCount; NextIndex %= FlipbookMaxCount; } // loop reverse - else if (flipbookParameter.y == 2) + else if (flipbookLoopType == 2) { bool Reverse = floor(Index / FlipbookMaxCount) % 2 == 1; Index %= FlipbookMaxCount; @@ -161,8 +162,8 @@ void ApplyFlipbookVS(inout float flipbookRate, inout float2 flipbookUV, float4 f float2 notInversedUV = uv; notInversedUV.y = uvInversed.x + uvInversed.y * notInversedUV.y; - float2 OriginUV = GetFlipbookOriginUV(notInversedUV, Index, flipbookParameter.z, flipbookParameter.w); - flipbookUV = GetFlipbookUVForIndex(OriginUV, NextIndex, flipbookParameter.z, flipbookParameter.w); + float2 OriginUV = GetFlipbookOriginUV(notInversedUV, Index, divideX, flipbookOneSize, flipbookOffset); + flipbookUV = GetFlipbookUVForIndex(OriginUV, NextIndex, divideX, flipbookOneSize, flipbookOffset); flipbookUV.y = uvInversed.x + uvInversed.y * flipbookUV.y; } } @@ -195,7 +196,8 @@ void ApplyFlipbookVS(inout float flipbookRate, inout float2 flipbookUV, float4 f // float4 fBlendUVDistortionUV[__INST__]; // #endif -float4 fFlipbookParameter; // x:enable, y:loopType, z:divideX, w:divideY +float4 flipbookParameter1; // x:enable, y:loopType, z:divideX, w:divideY +float4 flipbookParameter2; // #ifdef DISABLE_INSTANCE // float4 fFlipbookIndexAndNextRate; @@ -256,7 +258,7 @@ void CalculateAndStoreAdvancedParameter(in float2 uv, in float2 uv1, in float4 a // flipbook interpolation float flipbookRate = 0.0f; float2 flipbookNextIndexUV = 0.0f; - ApplyFlipbookVS(flipbookRate, flipbookNextIndexUV, fFlipbookParameter, flipbookIndexAndNextRate, uv1, mUVInversed); + ApplyFlipbookVS(flipbookRate, flipbookNextIndexUV, flipbookParameter1, flipbookParameter2, flipbookIndexAndNextRate, uv1, mUVInversed); vsoutput.Blend_FBNextIndex_UV.zw = flipbookNextIndexUV; vsoutput.UV_Others.z = flipbookRate; @@ -381,7 +383,8 @@ VS_Output vert(VS_Input i) //float4x4 mProj; float4 mUVInversed; -float4 fFlipbookParameter; // x:enable, y:loopType, z:divideX, w:divideY +float4 flipbookParameter1; // x:enable, y:loopType, z:divideX, w:divideY +float4 flipbookParameter2; //}; #if defined(ENABLE_LIGHTING) || defined(ENABLE_DISTORTION) @@ -452,7 +455,7 @@ void CalculateAndStoreAdvancedParameter(in VS_Input_Internal vsinput, inout VS_O // flipbook interpolation float flipbookRate = 0.0f; float2 flipbookNextIndexUV = 0.0f; - ApplyFlipbookVS(flipbookRate, flipbookNextIndexUV, fFlipbookParameter, vsinput.FlipbookIndex, vsoutput.UV_Others.xy, mUVInversed); + ApplyFlipbookVS(flipbookRate, flipbookNextIndexUV, flipbookParameter1, flipbookParameter2, vsinput.FlipbookIndex, vsoutput.UV_Others.xy, mUVInversed); vsoutput.Blend_FBNextIndex_UV.zw = flipbookNextIndexUV; vsoutput.UV_Others.z = flipbookRate; diff --git a/Assets/Effekseer/Materials/EffekseerShaderDistortionPS.cginc b/Assets/Effekseer/Materials/EffekseerShaderDistortionPS.cginc index 44ecca9..10c0866 100644 --- a/Assets/Effekseer/Materials/EffekseerShaderDistortionPS.cginc +++ b/Assets/Effekseer/Materials/EffekseerShaderDistortionPS.cginc @@ -13,7 +13,7 @@ SamplerState sampler_depthTex : register(s2); float4 g_scale; float4 mUVInversedBack; -float4 fFlipbookParameter; // x:enable, y:interpolationType +float4 flipbookParameter1; // x:enable, y:interpolationType float4 fUVDistortionParameter; // x:intensity, y:blendIntensity, zw:uvInversed diff --git a/Assets/Effekseer/Materials/EffekseerShaderLitUnlitPS.cginc b/Assets/Effekseer/Materials/EffekseerShaderLitUnlitPS.cginc index 89df764..d2d7597 100644 --- a/Assets/Effekseer/Materials/EffekseerShaderLitUnlitPS.cginc +++ b/Assets/Effekseer/Materials/EffekseerShaderLitUnlitPS.cginc @@ -5,7 +5,7 @@ float4 fLightDirection; float4 fLightColor; float4 fLightAmbient; -float4 fFlipbookParameter; // x:enable, y:interpolationType +float4 flipbookParameter1; // x:enable, y:interpolationType float4 fUVDistortionParameter; // x:intensity, y:blendIntensity, zw:uvInversed diff --git a/Assets/Effekseer/Plugins/Android/libs/arm64-v8a/libEffekseerUnity.so b/Assets/Effekseer/Plugins/Android/libs/arm64-v8a/libEffekseerUnity.so index 9d95a10..8df1238 100644 Binary files a/Assets/Effekseer/Plugins/Android/libs/arm64-v8a/libEffekseerUnity.so and b/Assets/Effekseer/Plugins/Android/libs/arm64-v8a/libEffekseerUnity.so differ diff --git a/Assets/Effekseer/Plugins/Android/libs/armeabi-v7a/libEffekseerUnity.so b/Assets/Effekseer/Plugins/Android/libs/armeabi-v7a/libEffekseerUnity.so index 6ebea1c..be2a38f 100644 Binary files a/Assets/Effekseer/Plugins/Android/libs/armeabi-v7a/libEffekseerUnity.so and b/Assets/Effekseer/Plugins/Android/libs/armeabi-v7a/libEffekseerUnity.so differ diff --git a/Assets/Effekseer/Plugins/Android/libs/x86/libEffekseerUnity.so b/Assets/Effekseer/Plugins/Android/libs/x86/libEffekseerUnity.so index a9146d6..05029c6 100644 Binary files a/Assets/Effekseer/Plugins/Android/libs/x86/libEffekseerUnity.so and b/Assets/Effekseer/Plugins/Android/libs/x86/libEffekseerUnity.so differ diff --git a/Assets/Effekseer/Plugins/EffekseerUnity.bundle/Contents/MacOS/EffekseerUnity b/Assets/Effekseer/Plugins/EffekseerUnity.bundle/Contents/MacOS/EffekseerUnity index e13a293..e65cd1a 100644 Binary files a/Assets/Effekseer/Plugins/EffekseerUnity.bundle/Contents/MacOS/EffekseerUnity and b/Assets/Effekseer/Plugins/EffekseerUnity.bundle/Contents/MacOS/EffekseerUnity differ diff --git a/Assets/Effekseer/Plugins/WebGL/2.0.19-64bit/libEffekseerUnity.bc b/Assets/Effekseer/Plugins/WebGL/2.0.19-64bit/libEffekseerUnity.bc index 69f5b68..7125d07 100644 Binary files a/Assets/Effekseer/Plugins/WebGL/2.0.19-64bit/libEffekseerUnity.bc and b/Assets/Effekseer/Plugins/WebGL/2.0.19-64bit/libEffekseerUnity.bc differ diff --git a/Assets/Effekseer/Plugins/WebGL/libEffekseerUnity.bc b/Assets/Effekseer/Plugins/WebGL/libEffekseerUnity.bc index 00db4c3..e21bb5e 100644 Binary files a/Assets/Effekseer/Plugins/WebGL/libEffekseerUnity.bc and b/Assets/Effekseer/Plugins/WebGL/libEffekseerUnity.bc differ diff --git a/Assets/Effekseer/Plugins/iOS/libEffekseerUnity.a b/Assets/Effekseer/Plugins/iOS/libEffekseerUnity.a index 98be1bc..b3c4edd 100644 Binary files a/Assets/Effekseer/Plugins/iOS/libEffekseerUnity.a and b/Assets/Effekseer/Plugins/iOS/libEffekseerUnity.a differ diff --git a/Assets/Effekseer/Plugins/x86/EffekseerUnity.dll b/Assets/Effekseer/Plugins/x86/EffekseerUnity.dll index 418c252..3f40d80 100644 Binary files a/Assets/Effekseer/Plugins/x86/EffekseerUnity.dll and b/Assets/Effekseer/Plugins/x86/EffekseerUnity.dll differ diff --git a/Assets/Effekseer/Plugins/x86_64/EffekseerUnity.dll b/Assets/Effekseer/Plugins/x86_64/EffekseerUnity.dll index 6b3af4c..0138c17 100644 Binary files a/Assets/Effekseer/Plugins/x86_64/EffekseerUnity.dll and b/Assets/Effekseer/Plugins/x86_64/EffekseerUnity.dll differ diff --git a/Assets/Effekseer/Scripts/Effekseer.cs b/Assets/Effekseer/Scripts/Effekseer.cs index 10fd81c..ab2b70f 100644 --- a/Assets/Effekseer/Scripts/Effekseer.cs +++ b/Assets/Effekseer/Scripts/Effekseer.cs @@ -253,6 +253,9 @@ public static extern void EffekseerSetRenderTargetProperty(int renderId, [DllImport(pluginName)] public static extern int EffekseerGetRestInstancesCount(); + [DllImport(pluginName)] + public static extern void EffekseerSendTrigger(int handle, int index); + [DllImport(pluginName)] public static extern float EffekseerGetDynamicInput(int handle, int index); @@ -389,6 +392,10 @@ public unsafe struct FlipbookParameters public int LoopType; public int DivideX; public int DivideY; + public float OneSizeX; + public float OneSizeY; + public float OffsetX; + public float OffsetY; } [StructLayout(LayoutKind.Sequential)] diff --git a/Assets/Effekseer/Scripts/EffekseerBlitter.cs b/Assets/Effekseer/Scripts/EffekseerBlitter.cs index 178d88a..e1e2559 100644 --- a/Assets/Effekseer/Scripts/EffekseerBlitter.cs +++ b/Assets/Effekseer/Scripts/EffekseerBlitter.cs @@ -1,12 +1,10 @@ -using UnityEngine; -using UnityEngine.Rendering; +using UnityEngine.Rendering; namespace Effekseer.Internal { public interface IEffekseerBlitter { void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest); - void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, Material material); } public class StandardBlitter : IEffekseerBlitter @@ -15,9 +13,5 @@ public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetI { cmd.Blit(source, dest); } - public void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, Material material) - { - cmd.Blit(source, dest, material); - } } } \ No newline at end of file diff --git a/Assets/Effekseer/Scripts/EffekseerBlitter.cs.meta b/Assets/Effekseer/Scripts/EffekseerBlitter.cs.meta index 7a992b4..9ef88f2 100644 --- a/Assets/Effekseer/Scripts/EffekseerBlitter.cs.meta +++ b/Assets/Effekseer/Scripts/EffekseerBlitter.cs.meta @@ -1,11 +1,3 @@ -fileFormatVersion: 2 -guid: 4f8208fcb9ae28540938947b2550c21b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: +fileFormatVersion: 2 +guid: b181080ec39c4832858c31e0626d34dc +timeCreated: 1655883965 \ No newline at end of file diff --git a/Assets/Effekseer/Scripts/EffekseerEmitter.cs b/Assets/Effekseer/Scripts/EffekseerEmitter.cs index cb8f417..06c5876 100644 --- a/Assets/Effekseer/Scripts/EffekseerEmitter.cs +++ b/Assets/Effekseer/Scripts/EffekseerEmitter.cs @@ -313,6 +313,21 @@ public void SetDynamicInputWithLocalDistance(ref Vector3 localPos) SetDynamicInput(0, localPos.magnitude / cachedMagnification); } + /// + /// Send a trigger signal + /// + /// + /// トリガーの信号を送信する。 + /// + /// + public void SendTrigger(int index) + { + foreach (var handle in handles) + { + Plugin.EffekseerSendTrigger(handle.m_handle, index); + } + } + /// /// Pausing the effect /// true: It will update on Update() diff --git a/Assets/Effekseer/Scripts/EffekseerMaterialAsset.cs b/Assets/Effekseer/Scripts/EffekseerMaterialAsset.cs index 3103b0b..f8d63cd 100644 --- a/Assets/Effekseer/Scripts/EffekseerMaterialAsset.cs +++ b/Assets/Effekseer/Scripts/EffekseerMaterialAsset.cs @@ -48,7 +48,7 @@ public static bool InspectorField(EffekseerMaterialResource res) namespace Effekseer { - public class EffekseerMaterialAsset : ScriptableObject + public partial class EffekseerMaterialAsset : ScriptableObject { [System.Serializable] public enum TextureType @@ -69,6 +69,7 @@ public class TextureProperty [SerializeField] public string UniformName; } + [System.Serializable] public class UniformProperty { @@ -82,6 +83,39 @@ public class UniformProperty public int Count; } + [System.Serializable] + public class GradientProperty + { + public string Name; + + public string UniformName; + + public ColorMarker[] ColorMarkers; + public AlphaMarker[] AlphaMarkers; + + public struct ColorMarker + { + public float Position; + public float ColorR; + public float ColorG; + public float ColorB; + public float Intensity; + } + + public struct AlphaMarker + { + public float Position; + public float Alpha; + } + } + + public enum MaterialRequiredFunctionType : int + { + Gradient = 0, + Noise = 1, + Light = 2, + } + public class ImportingAsset { public byte[] Data = new byte[0]; @@ -93,7 +127,10 @@ public class ImportingAsset public bool HasRefraction = false; public List Textures = new List(); public List Uniforms = new List(); + public List FixedGradients = new List(); + public List Gradients = new List(); public int ShadingModel = 0; + public MaterialRequiredFunctionType[] MaterialRequiredFunctionTypes = new MaterialRequiredFunctionType[0]; } [SerializeField] @@ -111,6 +148,9 @@ public class ImportingAsset [SerializeField] public UniformProperty[] uniforms = new UniformProperty[0]; + [SerializeField] + public GradientProperty[] gradients = new GradientProperty[0]; + [SerializeField] public int CustomData1Count = 0; @@ -190,6 +230,7 @@ public static void CreateAsset(string path, ImportingAsset importingAsset) asset.materialBuffers = importingAsset.Data; asset.uniforms = importingAsset.Uniforms.ToArray(); asset.textures = importingAsset.Textures.ToArray(); + asset.gradients = importingAsset.Gradients.ToArray(); asset.CustomData1Count = importingAsset.CustomData1Count; asset.CustomData2Count = importingAsset.CustomData2Count; asset.HasRefraction = importingAsset.HasRefraction; @@ -259,6 +300,7 @@ static string CreateMainShaderCode(ImportingAsset importingAsset, int stage) baseCode = baseCode.Replace("$F4$", "float4"); baseCode = baseCode.Replace("$TIME$", "_Time.y"); baseCode = baseCode.Replace("$EFFECTSCALE$", "predefined_uniform.y"); + baseCode = baseCode.Replace("$LOCALTIME$", "predefined_uniform.w"); baseCode = baseCode.Replace("$UV$", "uv"); int actualTextureCount = Math.Min(importingAsset.UserTextureSlotMax, importingAsset.Textures.Count); @@ -282,7 +324,7 @@ static string CreateMainShaderCode(ImportingAsset importingAsset, int stage) replacedS = "))"; } - if(importingAsset.Textures[i].Type == TextureType.Color) + if (importingAsset.Textures[i].Type == TextureType.Color) { replacedP = "ConvertFromSRGBTexture(" + replacedP; replacedS = replacedS + ")"; @@ -331,7 +373,29 @@ static Shader CreateShader(string path, ImportingAsset importingAsset) var mainVSCode = CreateMainShaderCode(importingAsset, 0); var mainPSCode = CreateMainShaderCode(importingAsset, 1); - var code = shaderTemplate; + var code = string.Empty; + + var functions = string.Empty; + + if (importingAsset.MaterialRequiredFunctionTypes.Contains(MaterialRequiredFunctionType.Gradient)) + { + functions += ShaderGenerator.gradientTemplate; + } + else if (importingAsset.MaterialRequiredFunctionTypes.Contains(MaterialRequiredFunctionType.Noise)) + { + functions += ShaderGenerator.noiseTemplate; + } + else if (importingAsset.MaterialRequiredFunctionTypes.Contains(MaterialRequiredFunctionType.Light)) + { + functions += lightTemplate; + } + + foreach (var gradient in importingAsset.FixedGradients) + { + functions += ShaderGenerator.GetFixedGradient(gradient.Name, gradient); + } + + code += shaderTemplate; code = code.Replace("@", "#"); string codeProperty = string.Empty; @@ -351,6 +415,16 @@ static Shader CreateShader(string path, ImportingAsset importingAsset) codeUniforms += "float4 " + importingAsset.Uniforms[i].Name + ";" + nl; } + for (int i = 0; i < importingAsset.Gradients.Count; i++) + { + var gradient = importingAsset.Gradients[i]; + + for (int j = 0; j < 13; j++) + { + codeUniforms += "float4 " + gradient.UniformName + "_" + j.ToString() + ";" + nl; + } + } + // replace for usability // HACK for efk_xxx_1 and efk_xxx_12 { @@ -371,7 +445,7 @@ static Shader CreateShader(string path, ImportingAsset importingAsset) } } - + code = code.Replace("%FUNCTIONS%", functions); code = code.Replace("%TEX_PROPERTY%", codeProperty); code = code.Replace("%TEX_VARIABLE%", codeVariable); code = code.Replace("%UNIFORMS%", codeUniforms); @@ -422,6 +496,18 @@ static Shader CreateShader(string path, ImportingAsset importingAsset) return asset; } + const string lightTemplate = @" +float3 GetLightDirection() { + return lightDirection.xyz; +} +float3 GetLightColor() { + return lightColor.xyz; +} +float3 GetLightAmbientColor() { + return lightAmbientColor.xyz; +} +"; + const string shaderTemplate = @" Shader ""EffekseerMaterial/%MATERIAL_NAME%"" { @@ -517,7 +603,7 @@ @pragma multi_compile _ _MODEL_ //PRAGMA_LIT_FLAG @include ""UnityCG.cginc"" - + @if _MATERIAL_REFRACTION_ sampler2D _BackTex; @endif @@ -626,6 +712,7 @@ float CalcDepthFade(float2 screenUV, float meshZ, float softParticleParam) return min(max((depth.x - depth.y) / distance, 0.0), 1.0); } + %FUNCTIONS% ps_input vert(uint id : SV_VertexID, uint inst : SV_InstanceID) { diff --git a/Assets/Effekseer/Scripts/EffekseerRenderer.cs b/Assets/Effekseer/Scripts/EffekseerRenderer.cs index d5d99c1..95c21ef 100644 --- a/Assets/Effekseer/Scripts/EffekseerRenderer.cs +++ b/Assets/Effekseer/Scripts/EffekseerRenderer.cs @@ -98,7 +98,7 @@ public RenderTargetProperty() { } - internal void ApplyToCommandBuffer(CommandBuffer cb, DepthRenderTexture depthRenderTexture, IEffekseerBlitter blitter) + internal void ApplyToCommandBuffer(CommandBuffer cb, DepthRenderTexture depthRenderTexture) { if (depthRenderTexture != null) { @@ -117,13 +117,13 @@ internal void ApplyToCommandBuffer(CommandBuffer cb, DepthRenderTexture depthRen if (renderFeature == RenderFeature.PostProcess) { - blitter.Blit(cb, BuiltinRenderTextureType.None, depthRenderTexture.renderTexture, grabDepthMat); + cb.Blit(null, depthRenderTexture.renderTexture, grabDepthMat); } else if (renderFeature == RenderFeature.URP) { if (canGrabDepth) { - blitter.Blit(cb, BuiltinRenderTextureType.None,depthRenderTexture.renderTexture, grabDepthMat); + cb.Blit(null, depthRenderTexture.renderTexture, grabDepthMat); } else { @@ -176,7 +176,7 @@ internal void ApplyToCommandBuffer(CommandBuffer cb, BackgroundRenderTexture bac Viewport.y / colorTargetRenderTexture.height)); cb.SetRenderTarget(backgroundRenderTexture.renderTexture); cb.ClearRenderTarget(true, true, new Color(0, 0, 0)); - blitter.Blit(cb, colorTargetIdentifier, backgroundRenderTexture.renderTexture, m); + cb.Blit(colorTargetIdentifier, backgroundRenderTexture.renderTexture, m); } else { @@ -189,7 +189,7 @@ internal void ApplyToCommandBuffer(CommandBuffer cb, BackgroundRenderTexture bac Viewport.y / colorTargetRenderTexture.height)); cb.SetRenderTarget(backgroundRenderTexture.renderTexture); cb.ClearRenderTarget(true, true, new Color(0, 0, 0)); - blitter.Blit(cb, colorTargetIdentifier, backgroundRenderTexture.renderTexture, m); + cb.Blit(colorTargetIdentifier, backgroundRenderTexture.renderTexture, m); } } else if (isRequiredToCopyBackground) diff --git a/Assets/Effekseer/Scripts/EffekseerRendererNative.cs b/Assets/Effekseer/Scripts/EffekseerRendererNative.cs index bb7ae0c..2246fe8 100644 --- a/Assets/Effekseer/Scripts/EffekseerRendererNative.cs +++ b/Assets/Effekseer/Scripts/EffekseerRendererNative.cs @@ -58,8 +58,8 @@ public RenderPath(Camera camera, CameraEvent cameraEvent, int renderId, bool isC #endif } - public void Init(bool enableDistortion, bool enableDepth, RenderTargetProperty renderTargetProperty, IEffekseerBlitter blitter - , StereoRendererUtil.StereoRenderingTypes stereoRenderingType = StereoRendererUtil.StereoRenderingTypes.None) + public void Init(bool enableDistortion, bool enableDepth, RenderTargetProperty renderTargetProperty, + IEffekseerBlitter blitter, StereoRendererUtil.StereoRenderingTypes stereoRenderingType = StereoRendererUtil.StereoRenderingTypes.None) { this.isDistortionEnabled = enableDistortion; isDepthEnabled = enableDepth; @@ -155,7 +155,7 @@ private void SetupEffekseerRenderCommandBuffer( { if (renderTargetProperty != null) { - renderTargetProperty.ApplyToCommandBuffer(cmbBuf, this.depthTexture, blitter); + renderTargetProperty.ApplyToCommandBuffer(cmbBuf, this.depthTexture); if (renderTargetProperty.Viewport.width > 0) { diff --git a/Assets/Effekseer/Scripts/EffekseerRendererUnity.cs b/Assets/Effekseer/Scripts/EffekseerRendererUnity.cs index 64f99b6..147f5c1 100644 --- a/Assets/Effekseer/Scripts/EffekseerRendererUnity.cs +++ b/Assets/Effekseer/Scripts/EffekseerRendererUnity.cs @@ -418,7 +418,7 @@ struct Vertex internal class EffekseerRendererUnity : IEffekseerRenderer { const CameraEvent cameraEvent = CameraEvent.AfterForwardAlpha; - private IEffekseerBlitter standardBlitter = new StandardBlitter(); + private StandardBlitter standardBlitter = new StandardBlitter(); class MaterialPropCollection { @@ -673,7 +673,7 @@ public ComputeBuffer Get(int stride, bool rewuireToAllocate) { if (!HasBuffer(stride)) { - if(!rewuireToAllocate) + if (!rewuireToAllocate) { return null; } @@ -850,7 +850,7 @@ public bool IsValid(RenderTargetProperty renderTargetProperty) { if (this.isDistortionEnabled != EffekseerRendererUtils.IsDistortionEnabled) return false; if (this.isDepthEnabled != EffekseerRendererUtils.IsDepthEnabled) return false; - + if (depthTexture != null) { var targetSize = BackgroundRenderTexture.GetRequiredSize(this.camera, renderTargetProperty); @@ -1208,7 +1208,7 @@ public void Render(Camera camera, RenderTargetProperty renderTargetProperty, Com { if (renderTargetProperty != null) { - renderTargetProperty.ApplyToCommandBuffer(path.commandBuffer, path.depthTexture, blitter); + renderTargetProperty.ApplyToCommandBuffer(path.commandBuffer, path.depthTexture); if (renderTargetProperty.Viewport.width > 0) { @@ -1289,8 +1289,6 @@ public void Render(Camera camera, RenderTargetProperty renderTargetProperty, Com } RenderInternal(path.commandBuffer, path.computeBufferFront, path.materiaProps, path.modelBuffers, path.customDataBuffers, path.renderTexture, path.depthTexture); - - } Texture GetCachedTexture(IntPtr key, BackgroundRenderTexture background, DepthRenderTexture depth, DummyTextureType type) @@ -1344,7 +1342,6 @@ unsafe void RenderInternal(CommandBuffer commandBuffer, ComputeBufferCollection } } } - } unsafe void RenderSprite(Plugin.UnityRenderParameter parameter, IntPtr infoBuffer, CommandBuffer commandBuffer, ComputeBufferCollection computeBuffer, MaterialPropCollection matPropCol, BackgroundRenderTexture background, DepthRenderTexture depth) @@ -1360,7 +1357,7 @@ unsafe void RenderSprite(Plugin.UnityRenderParameter parameter, IntPtr infoBuffe prop.SetFloat("buf_offset", parameter.VertexBufferOffset / parameter.VertexBufferStride); Debug.Assert(computeBuffer.HasBuffer(parameter.VertexBufferStride)); - var vertexBuffer = computeBuffer.Get(parameter.VertexBufferStride,false); + var vertexBuffer = computeBuffer.Get(parameter.VertexBufferStride, false); if (vertexBuffer == null) { Debug.LogWarning("Invalid allocation"); @@ -1380,7 +1377,7 @@ unsafe void RenderSprite(Plugin.UnityRenderParameter parameter, IntPtr infoBuffe if (isAdvanced) { var bufAd = computeBuffer.Get(sizeof(Effekseer.Plugin.AdvancedVertexParameter), false); - if(bufAd == null) + if (bufAd == null) { Debug.LogWarning("Invalid allocation"); return; @@ -1446,11 +1443,7 @@ unsafe void RenderSprite(Plugin.UnityRenderParameter parameter, IntPtr infoBuffe } } - for (int ui = 0; ui < efkMaterial.asset.uniforms.Length; ui++) - { - var f = ((float*)(((byte*)infoBuffer.ToPointer()) + parameter.UniformBufferOffset)); - prop.SetVector(efkMaterial.asset.uniforms[ui].Name, new Vector4(f[ui * 4 + 0], f[ui * 4 + 1], f[ui * 4 + 2], f[ui * 4 + 3])); - } + AssignUniforms(parameter, infoBuffer, prop, efkMaterial); if (parameter.IsRefraction > 0 && background != null) { @@ -1491,6 +1484,30 @@ unsafe void RenderSprite(Plugin.UnityRenderParameter parameter, IntPtr infoBuffe } + private static unsafe void AssignUniforms(Plugin.UnityRenderParameter parameter, IntPtr infoBuffer, MaterialPropertyBlock prop, UnityRendererMaterial efkMaterial) + { + int uniformOffset = 0; + for (int ui = 0; ui < efkMaterial.asset.uniforms.Length; ui++) + { + var f = ((float*)(((byte*)infoBuffer.ToPointer()) + parameter.UniformBufferOffset)); + prop.SetVector(efkMaterial.asset.uniforms[ui].Name, new Vector4(f[uniformOffset + 0], f[uniformOffset + 1], f[uniformOffset + 2], f[uniformOffset + 3])); + uniformOffset += 4; + } + + for (int gi = 0; gi < efkMaterial.asset.gradients.Length; gi++) + { + var gradient = efkMaterial.asset.gradients[gi]; + + var f = ((float*)(((byte*)infoBuffer.ToPointer()) + parameter.UniformBufferOffset)); + + for (int j = 0; j < 13; j++) + { + prop.SetVector(gradient.UniformName + "_" + j.ToString(), new Vector4(f[uniformOffset + 0], f[uniformOffset + 1], f[uniformOffset + 2], f[uniformOffset + 3])); + uniformOffset += 4; + } + } + } + unsafe void RenderModdel(Plugin.UnityRenderParameter parameter, IntPtr infoBuffer, CommandBuffer commandBuffer, MaterialPropCollection matPropCol, ModelBufferCollection modelBufferCol1, CustomDataBufferCollection customDataBuffers, BackgroundRenderTexture background, DepthRenderTexture depth) { // Draw model @@ -1621,12 +1638,7 @@ unsafe void RenderModdel(Plugin.UnityRenderParameter parameter, IntPtr infoBuffe } } - for (int ui = 0; ui < efkMaterial.asset.uniforms.Length; ui++) - { - var f = ((float*)(((byte*)infoBuffer.ToPointer()) + parameter.UniformBufferOffset)); - var uniform = new Vector4(f[ui * 4 + 0], f[ui * 4 + 1], f[ui * 4 + 2], f[ui * 4 + 3]); - prop.SetVector(efkMaterial.asset.uniforms[ui].Name, uniform); - } + AssignUniforms(parameter, infoBuffer, prop, efkMaterial); // CustomData if (efkMaterial.asset.CustomData1Count > 0) @@ -1779,12 +1791,18 @@ unsafe void ApplyTextures(in Plugin.UnityRenderParameter parameter, MaterialProp void ApplyAdvancedParameter(in Plugin.UnityRenderParameter parameter, MaterialPropertyBlock prop) { - prop.SetVector("fFlipbookParameter", new Vector4( + prop.SetVector("flipbookParameter1", new Vector4( parameter.FlipbookParams.Enable, parameter.FlipbookParams.LoopType, parameter.FlipbookParams.DivideX, parameter.FlipbookParams.DivideY)); + prop.SetVector("flipbookParameter2", new Vector4( + parameter.FlipbookParams.OneSizeX, + parameter.FlipbookParams.OneSizeY, + parameter.FlipbookParams.OffsetX, + parameter.FlipbookParams.OffsetY)); + prop.SetVector("fUVDistortionParameter", new Vector4(parameter.UVDistortionIntensity, parameter.BlendUVDistortionIntensity, 1.0f, 0.0f)); prop.SetVector("fBlendTextureParameter", new Vector4(parameter.TextureBlendType, 0.0f, 0.0f, 0.0f)); prop.SetVector("fFalloffParameter", new Vector4(parameter.EnableFalloff, parameter.FalloffParam.ColorBlendType, parameter.FalloffParam.Pow, 0.0f)); diff --git a/Assets/Effekseer/Scripts/EffekseerShaderGenerator.cs b/Assets/Effekseer/Scripts/EffekseerShaderGenerator.cs new file mode 100644 index 0000000..d1e9e41 --- /dev/null +++ b/Assets/Effekseer/Scripts/EffekseerShaderGenerator.cs @@ -0,0 +1,190 @@ +using System; +using System.IO; +using System.Text; +using UnityEngine; +using System.Collections.Generic; + +#if UNITY_EDITOR +using System.Linq; +using UnityEditor; + +namespace Effekseer +{ + partial class EffekseerMaterialAsset + { + class ShaderGenerator + { + + public const string gradientTemplate = @" +struct Gradient +{ + int colorCount; + int alphaCount; + int reserved1; + int reserved2; + float4 colors[8]; + float2 alphas[8]; +}; + +float LinearStep(float s, float e, float v) { + return clamp((v - s) / (e - s), 0.0, 1.0); +} + +float4 SampleGradient(Gradient gradient, float t) { + float t_clamp = clamp(t, 0.0, 1.0); + float3 color = gradient.colors[0].xyz; + for(int i = 1; i < 8; i++) { + float ratio = LinearStep(gradient.colors[i-1].w, gradient.colors[i].w, t_clamp); + color = LERP(color, gradient.colors[i].xyz, ratio); + } + + float alpha = gradient.alphas[0].x; + for(int i = 1; i < 8; i++) { + float ratio = LinearStep(gradient.alphas[i-1].y, gradient.alphas[i].y, t_clamp); + alpha = LERP(alpha, gradient.alphas[i].x, ratio); + } + return float4(color, alpha); +} + +Gradient GradientParameter(float4 param_v, float4 param_c1, float4 param_c2, float4 param_c3, float4 param_c4, float4 param_c5, float4 param_c6, float4 param_c7, float4 param_c8, float4 param_a1, float4 param_a2, float4 param_a3, float4 param_a4) +{ + Gradient g; + g.colorCount = int(param_v.x); + g.alphaCount = int(param_v.y); + g.reserved1 = int(param_v.z); + g.reserved2 = int(param_v.w); + g.colors[0] = param_c1; + g.colors[1] = param_c2; + g.colors[2] = param_c3; + g.colors[3] = param_c4; + g.colors[4] = param_c5; + g.colors[5] = param_c6; + g.colors[6] = param_c7; + g.colors[7] = param_c8; + g.alphas[0].xy = param_a1.xy; + g.alphas[1].xy = param_a1.zw; + g.alphas[2].xy = param_a2.xy; + g.alphas[3].xy = param_a2.zw; + g.alphas[4].xy = param_a3.xy; + g.alphas[5].xy = param_a3.zw; + g.alphas[6].xy = param_a4.xy; + g.alphas[7].xy = param_a4.zw; + return g; +} + +"; + + public const string noiseTemplate = @" + +float Rand2(float2 n) { + return FRAC(sin(dot(n, float2(12.9898, 78.233))) * 43758.5453123); +} + +float SimpleNoise_Block(float2 uv) { + int2 uvi = int2(floor(uv)); + float2 uvf = FRAC(uv); + uvf = uvf * uvf * (3.0 - 2.0 * uvf); + float x0 = LERP(Rand2(float2(uvi + int2(0, 0))), Rand2(float2(uvi + int2(1, 0))), uvf.x); + float x1 = LERP(Rand2(float2(uvi + int2(0, 1))), Rand2(float2(uvi + int2(1, 1))), uvf.x); + return LERP(x0, x1, uvf.y); +} + +float SimpleNoise(float2 uv, float scale) { + const int loop = 3; + float ret = 0.0; + for(int i = 0; i < loop; i++) { + float duration = pow(2.0, float(i)); + float intensity = pow(0.5, float(loop-i)); + ret += SimpleNoise_Block(uv * scale / duration) * intensity; + } + + return ret; +} + +"; + + public static string GetFixedGradient(string name, GradientProperty gradient) + { + var nl = Environment.NewLine; + string ss = string.Empty; + int keyMax = 8; + + ss += "Gradient " + name + "() {" + nl; + ss += "Gradient g = (Gradient)0;" + nl; + ss += "g.colorCount = " + gradient.ColorMarkers.Length + ";" + nl; + ss += "g.alphaCount = " + gradient.AlphaMarkers.Length + ";" + nl; + ss += "g.reserved1 = 0;" + nl; + ss += "g.reserved2 = 0;" + nl; + + GradientProperty.ColorMarker getColorKey(GradientProperty g, int index) + { + if (g.ColorMarkers.Length == 0) + { + GradientProperty.ColorMarker key = new GradientProperty.ColorMarker(); + key.ColorR = 1.0f; + key.ColorG = 1.0f; + key.ColorB = 1.0f; + key.Intensity = 1.0f; + key.Position = 0.0f; + return key; + } + else + { + if (g.ColorMarkers.Length <= index) + { + var key = g.ColorMarkers[g.ColorMarkers.Length - 1]; + key.Position += index; + return key; + } + + return g.ColorMarkers[index]; + } + }; + + GradientProperty.AlphaMarker getAlphaKey(GradientProperty g, int index) + { + if (g.AlphaMarkers.Length == 0) + { + GradientProperty.AlphaMarker key; + key.Alpha = 1.0f; + key.Position = 0.0f; + return key; + } + else + { + if (g.AlphaMarkers.Length <= index) + { + var key = g.AlphaMarkers[g.AlphaMarkers.Length - 1]; + key.Position += index; + return key; + } + + return g.AlphaMarkers[index]; + } + }; + + for (int i = 0; i < keyMax; i++) + { + var key = getColorKey(gradient, i); + ss += "g.colors[" + i + "].x = " + key.ColorR * key.Intensity + ";" + nl; + ss += "g.colors[" + i + "].y = " + key.ColorG * key.Intensity + ";" + nl; + ss += "g.colors[" + i + "].z = " + key.ColorB * key.Intensity + ";" + nl; + ss += "g.colors[" + i + "].w = " + key.Position + ";" + nl; + } + + for (int i = 0; i < keyMax; i++) + { + var key = getAlphaKey(gradient, i); + ss += "g.alphas[" + i + "].x = " + key.Alpha + ";" + nl; + ss += "g.alphas[" + i + "].y = " + key.Position + ";" + nl; + } + + ss += "return g; }" + nl; + + return ss; + } + } + } +} + +#endif \ No newline at end of file diff --git a/Assets/Effekseer/Scripts/EffekseerShaderGenerator.cs.meta b/Assets/Effekseer/Scripts/EffekseerShaderGenerator.cs.meta new file mode 100644 index 0000000..0bf52c2 --- /dev/null +++ b/Assets/Effekseer/Scripts/EffekseerShaderGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0aca3e3d5781f30409bf6cd9463b22f4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Effekseer/package.json b/Assets/Effekseer/package.json index 3b4ad0b..69de5df 100644 --- a/Assets/Effekseer/package.json +++ b/Assets/Effekseer/package.json @@ -1,7 +1,7 @@ { "name": "org.effekseer.effekseerforunity", "description": "", - "version": "1.62.6", + "version": "1.70.0", "unity": "2019.4", "displayName": "EffekseerForUnity" } diff --git a/README.md b/README.md index bbd8138..28ada87 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,8 @@ Please add this address from PackageManager in Unity It is better to remove Unity caches when you replace a unitypackage version to git repository -## 1.6 +## 1.7 ``` https://github.com/effekseer/EffekseerForUnity_Release.git?path=Assets/Effekseer -``` - -## Pre version - -``` -https://github.com/effekseer/EffekseerForUnity_Release.git?path=Assets/Effekseer#170alpha4 ``` \ No newline at end of file