diff options
| author | Freya Murphy <freya@freyacat.org> | 2024-12-27 00:56:58 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2024-12-27 00:58:02 -0500 |
| commit | 799e6680d40119dc9c2a9e0b320054a40324bebe (patch) | |
| tree | dbcd308d59eb6e4f937a5547dd77d9f91d4fec20 /VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables | |
| parent | move to self host (diff) | |
| download | unityprojects-799e6680d40119dc9c2a9e0b320054a40324bebe.tar.gz unityprojects-799e6680d40119dc9c2a9e0b320054a40324bebe.tar.bz2 unityprojects-799e6680d40119dc9c2a9e0b320054a40324bebe.zip | |
VRCSDK3Avatars found!
Diffstat (limited to 'VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables')
22 files changed, 747 insertions, 0 deletions
diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/EnableProperty.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/EnableProperty.cs new file mode 100644 index 00000000..d1b532a3 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/EnableProperty.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; + +namespace Poiyomi.ModularShaderSystem +{ + [Serializable] + public class EnableProperty : Property, IEquatable<EnableProperty> + { + public int EnableValue; + + public EnableProperty(string name, string displayName, int enableValue) + { + Name = name; + DisplayName = displayName; + Type = "Float"; + DefaultValue = "0.1"; + Attributes = new List<string>(); + + EnableValue = enableValue; + } + + public override Variable ToVariable() + { + Variable variable = new Variable(); + variable.Name = Name; + variable.Type = VariableType.Float; + return variable; + } + + public EnableProperty(string name, int enableValue) : this(name, name, enableValue){} + + bool IEquatable<EnableProperty>.Equals(EnableProperty other) + { + return Equals(other); + } + + public override bool Equals(object obj) + { + if (obj is Property other) + return Name == other.Name; + + return false; + } + + public static bool operator == (EnableProperty left, EnableProperty right) + { + return left?.Equals(right) ?? right is null; + } + + public static bool operator !=(EnableProperty left, EnableProperty right) + { + return !(left == right); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/EnableProperty.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/EnableProperty.cs.meta new file mode 100644 index 00000000..072ef649 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/EnableProperty.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2f78beee5aa767f4aaf5b933b0634ec0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModularShader.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModularShader.cs new file mode 100644 index 00000000..ec6cc473 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModularShader.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Poiyomi.ModularShaderSystem +{ + [CreateAssetMenu(fileName = "ModularShader", menuName = MSSConstants.CREATE_PATH + "/Modular Shader", order = 0)] + public class ModularShader : ScriptableObject + { + public string Id; + + public string Name; + + public string Version; + + public string Author; + + public string Description; + + public bool UseTemplatesForProperties; + + public TemplateAsset ShaderPropertiesTemplate; + + public string ShaderPath; + + public TemplateAsset ShaderTemplate; + + public string CustomEditor; + + public List<Property> Properties; + + public List<ShaderModule> BaseModules; + + [HideInInspector] public List<ShaderModule> AdditionalModules; + + public bool LockBaseModules; + + public List<Shader> LastGeneratedShaders; + + [HideInInspector] public string AdditionalSerializedData; + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModularShader.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModularShader.cs.meta new file mode 100644 index 00000000..0210fef6 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModularShader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f8aa43eb5c662824699f2379805fb2c0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: d739c8b030a91b04fb8907203fc97376, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModuleTemplate.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModuleTemplate.cs new file mode 100644 index 00000000..90b97dae --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModuleTemplate.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Serialization; + +namespace Poiyomi.ModularShaderSystem +{ + [Serializable] + public class ModuleTemplate + { + public TemplateAsset Template; + + [FormerlySerializedAs("Keyword")] public List<string> Keywords; + + [FormerlySerializedAs("IsCGOnly")] public bool NeedsVariant; + + public int Queue = 100; + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModuleTemplate.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModuleTemplate.cs.meta new file mode 100644 index 00000000..3818c721 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ModuleTemplate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9d2d3cba893c01945836e28f34ef3502 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Property.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Property.cs new file mode 100644 index 00000000..55ba6f5e --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Property.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using Poiyomi.ModularShaderSystem.UI; + +namespace Poiyomi.ModularShaderSystem +{ + public enum PropertyType + { + Float, + Int, + Range, + Vector, + Color, + Texture2D, + Texture2DArray, + Cube, + CubeArray, + Texture3D + } + + [Serializable] + public class Property : IEquatable<Property> + { + public string Name; + + public string DisplayName; + + public string Type; + + public string DefaultValue; + + public Texture DefaultTextureAsset; + + [PropertyAttribute] + public List<string> Attributes; + + public virtual Variable ToVariable() + { + var variable = new Variable(); + variable.Name = Name; + + switch(Type) + { + case "Float": variable.Type = VariableType.Float; break; + case "Int": variable.Type = VariableType.Float; break; + case "Color": variable.Type = VariableType.Float4; break; + case "Vector": variable.Type = VariableType.Float4; break; + case "2D": variable.Type = VariableType.Texture2D; break; + case "3D": variable.Type = VariableType.Texture3D; break; + case "Cube": variable.Type = VariableType.TextureCube; break; + case "2DArray": variable.Type = VariableType.Texture2DArray; break; + case "CubeArray": variable.Type = VariableType.TextureCubeArray; break; + default: variable.Type = Type.StartsWith("Range") ? VariableType.Float : VariableType.Custom; break; + } + + return variable; + } + + public override bool Equals(object obj) + { + if (obj is Property other) + return Name == other.Name; + + return false; + } + + bool IEquatable<Property>.Equals(Property other) + { + return Equals(other); + } + + public static bool operator == (Property left, Property right) + { + return left?.Equals(right) ?? right is null; + } + + public static bool operator !=(Property left, Property right) + { + return !(left == right); + } + + public override int GetHashCode() + { + int hashCode = (Name != null ? Name.GetHashCode() : 0); + return hashCode; + } + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Property.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Property.cs.meta new file mode 100644 index 00000000..f4722462 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Property.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a3ea212d65d0f404a839a2f2b0a99228 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderFunction.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderFunction.cs new file mode 100644 index 00000000..c2e9eff7 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderFunction.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Serialization; + +namespace Poiyomi.ModularShaderSystem +{ + [Serializable] + public class ShaderFunction + { + public string Name; + + public string AppendAfter; + + [FormerlySerializedAs("Priority")] public short Queue = 100; + + public TemplateAsset ShaderFunctionCode; + + public List<Variable> UsedVariables; + + [FormerlySerializedAs("VariableSinkKeywords")] [FormerlySerializedAs("VariableSinkKeyword")] public List<string> VariableKeywords; + + [FormerlySerializedAs("CodeSinkKeywords")] [FormerlySerializedAs("CodeSinkKeyword")] public List<string> CodeKeywords; + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderFunction.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderFunction.cs.meta new file mode 100644 index 00000000..c528cebc --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderFunction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d721b76d4a9ecd34c98bf2710f25cecc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderModule.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderModule.cs new file mode 100644 index 00000000..d30bb062 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderModule.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace Poiyomi.ModularShaderSystem +{ + [CreateAssetMenu(fileName = "ShaderModule", menuName = MSSConstants.CREATE_PATH + "/Shader Module", order = 0)] + public class ShaderModule : ScriptableObject + { + public string Id; + + public string Name; + + public string Version; + + public string Author; + + public string Description; + + public List<EnableProperty> EnableProperties; + + public List<Property> Properties; + + public List<string> ModuleDependencies; + + public List<string> IncompatibleWith; + + public List<ModuleTemplate> Templates; + + public List<ShaderFunction> Functions; + + [HideInInspector] public string AdditionalSerializedData; + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderModule.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderModule.cs.meta new file mode 100644 index 00000000..5d2a860c --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/ShaderModule.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1039f25740a92fc4292bb1d94d07ad19 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 768d4dfd2b3ad7d4ca6cfe703c398631, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAsset.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAsset.cs new file mode 100644 index 00000000..7c9d2460 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAsset.cs @@ -0,0 +1,48 @@ +using System; +using System.IO; +using System.Reflection; +using UnityEditor; +using UnityEditor.ProjectWindowCallback; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace Poiyomi.ModularShaderSystem +{ + public class TemplateAsset : ScriptableObject + { + public string Template; + + public string[] Keywords; + + public TemplateAsset(string template) + { + Template = template; + } + public TemplateAsset() : this("") { } + + [MenuItem("Assets/Create/" + MSSConstants.CREATE_PATH + "/Template", priority = 9)] + private static void CreateTemplate() + { + Type projectWindowUtilType = typeof(ProjectWindowUtil); + MethodInfo getActiveFolderPath = projectWindowUtilType.GetMethod("GetActiveFolderPath", BindingFlags.Static | BindingFlags.NonPublic); + object obj = getActiveFolderPath.Invoke(null, new object[0]); + string pathToCurrentFolder = obj.ToString(); + string uniquePath = AssetDatabase.GenerateUniqueAssetPath($"{pathToCurrentFolder}/Template.{MSSConstants.TEMPLATE_EXTENSION}"); + + ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAsset>(), uniquePath, null, (string) null); + } + + internal class DoCreateNewAsset : EndNameEditAction + { + public override void Action(int instanceId, string pathName, string resourceFile) + { + File.WriteAllText(pathName, ""); + AssetDatabase.Refresh(); + Object o = AssetDatabase.LoadAssetAtPath<Object>(pathName); + Selection.activeObject = o; + } + + public override void Cancelled(int instanceId, string pathName, string resourceFile) => Selection.activeObject = (Object) null; + } + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAsset.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAsset.cs.meta new file mode 100644 index 00000000..bb13ffbf --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAsset.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5245566ee65d4b4bbd25c70aee47169 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: a4f5b0b9036a57e49866d0e975fede53, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAssetImporter.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAssetImporter.cs new file mode 100644 index 00000000..4e7f7ed4 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAssetImporter.cs @@ -0,0 +1,39 @@ +using System; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using UnityEditor.Experimental.AssetImporters; +using UnityEngine; + +namespace Poiyomi.ModularShaderSystem +{ + + [ScriptedImporter(1, MSSConstants.TEMPLATE_EXTENSION)] + public class TemplateAssetImporter : ScriptedImporter + { + public override void OnImportAsset(AssetImportContext ctx) + { + var subAsset = ScriptableObject.CreateInstance<TemplateAsset>(); + subAsset.Template = File.ReadAllText(ctx.assetPath); + + MatchCollection mk = Regex.Matches(subAsset.Template, @"#K#\w*", RegexOptions.Multiline); + MatchCollection mki = Regex.Matches(subAsset.Template, @"#KI#\w*", RegexOptions.Multiline); + + var mkr = new string[mk.Count + mki.Count]; + for (var i = 0; i < mk.Count; i++) + mkr[i] = mk[i].Value; + for (var i = 0; i < mki.Count; i++) + mkr[mk.Count + i] = mki[i].Value; + + subAsset.Keywords = mkr.Distinct().ToArray(); + + ctx.AddObjectToAsset("Template", subAsset/*, icon*/); + ctx.SetMainObject(subAsset); + } + + public override bool SupportsRemappedAssetType(Type type) + { + return type.IsAssignableFrom(typeof(TemplateAsset)); + } + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAssetImporter.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAssetImporter.cs.meta new file mode 100644 index 00000000..ea57a2e1 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateAssetImporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 836627ab161102f4caef6d73aab2391d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAsset.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAsset.cs new file mode 100644 index 00000000..c8f32504 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAsset.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using UnityEditor; +using UnityEditor.ProjectWindowCallback; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace Poiyomi.ModularShaderSystem +{ + public class TemplateCollectionAsset : ScriptableObject + { + public List<TemplateAsset> Templates; + + public TemplateCollectionAsset() + { + Templates = new List<TemplateAsset>(); + } + + + [MenuItem("Assets/Create/" + MSSConstants.CREATE_PATH + "/Template Collection", priority = 9)] + private static void CreateTemplate() + { + Type projectWindowUtilType = typeof(ProjectWindowUtil); + MethodInfo getActiveFolderPath = projectWindowUtilType.GetMethod("GetActiveFolderPath", BindingFlags.Static | BindingFlags.NonPublic); + object obj = getActiveFolderPath.Invoke(null, new object[0]); + string pathToCurrentFolder = obj.ToString(); + string uniquePath = AssetDatabase.GenerateUniqueAssetPath($"{pathToCurrentFolder}/Template.{MSSConstants.TEMPLATE_COLLECTION_EXTENSION}"); + + ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAsset>(), uniquePath, null, (string) null); + } + + internal class DoCreateNewAsset : EndNameEditAction + { + public override void Action(int instanceId, string pathName, string resourceFile) + { + File.WriteAllText(pathName, ""); + AssetDatabase.Refresh(); + Object o = AssetDatabase.LoadAssetAtPath<Object>(pathName); + Selection.activeObject = o; + } + + public override void Cancelled(int instanceId, string pathName, string resourceFile) => Selection.activeObject = (Object) null; + } + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAsset.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAsset.cs.meta new file mode 100644 index 00000000..f60c5c0d --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAsset.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c670b58f3d80515448cad87058c4e731 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 64d8d3c5a7468a547b7e8cb106f65d0b, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAssetImporter.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAssetImporter.cs new file mode 100644 index 00000000..a1be0cef --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAssetImporter.cs @@ -0,0 +1,86 @@ +using System; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using UnityEditor.Experimental.AssetImporters; +using UnityEngine; + +namespace Poiyomi.ModularShaderSystem +{ + [ScriptedImporter(1, MSSConstants.TEMPLATE_COLLECTION_EXTENSION)] + public class TemplateColletionAssetImporter : ScriptedImporter + { + public override void OnImportAsset(AssetImportContext ctx) + { + var subAsset = ScriptableObject.CreateInstance<TemplateCollectionAsset>(); + + + + using (var sr = new StringReader(File.ReadAllText(ctx.assetPath))) + { + var builder = new StringBuilder(); + string line; + string name = ""; + bool deleteEmptyLine = false; + while ((line = sr.ReadLine()) != null) + { + if (line.Contains("#T#")) + { + if (builder.Length > 0 && !string.IsNullOrWhiteSpace(name)) + SaveSubAsset(ctx, subAsset, builder, name); + + builder = new StringBuilder(); + name = line.Replace("#T#", "").Trim(); + continue; + } + + if (string.IsNullOrEmpty(line)) + { + if (deleteEmptyLine) + continue; + deleteEmptyLine = true; + } + else + { + deleteEmptyLine = false; + } + + builder.AppendLine(line); + } + + if (builder.Length > 0 && !string.IsNullOrWhiteSpace(name)) + SaveSubAsset(ctx, subAsset, builder, name); + } + + ctx.AddObjectToAsset("Collection", subAsset); + ctx.SetMainObject(subAsset); + } + + private static void SaveSubAsset(AssetImportContext ctx, TemplateCollectionAsset asset, StringBuilder builder, string name) + { + var templateAsset = ScriptableObject.CreateInstance<TemplateAsset>(); + templateAsset.Template = builder.ToString(); + templateAsset.name = name; + + MatchCollection mk = Regex.Matches(templateAsset.Template, @"#K#\w*", RegexOptions.Multiline); + MatchCollection mki = Regex.Matches(templateAsset.Template, @"#KI#\w*", RegexOptions.Multiline); + + var mkr = new string[mk.Count + mki.Count]; + for (var i = 0; i < mk.Count; i++) + mkr[i] = mk[i].Value; + for (var i = 0; i < mki.Count; i++) + mkr[mk.Count + i] = mki[i].Value; + + templateAsset.Keywords = mkr.Distinct().ToArray(); + + ctx.AddObjectToAsset(name, templateAsset); + asset.Templates.Add(templateAsset); + } + + public override bool SupportsRemappedAssetType(Type type) + { + return type.IsAssignableFrom(typeof(TemplateAsset)); + } + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAssetImporter.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAssetImporter.cs.meta new file mode 100644 index 00000000..00e685b8 --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/TemplateCollectionAssetImporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b8e1b7bf6f1d9674dbe75fe157540c41 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Variable.cs b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Variable.cs new file mode 100644 index 00000000..892210bc --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Variable.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace Poiyomi.ModularShaderSystem +{ + [Serializable] + public class Variable : IEquatable<Variable> + { + public override int GetHashCode() + { + int hashCode = (Name != null ? Name.GetHashCode() : 0); + return hashCode; + } + + public string Name; + public VariableType Type; + public string CustomType; + + public string GetDefinition() + { + switch (Type) + { + case VariableType.Half: + return $"half {Name};"; + case VariableType.Half2: + return $"half2 {Name};"; + case VariableType.Half3: + return $"half3 {Name};"; + case VariableType.Half4: + return $"half4 {Name};"; + case VariableType.Float: + return $"float {Name};"; + case VariableType.Float2: + return $"float2 {Name};"; + case VariableType.Float3: + return $"float3 {Name};"; + case VariableType.Float4: + return $"float4 {Name};"; + case VariableType.Sampler2D: + return $"sampler2D {Name};"; + case VariableType.SamplerCUBE: + return $"samplerCUBE {Name};"; + case VariableType.Sampler3D: + return $"sampler3D {Name};"; + case VariableType.Texture2D: + return $"Texture2D {Name};"; + case VariableType.Texture2DArray: + return $"Texture2DArray {Name};"; + case VariableType.Texture2DMS: + return $"Texture2DMS {Name};"; + case VariableType.TextureCube: + return $"TextureCube {Name};"; + case VariableType.TextureCubeArray: + return $"TextureCubeArray {Name};"; + case VariableType.Texture3D: + return $"Texture3D {Name};"; + case VariableType.UnityTex2D: + return $"UNITY_DECLARE_TEX2D({Name});"; + case VariableType.UnityTex2DNoSampler: + return $"UNITY_DECLARE_TEX2D_NOSAMPLER({Name});"; + case VariableType.UnityTexCube: + return $"UNITY_DECLARE_TEXCUBE({Name});"; + case VariableType.UnityTexCubeNoSampler: + return $"UNITY_DECLARE_TEXCUBE_NOSAMPLER({Name});"; + case VariableType.UnityTex3D: + return $"UNITY_DECLARE_TEX3D({Name});"; + case VariableType.UnityTex3DNoSampler: + return $"UNITY_DECLARE_TEX3D_NOSAMPLER({Name});"; + case VariableType.UnityTex2DArray: + return $"UNITY_DECLARE_TEX2DARRAY({Name});"; + case VariableType.UnityTex2DArrayNoSampler: + return $"UNITY_DECLARE_TEX2DARRAY_NOSAMPLER({Name});"; + case VariableType.UnityTexCubeArray: + return $"UNITY_DECLARE_TEXCUBEARRAY({Name});"; + case VariableType.UnityTexCubeArrayNoSampler: + return $"UNITY_DECLARE_TEXCUBEARRAY_NOSAMPLER({Name});"; + case VariableType.Custom: + return $"{CustomType} {Name};"; + } + + return ""; + } + + public override bool Equals(object obj) + { + return Equals(obj as Variable); + } + + public bool Equals(Variable other) + { + return other != null && + Name.Equals(other.Name); + } + + public static bool operator ==(Variable left, Variable right) + { + return EqualityComparer<Variable>.Default.Equals(left, right); + } + + public static bool operator !=(Variable left, Variable right) + { + return !(left == right); + } + } + + public enum VariableType + { + Half, + Half2, + Half3, + Half4, + Float, + Float2, + Float3, + Float4, + Sampler2D, + SamplerCUBE, + Sampler3D, + Texture2D, + Texture2DArray, + Texture2DMS, + TextureCube, + TextureCubeArray, + Texture3D, + UnityTex2D, + UnityTex2DNoSampler, + UnityTexCube, + UnityTexCubeNoSampler, + UnityTex3D, + UnityTex3DNoSampler, + UnityTex2DArray, + UnityTex2DArrayNoSampler, + UnityTexCubeArray, + UnityTexCubeArrayNoSampler, + Custom = 999 + } +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Variable.cs.meta b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Variable.cs.meta new file mode 100644 index 00000000..d7b661ef --- /dev/null +++ b/VRCSDK3Avatars/Assets/_PoiyomiShaders/Scripts/ModularShaderSystem/Scriptables/Variable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 162a71be29039a548960264e20bd6969 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |