diff --git a/Assets/lilFurGenerator/Editor/ShaderSetting.asset b/Assets/lilFurGenerator/Editor/ShaderSetting.asset new file mode 100644 index 0000000..8293a77 --- /dev/null +++ b/Assets/lilFurGenerator/Editor/ShaderSetting.asset @@ -0,0 +1,18 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1702bfaf2bdfcf04eb7d482e679e1912, type: 3} + m_Name: ShaderSetting + m_EditorClassIdentifier: + LIL_FEATURE_SHADOW: 1 + LIL_FEATURE_RECEIVE_SHADOW: 0 + LIL_FEATURE_CLIPPING_CANCELLER: 0 + LIL_FEATURE_DISTANCE_FADE: 0 diff --git a/Assets/lilFurGenerator/Editor/ShaderSetting.asset.meta b/Assets/lilFurGenerator/Editor/ShaderSetting.asset.meta new file mode 100644 index 0000000..b8d6b7a --- /dev/null +++ b/Assets/lilFurGenerator/Editor/ShaderSetting.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 13cb99d89b41fd9428d5101d176b6408 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/lilFurGenerator/Editor/lang.txt b/Assets/lilFurGenerator/Editor/lang.txt index 9366846..f2053b2 100644 --- a/Assets/lilFurGenerator/Editor/lang.txt +++ b/Assets/lilFurGenerator/Editor/lang.txt @@ -11,8 +11,10 @@ sLength Length 長さ 길이 长度 長度 sLengthMask Length Mask 長さマスク 길이 마스크 长度蒙版 長度蒙版 sVector Vector 向き 방향 向量 向量 sStrength Strength 強度 강도 强度 強度 +sAdvProperties Advanced Properties 拡張設定 확장 설정 扩展设置 擴展設置 sFrequency Frequency 周期 주기 周期 週期 sDetail Detail ディテール 디테일 细节 細節 +sTouchStrength Touch strength 接触強度 접촉 강도 接触强度 接觸強度 sNormalMapStrength Normal Map Strength ノーマルマップの強度 노멀 맵의 강도 法线贴图强度 法線貼圖強度 sNormalMap Normal Map ノーマルマップ 노멀 맵 法线贴图 法線貼圖 sRandomize Randomize ランダム化 임의화 随机化 隨機化 @@ -108,4 +110,11 @@ sYes Yes はい Yes Yes Yes sNo No いいえ No No No sOK OK OK OK OK OK sCancel Cancel キャンセル Cancel Cancel Cancel -sComplete Complete! 完了しました。 Complete! Complete! Complete! \ No newline at end of file +sComplete Complete! 完了しました。 Complete! Complete! Complete! +sShaderSetting Shader Setting (for all materials) シェーダー設定 (全マテリアル共通) 쉐이더 설정 (전체 재료 공통) 着色器设置(用于所有材质) 著色器設置(用於所有材質) +sShaderSettingTips You can toggle unused functions. 不要な機能を無効化できます 불필요한 기능을 비활성화 할 수 있습니다 你可以切换不使用的功能。 你可以切換不使用的功能。 +sHelpShaderSetting Features turned off here will be removed from the shader. By turning off unused features, you can reduce the size of your avatar while also reducing the load. ここでオフにした機能はシェーダーから除去されます。不要な機能をオフにすることでアバターの容量を削減しつつ、負荷も抑えることができます。 여기에 끈 기능은 쉐이더에서 제거됩니다. 불필요한 기능을 해제하여 아바타의 용량을 줄이면서 부하도 줄일 수 있습니다. 在这里关闭的功能将从着色器中删除。通过关闭不使用的功能,你可以减少你的头像的大小,同时也可以减少负载。 在這里關閉的功能將從著色器中刪除。通過關閉不使用的功能,你可以減少你的頭像的大小,同時也可以減少負載。​​ +sSettingShadow Shadow 影 그림자 阴影 陰影 +sSettingReceiveShadow Receive Shadow 影の受け取り 그림자 받고 接收阴影 接收陰影 +sSettingClippingCanceller Distance Clipping Canceller 距離クリッピングキャンセラー 거리 클리핑 취소 기 距离剪裁取消器 距離剪裁取消器 +sSettingDistanceFade Distance Fade 距離フェード 거리 페이드 距离淡化 距離淡化 \ No newline at end of file diff --git a/Assets/lilFurGenerator/Editor/lilFurGeneratorInspector.cs b/Assets/lilFurGenerator/Editor/lilFurGeneratorInspector.cs index 48eac47..86b4bdd 100644 --- a/Assets/lilFurGenerator/Editor/lilFurGeneratorInspector.cs +++ b/Assets/lilFurGenerator/Editor/lilFurGeneratorInspector.cs @@ -5,6 +5,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; +using System.Text; namespace lilFurGenerator { @@ -21,16 +22,18 @@ public enum lilRenderPipeline //------------------------------------------------------------------------------------------------------------------------------ // Constant - public const string currentVersionName = "1.0.0"; - public const int currentVersionValue = 1; + public const string currentVersionName = "1.0.1"; + public const int currentVersionValue = 2; public const string boothURL = "https://lilxyzw.booth.pm/"; public const string githubURL = "https://github.com/lilxyzw/lilFurGenerator"; public const string versionInfoURL = "https://raw.githubusercontent.com/lilxyzw/lilFurGenerator/master/version.json"; public const string editorFolderGUID = "59970fc0d266132478e5327940963258"; // "Assets/lilFurGenerator/Editor" public const string languageFileGUID = "31b8eeba6110d59439de5782850a4574"; // "Assets/lilFurGenerator/Editor/lang.txt" - public const string fgShaderGUID = "2c540356c3ded7340b263ceb4ace7e37"; // "Assets/lilFurGenerator/Shader/lilFurGenerator.shader" - public const string hqfgShaderGUID = "7fc1943976840044e82d0503f1f70d23"; // "Assets/lilFurGenerator/Shader/lilFurGenerator.shader" + public const string fgShaderGUID = "2c540356c3ded7340b263ceb4ace7e37"; // "Assets/lilFurGenerator/Shader/lilFurGeneratorToon.shader" + public const string hqfgShaderGUID = "7fc1943976840044e82d0503f1f70d23"; // "Assets/lilFurGenerator/Shader/lilFurGeneratorToonHQ.shader" + public const string ShaderSettingGUID = "13cb99d89b41fd9428d5101d176b6408"; // "Assets/lilFurGenerator/Editor/ShaderSetting.asset" + public const string ShaderSettingHLSLGUID = "f79e08f45a0f3b640b563a49ff855b0c"; // "Assets/lilFurGenerator/Shader/lil_fur_setting.hlsl" public const string editorSettingTempPath = "Temp/lilFurGeneratorEditorSetting"; public const string versionInfoTempPath = "Temp/lilFurGeneratorVersion"; public const string windowName = "lilFurGenerator"; @@ -40,6 +43,16 @@ public static string GetEditorFolderPath() return AssetDatabase.GUIDToAssetPath(editorFolderGUID); } + public static string GetShaderSettingPath() + { + return AssetDatabase.GUIDToAssetPath(ShaderSettingGUID); + } + + public static string GetShaderSettingHLSLPath() + { + return AssetDatabase.GUIDToAssetPath(ShaderSettingHLSLGUID); + } + public static readonly Vector2 defaultTextureOffset = new Vector2(0.0f,0.0f); public static readonly Vector2 defaultTextureScale = new Vector2(1.0f,1.0f); public static readonly Vector4 defaultDistanceFadeParams = new Vector4(0.1f,0.01f,0.0f,0.0f); @@ -47,6 +60,7 @@ public static string GetEditorFolderPath() //------------------------------------------------------------------------------------------------------------------------------ // Editor + static lilFurGeneratorSetting shaderSetting; public static Dictionary loc = new Dictionary(); [Serializable] @@ -67,6 +81,8 @@ public class lilFurEditorSetting public bool isShowBlendAdd = false; public bool isShowWebPages = false; public bool isShowAdvanced = false; + public bool isShowShaderSetting = false; + public bool isShaderSettingChanged = false; // for generator window public GameObject gameObject; @@ -157,6 +173,7 @@ public class lilFurVersion MaterialProperty furWindMove1; MaterialProperty furWindFreq2; MaterialProperty furWindMove2; + MaterialProperty furTouchStrength; //------------------------------------------------------------------------------------------------------------------------------ // GUI @@ -200,6 +217,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro //------------------------------------------------------------------------------------------------------------------------------ // Initialize Setting ApplyEditorSettingTemp(); + InitializeShaderSetting(ref shaderSetting); //------------------------------------------------------------------------------------------------------------------------------ // Load Material @@ -250,7 +268,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro EditorGUILayout.HelpBox(GetLoc("sHelpZWrite"),MessageType.Warning); } EditorGUI.indentLevel--; - materialEditor.ShaderProperty(useClippingCanceller, GetLoc("sClippingCanceller")); + if(shaderSetting.LIL_FEATURE_CLIPPING_CANCELLER) materialEditor.ShaderProperty(useClippingCanceller, GetLoc("sClippingCanceller")); DrawLine(); materialEditor.ShaderProperty(asUnlit, GetLoc("sAsUnlit")); materialEditor.ShaderProperty(vertexLightStrength, GetLoc("sVertexLightStrength")); @@ -292,24 +310,27 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro //------------------------------------------------------------------------------------------------------------------------------ // Shadow - edSet.isShowShadow = Foldout(GetLoc("sShadowSetting"), GetLoc("sShadowTips"), edSet.isShowShadow); - if(edSet.isShowShadow) + if(shaderSetting.LIL_FEATURE_SHADOW) { - EditorGUILayout.BeginVertical(boxOuter); - EditorGUILayout.LabelField(GetLoc("sShadow"), customToggleFont); - EditorGUILayout.BeginVertical(boxInnerHalf); - materialEditor.ShaderProperty(shadowColor, GetLoc("sShadowColor")); - materialEditor.ShaderProperty(shadowBorder, GetLoc("sBorder")); - materialEditor.ShaderProperty(shadowBlur, GetLoc("sBlur")); - DrawLine(); - materialEditor.ShaderProperty(shadowBorderColor, GetLoc("sShadowBorderColor")); - materialEditor.ShaderProperty(shadowBorderRange, GetLoc("sShadowBorderRange")); - materialEditor.ShaderProperty(shadowReceive, GetLoc("sReceiveShadow")); - EditorGUILayout.EndVertical(); - EditorGUILayout.EndVertical(); - } + edSet.isShowShadow = Foldout(GetLoc("sShadowSetting"), GetLoc("sShadowTips"), edSet.isShowShadow); + if(edSet.isShowShadow) + { + EditorGUILayout.BeginVertical(boxOuter); + EditorGUILayout.LabelField(GetLoc("sShadow"), customToggleFont); + EditorGUILayout.BeginVertical(boxInnerHalf); + materialEditor.ShaderProperty(shadowColor, GetLoc("sShadowColor")); + materialEditor.ShaderProperty(shadowBorder, GetLoc("sBorder")); + materialEditor.ShaderProperty(shadowBlur, GetLoc("sBlur")); + DrawLine(); + materialEditor.ShaderProperty(shadowBorderColor, GetLoc("sShadowBorderColor")); + materialEditor.ShaderProperty(shadowBorderRange, GetLoc("sShadowBorderRange")); + if(shaderSetting.LIL_FEATURE_RECEIVE_SHADOW) materialEditor.ShaderProperty(shadowReceive, GetLoc("sReceiveShadow")); + EditorGUILayout.EndVertical(); + EditorGUILayout.EndVertical(); + } - EditorGUILayout.Space(); + EditorGUILayout.Space(); + } //------------------------------------------------------------------------------------------------------------------------------ // Advanced @@ -317,16 +338,19 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro //------------------------------------------------------------------------------------------------------------------------------ // Distance Fade - edSet.isShowDistanceFade = Foldout(GetLoc("sDistanceFade"), GetLoc("sDistanceFadeTips"), edSet.isShowDistanceFade); - if(edSet.isShowDistanceFade) + if(shaderSetting.LIL_FEATURE_DISTANCE_FADE) { - EditorGUILayout.BeginVertical(boxOuter); - EditorGUILayout.LabelField(GetLoc("sDistanceFade"), customToggleFont); - EditorGUILayout.BeginVertical(boxInnerHalf); - materialEditor.ShaderProperty(distanceFadeColor, GetLoc("sColor")); - materialEditor.ShaderProperty(distanceFade, GetLoc("sStartDistance")+"|"+GetLoc("sEndDistance")+"|"+GetLoc("sStrength")); - EditorGUILayout.EndVertical(); - EditorGUILayout.EndVertical(); + edSet.isShowDistanceFade = Foldout(GetLoc("sDistanceFade"), GetLoc("sDistanceFadeTips"), edSet.isShowDistanceFade); + if(edSet.isShowDistanceFade) + { + EditorGUILayout.BeginVertical(boxOuter); + EditorGUILayout.LabelField(GetLoc("sDistanceFade"), customToggleFont); + EditorGUILayout.BeginVertical(boxInnerHalf); + materialEditor.ShaderProperty(distanceFadeColor, GetLoc("sColor")); + materialEditor.ShaderProperty(distanceFade, GetLoc("sStartDistance")+"|"+GetLoc("sEndDistance")+"|"+GetLoc("sStrength")); + EditorGUILayout.EndVertical(); + EditorGUILayout.EndVertical(); + } } //------------------------------------------------------------------------------------------------------------------------------ @@ -345,7 +369,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro materialEditor.ShaderProperty(furAO, GetLoc("sAO")); materialEditor.ShaderProperty(furAOColor, GetLoc("sAOColor")); DrawLine(); - bool isHQ2 = EditorGUILayout.Toggle("Use Wind", isHQ); + bool isHQ2 = EditorGUILayout.Toggle(GetLoc("sAdvProperties"), isHQ); if(isHQ != isHQ2) { material.shader = isHQ2 ? fchq : fc; @@ -360,6 +384,8 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro EditorGUILayout.LabelField("Wind 2", EditorStyles.boldLabel); materialEditor.ShaderProperty(furWindFreq2, GetLoc("sFrequency")); materialEditor.ShaderProperty(furWindMove2, GetLoc("sStrength") + "|" + GetLoc("sDetail")); + DrawLine(); + materialEditor.ShaderProperty(furTouchStrength, GetLoc("sTouchStrength")); EditorGUI.indentLevel--; } EditorGUILayout.EndVertical(); @@ -497,6 +523,20 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro EditorGUILayout.EndVertical(); } + //------------------------------------------------------------------------------------------------------------------------------ + // Shader Setting + edSet.isShowShaderSetting = Foldout(GetLoc("sShaderSetting"), GetLoc("sShaderSettingTips"), edSet.isShowShaderSetting); + if(edSet.isShowShaderSetting) + { + EditorGUILayout.BeginVertical(boxOuter); + EditorGUILayout.LabelField(GetLoc("sShaderSetting"), customToggleFont); + EditorGUILayout.BeginVertical(boxInnerHalf); + EditorGUILayout.HelpBox(GetLoc("sHelpShaderSetting"),MessageType.Info); + ShaderSettingGUI(); + EditorGUILayout.EndVertical(); + EditorGUILayout.EndVertical(); + } + SaveEditorSettingTemp(); } @@ -563,6 +603,7 @@ void LoadHQProperties(MaterialProperty[] props) furWindMove1 = FindProperty("_FurWindMove1", props); furWindFreq2 = FindProperty("_FurWindFreq2", props); furWindMove2 = FindProperty("_FurWindMove2", props); + furTouchStrength = FindProperty("_FurTouchStrength", props); } //------------------------------------------------------------------------------------------------------------------------------ @@ -871,6 +912,144 @@ public static int InitializeLanguage(int lnum) return lnum; } + public static void InitializeShaderSetting(ref lilFurGeneratorSetting shaderSetting) + { + if(shaderSetting != null) return; + string shaderSettingPath = GetShaderSettingPath(); + shaderSetting = (lilFurGeneratorSetting)AssetDatabase.LoadAssetAtPath(shaderSettingPath, typeof(lilFurGeneratorSetting)); + if(shaderSetting == null) + { + shaderSetting = ScriptableObject.CreateInstance(); + AssetDatabase.CreateAsset(shaderSetting, shaderSettingPath); + shaderSetting.LIL_FEATURE_SHADOW = true; + shaderSetting.LIL_FEATURE_RECEIVE_SHADOW = false; + shaderSetting.LIL_FEATURE_CLIPPING_CANCELLER = false; + shaderSetting.LIL_FEATURE_DISTANCE_FADE = false; + EditorUtility.SetDirty(shaderSetting); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + } + + static void ShaderSettingGUI() + { + GUIStyle applyButton = new GUIStyle(GUI.skin.button); + applyButton.normal.textColor = Color.red; + applyButton.fontStyle = FontStyle.Bold; + + // Apply Button + if(edSet.isShaderSettingChanged && GUILayout.Button("Apply", applyButton)) + { + ApplyShaderSetting(shaderSetting); + edSet.isShaderSettingChanged = false; + } + DrawLine(); + + EditorGUI.BeginChangeCheck(); + + lilToggleGUI(GetLoc("sSettingShadow"), ref shaderSetting.LIL_FEATURE_SHADOW); + if(shaderSetting.LIL_FEATURE_SHADOW) + { + EditorGUI.indentLevel++; + lilToggleGUI(GetLoc("sSettingReceiveShadow"), ref shaderSetting.LIL_FEATURE_RECEIVE_SHADOW); + EditorGUI.indentLevel--; + } + DrawLine(); + + lilToggleGUI(GetLoc("sSettingClippingCanceller"), ref shaderSetting.LIL_FEATURE_CLIPPING_CANCELLER); + DrawLine(); + + lilToggleGUI(GetLoc("sSettingDistanceFade"), ref shaderSetting.LIL_FEATURE_DISTANCE_FADE); + + if(EditorGUI.EndChangeCheck()) + { + edSet.isShaderSettingChanged = true; + EditorUtility.SetDirty(shaderSetting); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + } + + static void lilToggleGUI(string label, ref bool value) + { + value = EditorGUILayout.ToggleLeft(label, value); + } + + public static void ApplyShaderSetting(lilFurGeneratorSetting shaderSetting) + { + StringBuilder sb = new StringBuilder(); + sb.Append("#ifndef LIL_FUR_SETTING_INCLUDED\r\n#define LIL_FUR_SETTING_INCLUDED\r\n\r\n"); + if(shaderSetting.LIL_FEATURE_SHADOW) + { + sb.Append("#define LIL_FEATURE_SHADOW\r\n"); + if(shaderSetting.LIL_FEATURE_RECEIVE_SHADOW) sb.Append("#define LIL_FEATURE_RECEIVE_SHADOW\r\n"); + } + if(shaderSetting.LIL_FEATURE_CLIPPING_CANCELLER) sb.Append("#define LIL_FEATURE_CLIPPING_CANCELLER\r\n"); + if(shaderSetting.LIL_FEATURE_DISTANCE_FADE) sb.Append("#define LIL_FEATURE_DISTANCE_FADE\r\n"); + sb.Append("\r\n#endif"); + string shaderSettingString = sb.ToString(); + + string shaderSettingStringBuf = ""; + string shaderSettingHLSLPath = GetShaderSettingHLSLPath(); + if(File.Exists(shaderSettingHLSLPath)) + { + StreamReader sr = new StreamReader(shaderSettingHLSLPath); + shaderSettingStringBuf = sr.ReadToEnd(); + sr.Close(); + } + + if(shaderSettingString != shaderSettingStringBuf) + { + StreamWriter sw = new StreamWriter(shaderSettingHLSLPath,false); + sw.Write(shaderSettingString); + sw.Close(); + RewriteReceiveShadow(AssetDatabase.GUIDToAssetPath(fgShaderGUID), shaderSetting.LIL_FEATURE_SHADOW && shaderSetting.LIL_FEATURE_RECEIVE_SHADOW); + RewriteReceiveShadow(AssetDatabase.GUIDToAssetPath(hqfgShaderGUID), shaderSetting.LIL_FEATURE_SHADOW && shaderSetting.LIL_FEATURE_RECEIVE_SHADOW); + AssetDatabase.SaveAssets(); + AssetDatabase.ImportAsset(shaderSettingHLSLPath); + AssetDatabase.Refresh(); + } + } + + static void RewriteReceiveShadow(string path, bool enable) + { + if(String.IsNullOrEmpty(path) || !File.Exists(path)) return; + StreamReader sr = new StreamReader(path); + string s = sr.ReadToEnd(); + sr.Close(); + if(enable) + { + // BRP + s = s.Replace( + " // Skip receiving shadow\r\n #pragma skip_variants SHADOWS_SCREEN", + " // Skip receiving shadow\r\n //#pragma skip_variants SHADOWS_SCREEN"); + // LWRP & URP + s = s.Replace( + " // Skip receiving shadow\r\n //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN\r\n //#pragma multi_compile_fragment _ _SHADOWS_SOFT", + " // Skip receiving shadow\r\n #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN\r\n #pragma multi_compile_fragment _ _SHADOWS_SOFT"); + } + else + { + // BRP + s = s.Replace( + " // Skip receiving shadow\r\n //#pragma skip_variants SHADOWS_SCREEN", + " // Skip receiving shadow\r\n #pragma skip_variants SHADOWS_SCREEN"); + // LWRP & URP + s = s.Replace( + " // Skip receiving shadow\r\n #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN\r\n #pragma multi_compile_fragment _ _SHADOWS_SOFT", + " // Skip receiving shadow\r\n //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN\r\n //#pragma multi_compile_fragment _ _SHADOWS_SOFT"); + } + StreamWriter sw = new StreamWriter(path,false); + sw.Write(s); + sw.Close(); + } + + static void RewriteReceiveShadow(Shader shader, bool enable) + { + string path = AssetDatabase.GetAssetPath(shader); + RewriteReceiveShadow(path, enable); + } + //------------------------------------------------------------------------------------------------------------------------------ // Material Setup static void RemoveShaderKeywords(Material material) diff --git a/Assets/lilFurGenerator/Editor/lilFurGeneratorSetting.cs b/Assets/lilFurGenerator/Editor/lilFurGeneratorSetting.cs new file mode 100644 index 0000000..979e54f --- /dev/null +++ b/Assets/lilFurGenerator/Editor/lilFurGeneratorSetting.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +public class lilFurGeneratorSetting : ScriptableObject +{ + public bool LIL_FEATURE_SHADOW; + public bool LIL_FEATURE_RECEIVE_SHADOW; + public bool LIL_FEATURE_CLIPPING_CANCELLER; + public bool LIL_FEATURE_DISTANCE_FADE; +} \ No newline at end of file diff --git a/Assets/lilFurGenerator/Editor/lilFurGeneratorSetting.cs.meta b/Assets/lilFurGenerator/Editor/lilFurGeneratorSetting.cs.meta new file mode 100644 index 0000000..188834a --- /dev/null +++ b/Assets/lilFurGenerator/Editor/lilFurGeneratorSetting.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1702bfaf2bdfcf04eb7d482e679e1912 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/lilFurGenerator/Prefabs.meta b/Assets/lilFurGenerator/Prefabs.meta new file mode 100644 index 0000000..330d3d2 --- /dev/null +++ b/Assets/lilFurGenerator/Prefabs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4240ec5df75e1bc458a659fe8cecff4c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/lilFurGenerator/Prefabs/FurCollider (alpha_0.055).prefab b/Assets/lilFurGenerator/Prefabs/FurCollider (alpha_0.055).prefab new file mode 100644 index 0000000..6fe47eb --- /dev/null +++ b/Assets/lilFurGenerator/Prefabs/FurCollider (alpha_0.055).prefab @@ -0,0 +1,94 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &1173276058128652091 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1173276058128652085} + - component: {fileID: 1173276058128652090} + m_Layer: 0 + m_Name: FurCollider (alpha_0.055) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1173276058128652085 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1173276058128652091} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!108 &1173276058128652090 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1173276058128652091} + m_Enabled: 1 + serializedVersion: 10 + m_Type: 2 + m_Shape: 0 + m_Color: {r: 0, g: 0, b: 0, a: 0.05490196} + m_Intensity: 1 + m_Range: 0.1 + m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 + m_CookieSize: 10 + m_Shadows: + m_Type: 0 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 2 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingLayerMask: 1 + m_Lightmapping: 4 + m_LightShadowCasterMode: 0 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 0 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_ShadowRadius: 0 + m_ShadowAngle: 0 diff --git a/Assets/lilFurGenerator/Prefabs/FurCollider (alpha_0.055).prefab.meta b/Assets/lilFurGenerator/Prefabs/FurCollider (alpha_0.055).prefab.meta new file mode 100644 index 0000000..544ef90 --- /dev/null +++ b/Assets/lilFurGenerator/Prefabs/FurCollider (alpha_0.055).prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5da7545ba4296fd4b8f72f321d628fc1 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/lilFurGenerator/README.md b/Assets/lilFurGenerator/README.md index 4f1571b..5b24900 100644 --- a/Assets/lilFurGenerator/README.md +++ b/Assets/lilFurGenerator/README.md @@ -1,5 +1,5 @@ # lilFurGenerator -Version 1.0.0 +Version 1.0.1 # Overview A plug-in that generates a fur mesh. @@ -37,6 +37,25 @@ lilFurGenerator is available under the MIT License. Please refer to the `LICENSE Select and edit materials for change advanced settings. +# Advanced Properties +|Name|Description| +|-|-| +|Frequency|Wind frequency of each XYZ axes.| +|Strength|Wind strength of each XYZ axes.| +|Detail|Randomness of wind direction.| +|Touch Strength|Strength of deformation by collider using vertex light.| + +Point Light used for the touch function works by setting as follows. +Due to Unity's limits, you can only touch up to 4 lights. +Prefab asset that has already been set is included in the `Prefabs` folder. +|Name|Description| +|-|-| +|Range|Any (the size of the Collider)| +|Color|RGBA = (0.0, 0.0, 0.0, 0.055)| +|Mode|Realtime| +|Intensity|1| +|Render Mode|Not Important| + # Bug Report If you have any other problems and suspect a bug, please contact me on [Twitter](https://twitter.com/lil_xyzw), [GitHub](https://github.com/lilxyzw/lilFurGenerator), or [BOOTH](https://lilxyzw.booth.pm/). Please refer to the following template when reporting a bug. @@ -62,5 +81,13 @@ Shaders with `FurGenerator` in their display name will be added to the list in t See `lilFurGenerator/Shader/lilFurGeneratorUnlit.shader` for fur calculations. # Change log -## v1.0 +## v1.0.1 +- Add color code next to HDR color picker +- Added touch function +- Fixed UPM import +- Fixed error in Unity 2019 URP +- Added shader settings for optimization +- Moved some processing to the vertex shader for optimization +- Changed transform calculation +## v1.0.0 - Opening to the public \ No newline at end of file diff --git a/Assets/lilFurGenerator/README_JP.md b/Assets/lilFurGenerator/README_JP.md index 452f482..67a1fea 100644 --- a/Assets/lilFurGenerator/README_JP.md +++ b/Assets/lilFurGenerator/README_JP.md @@ -1,5 +1,5 @@ # lilFurGenerator -Version 1.0.0 +Version 1.0.1 # 概要 ファーのメッシュを生成するプラグインです。 @@ -37,6 +37,25 @@ MIT Licenseで公開しています。同梱の`LICENSE`をご確認ください マテリアルの細かい調整は直接編集して行って下さい。 +# 拡張設定 +|名前|説明| +|-|-| +|周期|XYZ軸それぞれの風の周期です。| +|強度|XYZ軸それぞれの風の強さです。| +|ディテール|風向きのランダム度です。| +|接触強度|頂点ライトを用いた接触機能による変形の強度です。| + +接触機能に用いるPoint Lightは以下のように設定することで機能します。 +Unityの制限で接触できるライトの数は最大4つまでになります。 +Prefabsフォルダに設定済みのPrefabを同梱しています。 +|名前|説明| +|-|-| +|Range|任意 (コライダーの大きさになります)| +|Color|RGBA = (0.0, 0.0, 0.0, 0.055)| +|Mode|Realtime| +|Intensity|1| +|Render Mode|Not Important| + # バグレポート トラブルが発生し不具合であることが疑われる場合は[Twitter](https://twitter.com/lil_xyzw)、[GitHub](https://github.com/lilxyzw/lilFurGenerator)、[BOOTH](https://lilxyzw.booth.pm/)のいずれかにご連絡いただければ幸いです。 以下にテンプレートも用意させていただきましたのでバグ報告の際の参考にご活用下さい。 @@ -62,5 +81,13 @@ VRChatのワールド: ファーの実装方法は`lilFurGenerator/Shader/lilFurGeneratorUnlit.shader`を参照してください。 # 変更履歴 -## v1.0 +## v1.0.1 +- HDRカラーピッカーの隣にカラーコードを追加 +- 接触機能の追加 +- UPMインポートの修正 +- Unity 2019のURPでうまく動作しない問題を修正 +- 軽量化のためにシェーダー設定機能を追加 +- いくつかの処理を頂点シェーダーに移動し最適化 +- 行列計算の変更 +## v1.0.0 - 公開開始 \ No newline at end of file diff --git a/Assets/lilFurGenerator/Shader/lilFurGeneratorToon.shader b/Assets/lilFurGenerator/Shader/lilFurGeneratorToon.shader index b675134..cefcdd1 100644 --- a/Assets/lilFurGenerator/Shader/lilFurGeneratorToon.shader +++ b/Assets/lilFurGenerator/Shader/lilFurGeneratorToon.shader @@ -117,7 +117,7 @@ Shader "_lil/FurGeneratorToon" #pragma fragmentoption ARB_precision_hint_fastest // Skip receiving shadow - //#pragma skip_variants SHADOWS_SCREEN + #pragma skip_variants SHADOWS_SCREEN //------------------------------------------------------------------------------------------------------------------ // Pass @@ -290,8 +290,8 @@ Shader "_lil/FurGeneratorToon" #pragma multi_compile _ DOTS_INSTANCING_ON // Skip receiving shadow - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN - #pragma multi_compile_fragment _ _SHADOWS_SOFT + //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + //#pragma multi_compile_fragment _ _SHADOWS_SOFT //------------------------------------------------------------------------------------------------------------------ // Pass @@ -434,8 +434,8 @@ Shader "_lil/FurGeneratorToon" #pragma multi_compile_instancing // Skip receiving shadow - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN - #pragma multi_compile_fragment _ _SHADOWS_SOFT + //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + //#pragma multi_compile_fragment _ _SHADOWS_SOFT //------------------------------------------------------------------------------------------------------------------ // Pass @@ -587,8 +587,8 @@ Shader "_lil/FurGeneratorToon" #pragma multi_compile _ DOTS_INSTANCING_ON // Skip receiving shadow - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN - #pragma multi_compile_fragment _ _SHADOWS_SOFT + //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + //#pragma multi_compile_fragment _ _SHADOWS_SOFT //------------------------------------------------------------------------------------------------------------------ // Pass @@ -758,8 +758,8 @@ Shader "_lil/FurGeneratorToon" #pragma multi_compile_instancing // Skip receiving shadow - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN - #pragma multi_compile_fragment _ _SHADOWS_SOFT + //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + //#pragma multi_compile_fragment _ _SHADOWS_SOFT //------------------------------------------------------------------------------------------------------------------ // Pass diff --git a/Assets/lilFurGenerator/Shader/lilFurGeneratorToonHQ.shader b/Assets/lilFurGenerator/Shader/lilFurGeneratorToonHQ.shader index cd5127b..f276e8a 100644 --- a/Assets/lilFurGenerator/Shader/lilFurGeneratorToonHQ.shader +++ b/Assets/lilFurGenerator/Shader/lilFurGeneratorToonHQ.shader @@ -41,6 +41,7 @@ Shader "_lil/FurGeneratorToonHQ" [lilVec3Float] _FurWindMove1 ("Wind Strength 1|Wind Detail 1", Vector) = (0.05, 0.05, 0.05, 1.0) [lilVec3] _FurWindFreq2 ("Wind Freq 2", Vector) = (10.0, 14.0, 18.0, 1.0) [lilVec3Float] _FurWindMove2 ("Wind Strength 2|Wind Detail 2", Vector) = (0.0025, 0.0025, 0.0025, 5000.0) + _FurTouchStrength ("Fur Touch Strength", Range(0,1)) = 0 //---------------------------------------------------------------------------------------------------------------------- // Advanced @@ -122,7 +123,7 @@ Shader "_lil/FurGeneratorToonHQ" #pragma fragmentoption ARB_precision_hint_fastest // Skip receiving shadow - //#pragma skip_variants SHADOWS_SCREEN + #pragma skip_variants SHADOWS_SCREEN //------------------------------------------------------------------------------------------------------------------ // Pass @@ -296,8 +297,8 @@ Shader "_lil/FurGeneratorToonHQ" #pragma multi_compile _ DOTS_INSTANCING_ON // Skip receiving shadow - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN - #pragma multi_compile_fragment _ _SHADOWS_SOFT + //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + //#pragma multi_compile_fragment _ _SHADOWS_SOFT //------------------------------------------------------------------------------------------------------------------ // Pass @@ -440,8 +441,8 @@ Shader "_lil/FurGeneratorToonHQ" #pragma multi_compile_instancing // Skip receiving shadow - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN - #pragma multi_compile_fragment _ _SHADOWS_SOFT + //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + //#pragma multi_compile_fragment _ _SHADOWS_SOFT //------------------------------------------------------------------------------------------------------------------ // Pass @@ -594,8 +595,8 @@ Shader "_lil/FurGeneratorToonHQ" #pragma multi_compile _ DOTS_INSTANCING_ON // Skip receiving shadow - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN - #pragma multi_compile_fragment _ _SHADOWS_SOFT + //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + //#pragma multi_compile_fragment _ _SHADOWS_SOFT //------------------------------------------------------------------------------------------------------------------ // Pass @@ -748,8 +749,8 @@ Shader "_lil/FurGeneratorToonHQ" #pragma multi_compile_instancing // Skip receiving shadow - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN - #pragma multi_compile_fragment _ _SHADOWS_SOFT + //#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + //#pragma multi_compile_fragment _ _SHADOWS_SOFT //------------------------------------------------------------------------------------------------------------------ // Pass diff --git a/Assets/lilFurGenerator/Shader/lil_fur_functions.hlsl b/Assets/lilFurGenerator/Shader/lil_fur_functions.hlsl index b3e13fe..66ae582 100644 --- a/Assets/lilFurGenerator/Shader/lil_fur_functions.hlsl +++ b/Assets/lilFurGenerator/Shader/lil_fur_functions.hlsl @@ -19,7 +19,8 @@ float lilTooning(float value, float border, float blur, float borderRange) float4 lilOptMul(float4x4 mat, float3 pos) { - return mat._m00_m10_m20_m30 * pos.x + (mat._m01_m11_m21_m31 * pos.y + (mat._m02_m12_m22_m32 * pos.z + mat._m03_m13_m23_m33)); + return mul(mat, float4(pos,1.0)); + //return mat._m00_m10_m20_m30 * pos.x + (mat._m01_m11_m21_m31 * pos.y + (mat._m02_m12_m22_m32 * pos.z + mat._m03_m13_m23_m33)); } float3 lilTransformNormalOStoWS(float3 normalOS) @@ -174,6 +175,23 @@ void CalcFur(inout float3 positionWS, float3 normalOS, float4 tangentOS, float4 float motionStrength = _FurSoftness * color.w * furLength; #endif + // Touch + #if defined(LIL_FUR_HQ) && defined(VERTEXLIGHT_ON) + float3 vectorWS2 = normalize(vectorWS + motionWS * motionStrength) * (furLength * _FurLength * uv4.y); + float3 positionWS2 = uv4.y > -0.5 ? positionWS + vectorWS2 : positionWS; + float4 toLightX = unity_4LightPosX0 - positionWS2.x; + float4 toLightY = unity_4LightPosY0 - positionWS2.y; + float4 toLightZ = unity_4LightPosZ0 - positionWS2.z; + float4 lengthSq = toLightX * toLightX + 0.000001; + lengthSq += toLightY * toLightY; + lengthSq += toLightZ * toLightZ; + float4 atten = saturate(1.0 - lengthSq * unity_4LightAtten0 / 25.0) * _FurTouchStrength; + motionWS = abs(unity_LightColor[0].a - 0.055) < 0.001 ? motionWS - float3(toLightX[0], toLightY[0], toLightZ[0]) * rsqrt(lengthSq[0]) * atten[0] : motionWS; + motionWS = abs(unity_LightColor[1].a - 0.055) < 0.001 ? motionWS - float3(toLightX[1], toLightY[1], toLightZ[1]) * rsqrt(lengthSq[1]) * atten[1] : motionWS; + motionWS = abs(unity_LightColor[2].a - 0.055) < 0.001 ? motionWS - float3(toLightX[2], toLightY[2], toLightZ[2]) * rsqrt(lengthSq[2]) * atten[2] : motionWS; + motionWS = abs(unity_LightColor[3].a - 0.055) < 0.001 ? motionWS - float3(toLightX[3], toLightY[3], toLightZ[3]) * rsqrt(lengthSq[3]) * atten[3] : motionWS; + #endif + // Blend vectorWS = normalize(vectorWS + motionWS * motionStrength) * (furLength * _FurLength * uv4.y); diff --git a/Assets/lilFurGenerator/Shader/lil_fur_input.hlsl b/Assets/lilFurGenerator/Shader/lil_fur_input.hlsl index a4015a5..fa9b5f1 100644 --- a/Assets/lilFurGenerator/Shader/lil_fur_input.hlsl +++ b/Assets/lilFurGenerator/Shader/lil_fur_input.hlsl @@ -31,6 +31,9 @@ CBUFFER_START(UnityPerMaterial) float _FurAO; float _FurDensity; float _FurSoftness; + #if defined(LIL_FUR_HQ) + float _FurTouchStrength; + #endif uint _UseClippingCanceller; uint _ShadowReceive; CBUFFER_END diff --git a/Assets/lilFurGenerator/Shader/lil_fur_macro.hlsl b/Assets/lilFurGenerator/Shader/lil_fur_macro.hlsl index d6d3e49..cdebc51 100644 --- a/Assets/lilFurGenerator/Shader/lil_fur_macro.hlsl +++ b/Assets/lilFurGenerator/Shader/lil_fur_macro.hlsl @@ -75,7 +75,7 @@ return normalWS * invNdotL * _ShadowBias.y + lightDirectionWS * _ShadowBias.xxx + positionWS; } #elif defined(LIL_URP) - #define LIL_GET_VIEWDIR_WS(positionWS) GetWorldSpaceViewDir(positionWS) + #define LIL_GET_VIEWDIR_WS(positionWS) GetCameraPositionWS() - positionWS #endif #if defined(LIL_BRP) @@ -228,6 +228,7 @@ #define LIL_TIME _Time.y #define LIL_INTER_TIME lilIntervalTime(_TimeInterval) +// Texture #if defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (defined(SHADER_TARGET_SURFACE_ANALYSIS) && !defined(SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) #define LIL_SAMPLE_2D(tex,samp,uv) tex.Sample(samp,uv) #define LIL_SAMPLE_2D_BIAS(tex,samp,uv,bias) tex.SampleBias(samp,uv,bias) @@ -248,6 +249,7 @@ #endif #endif +// Lightmap #if defined(LIL_USE_DOTS_INSTANCING) #define LIL_SHADOWMAP_TEX unity_ShadowMasks #define LIL_SHADOWMAP_SAMP samplerunity_ShadowMasks @@ -268,6 +270,7 @@ #define LIL_SAMPLE_LIGHTMAP(tex,samp,uv) LIL_SAMPLE_2D(tex,samp,uv) #endif +// Lightmap uv #if defined(LIL_USE_LIGHTMAP_UV) #define LIL_VERTEX_INPUT_LIGHTMAP_UV float2 uv1 : TEXCOORD1; #define LIL_LIGHTMAP_COORDS(idx) float2 uvLM : TEXCOORD##idx; @@ -278,13 +281,31 @@ #define LIL_TRANSFER_LIGHTMAPUV(uv1,o) #endif -#if defined(LIL_USE_LPPV) - #define LIL_GET_LIGHTCOLOR lilGetLightColor(input.positionWS) +// Main Light Coords +#if defined(LIL_PASS_FORWARDADD) + #define LIL_LIGHTCOLOR_COORDS(idx) + #define LIL_LIGHTDIRECTION_COORDS(idx) +#else + #define LIL_LIGHTCOLOR_COORDS(idx) noperspective float3 lightColor : TEXCOORD##idx; + #define LIL_LIGHTDIRECTION_COORDS(idx) noperspective float3 lightDirection : TEXCOORD##idx; +#endif + +// Main Light in VS (Color / Direction) +#if defined(LIL_PASS_FORWARDADD) + #define LIL_CALC_MAINLIGHT(i,o) +#elif defined(LIL_USE_LIGHTMAP) + #define LIL_CALC_MAINLIGHT(i,o) \ + o.lightDirection = lilGetLightDirection(); \ + o.lightColor = lilGetLightColor(); #else - #define LIL_GET_LIGHTCOLOR lilGetLightColor() + #define LIL_CALC_MAINLIGHT(i,o) \ + o.lightDirection = lilGetLightDirection(); \ + o.lightColor = lilGetLightColor(); \ + o.lightColor = max(o.lightColor, _LightMinLimit); \ + o.lightColor = lerp(o.lightColor, 1.0, _AsUnlit) #endif -// Main Light (Color / Direction / Attenuation) +// Main Light in PS (Color / Direction / Attenuation) #if defined(LIL_PASS_FORWARDADD) // Point Light & Spot Light (ForwardAdd) #define LIL_GET_MAINLIGHT(input,lightColor,lightDirection,atten) \ @@ -295,8 +316,8 @@ // Mixed Lightmap (Shadowmask) #define LIL_GET_MAINLIGHT(input,lightColor,lightDirection,atten) \ LIL_LIGHT_ATTENUATION(atten, input); \ - float3 lightColor = LIL_GET_LIGHTCOLOR; \ - float3 lightDirection = lilGetLightDirection(); \ + float3 lightColor = input.lightColor; \ + float3 lightDirection = input.lightDirection; \ float3 lightmapColor = lilGetLightMapColor(input.uvLM); \ lightColor = max(lightColor, lightmapColor); \ atten = min(atten, LIL_SAMPLE_LIGHTMAP(LIL_SHADOWMAP_TEX,LIL_LIGHTMAP_SAMP,input.uvLM).r) @@ -306,8 +327,8 @@ #undef LIL_USE_DYNAMICLIGHTMAP #define LIL_GET_MAINLIGHT(input,lightColor,lightDirection,atten) \ LIL_LIGHT_ATTENUATION(atten, input); \ - float3 lightColor = LIL_GET_LIGHTCOLOR; \ - float3 lightDirection = lilGetLightDirection(); \ + float3 lightColor = input.lightColor; \ + float3 lightDirection = input.lightDirection; \ float3 lightmapColor = lilGetLightMapColor(input.uvLM); \ lightColor = max(lightColor, lightmapColor); \ float3 lightmapShadowThreshold = _MainLightColor.rgb*0.5; \ @@ -319,8 +340,8 @@ // Use Lightmap as Shadowmask #define LIL_GET_MAINLIGHT(input,lightColor,lightDirection,atten) \ LIL_LIGHT_ATTENUATION(atten, input); \ - float3 lightColor = LIL_GET_LIGHTCOLOR; \ - float3 lightDirection = lilGetLightDirection(); \ + float3 lightColor = input.lightColor; \ + float3 lightDirection = input.lightDirection; \ float3 lightmapColor = lilGetLightMapColor(input.uvLM); \ lightColor = max(lightColor, lightmapColor); \ float3 lightmapS = (lightmapColor - SampleSH(input.normalWS)) / _MainLightColor.rgb; \ @@ -330,8 +351,8 @@ // Lightmap (Directional) #define LIL_GET_MAINLIGHT(input,lightColor,lightDirection,atten) \ LIL_LIGHT_ATTENUATION(atten, input); \ - float3 lightColor = LIL_GET_LIGHTCOLOR; \ - float3 lightDirection = lilGetLightDirection(); \ + float3 lightColor = input.lightColor; \ + float3 lightDirection = input.lightDirection; \ float3 lightmapColor = lilGetLightMapColor(input.uvLM); \ float3 lightmapDirection = lilGetLightMapDirection(input.uvLM); \ lightColor = saturate(lightColor + lightmapColor); \ @@ -341,7 +362,7 @@ #define LIL_GET_MAINLIGHT(input,lightColor,lightDirection,atten) \ LIL_LIGHT_ATTENUATION(atten, input); \ float3 lightColor = _MainLightColor.rgb; \ - float3 lightDirection = lilGetLightDirection(); \ + float3 lightDirection = input.lightDirection; \ float3 lightmapColor = lilGetLightMapColor(input.uvLM); \ lightColor = saturate(lightColor + max(lightmapColor,lilGetSHToon())) #elif defined(LIL_USE_LIGHTMAP) && defined(LIL_USE_DYNAMICLIGHTMAP) @@ -349,8 +370,8 @@ #undef LIL_USE_DYNAMICLIGHTMAP #define LIL_GET_MAINLIGHT(input,lightColor,lightDirection,atten) \ LIL_LIGHT_ATTENUATION(atten, input); \ - float3 lightColor = LIL_GET_LIGHTCOLOR; \ - float3 lightDirection = lilGetLightDirection(); \ + float3 lightColor = input.lightColor; \ + float3 lightDirection = input.lightDirection; \ float3 lightmapColor = lilGetLightMapColor(input.uvLM); \ lightColor = saturate(lightColor + lightmapColor) #elif defined(LIL_USE_LIGHTMAP) @@ -358,16 +379,15 @@ #define LIL_GET_MAINLIGHT(input,lightColor,lightDirection,atten) \ LIL_LIGHT_ATTENUATION(atten, input); \ float3 lightColor = _MainLightColor.rgb; \ - float3 lightDirection = lilGetLightDirection(); \ + float3 lightDirection = input.lightDirection; \ float3 lightmapColor = lilGetLightMapColor(input.uvLM); \ lightColor = saturate(lightColor + lightmapColor) #else // Realtime #define LIL_GET_MAINLIGHT(input,lightColor,lightDirection,atten) \ LIL_LIGHT_ATTENUATION(atten, input); \ - float3 lightColor = LIL_GET_LIGHTCOLOR; \ - float3 lightDirection = lilGetLightDirection(); \ - float3 lightmapColor = 0 + float3 lightColor = input.lightColor; \ + float3 lightDirection = input.lightDirection; #endif // Vertex Light diff --git a/Assets/lilFurGenerator/Shader/lil_fur_main.hlsl b/Assets/lilFurGenerator/Shader/lil_fur_main.hlsl index e9ddbda..c761bf6 100644 --- a/Assets/lilFurGenerator/Shader/lil_fur_main.hlsl +++ b/Assets/lilFurGenerator/Shader/lil_fur_main.hlsl @@ -1,6 +1,10 @@ #ifndef LIL_MAIN_INCLUDED #define LIL_MAIN_INCLUDED +//------------------------------------------------------------------------------------------------------------------------------ +// Setting +#include "lil_fur_setting.hlsl" + //------------------------------------------------------------------------------------------------------------------------------ // Struct struct appdata @@ -24,10 +28,12 @@ struct v2f #if !defined(LIL_PASS_FORWARDADD) float3 normalWS : TEXCOORD3; #endif - LIL_VERTEXLIGHT_COORDS(4) - LIL_FOG_COORDS(5) - LIL_SHADOW_COORDS(6) - LIL_LIGHTMAP_COORDS(7) + LIL_LIGHTCOLOR_COORDS(4) + LIL_LIGHTDIRECTION_COORDS(5) + LIL_VERTEXLIGHT_COORDS(6) + LIL_FOG_COORDS(7) + LIL_SHADOW_COORDS(8) + LIL_LIGHTMAP_COORDS(9) LIL_VERTEX_INPUT_INSTANCE_ID LIL_VERTEX_OUTPUT_STEREO }; @@ -56,14 +62,17 @@ v2f vert(appdata input) //---------------------------------------------------------------------------------------------------------------------- // Clipping Canceller - #if defined(UNITY_REVERSED_Z) - // DirectX - if(_UseClippingCanceller && output.positionCS.w < _ProjectionParams.y * 1.01 && output.positionCS.w > 0) output.positionCS.z = output.positionCS.z * 0.0001 + output.positionCS.w * 0.999; - #else - // OpenGL - if(_UseClippingCanceller && output.positionCS.w < _ProjectionParams.y * 1.01 && output.positionCS.w > 0) output.positionCS.z = output.positionCS.z * 0.0001 - output.positionCS.w * 0.999; + #if defined(LIL_FEATURE_CLIPPING_CANCELLER) + #if defined(UNITY_REVERSED_Z) + // DirectX + if(_UseClippingCanceller && output.positionCS.w < _ProjectionParams.y * 1.01 && output.positionCS.w > 0) output.positionCS.z = output.positionCS.z * 0.0001 + output.positionCS.w * 0.999; + #else + // OpenGL + if(_UseClippingCanceller && output.positionCS.w < _ProjectionParams.y * 1.01 && output.positionCS.w > 0) output.positionCS.z = output.positionCS.z * 0.0001 - output.positionCS.w * 0.999; + #endif #endif + LIL_CALC_MAINLIGHT(output, output); LIL_TRANSFER_SHADOW(output, input.uv1, output); LIL_TRANSFER_FOG(output, output); LIL_TRANSFER_LIGHTMAPUV(input.uv1, output); @@ -79,8 +88,15 @@ float4 frag(v2f input) : SV_Target LIL_GET_VERTEXLIGHT(input, vertexLightColor); LIL_GET_ADDITIONALLIGHT(input.positionWS, additionalLightColor); #if !defined(LIL_PASS_FORWARDADD) - lightColor = lerp(lightColor, 1.0, _AsUnlit); - float3 addLightColor = lerp(vertexLightColor + additionalLightColor, 0.0, _AsUnlit); + #if defined(LIL_USE_LIGHTMAP) + lightColor = max(lightColor, _LightMinLimit); + lightColor = lerp(lightColor, 1.0, _AsUnlit); + #endif + #if defined(_ADDITIONAL_LIGHTS) + float3 addLightColor = vertexLightColor + lerp(additionalLightColor, 0.0, _AsUnlit); + #else + float3 addLightColor = vertexLightColor; + #endif #else lightColor = lerp(lightColor, 0.0, _AsUnlit); #endif @@ -95,7 +111,7 @@ float4 frag(v2f input) : SV_Target col.a = input.uv4.y > -0.5 ? col.a * saturate(LIL_SAMPLE_2D(_FurMap, sampler_linear_repeatU_clampV, input.uv4).a) : col.a; clip(col.a - _Cutoff); #else - col.a = input.uv4.y > -0.5 ? col.a * saturate(LIL_SAMPLE_2D(_FurMap, sampler_linear_repeatU_clampV, input.uv4).a + fwidth(input.uv4.y) * 2.0) : col.a; + col.a = input.uv4.y > -0.5 ? col.a * saturate(LIL_SAMPLE_2D(_FurMap, sampler_linear_repeatU_clampV, input.uv4).a) : col.a; col.a = saturate((col.a - _Cutoff) / max(fwidth(col.a), 0.0001) + 0.5); clip(col.a); #endif @@ -106,38 +122,44 @@ float4 frag(v2f input) : SV_Target float3 albedo = col.rgb; #if !defined(LIL_PASS_FORWARDADD) - float3 normalDirection = normalize(input.normalWS); - float ln = saturate(dot(lightDirection,normalDirection)*0.5+0.5); + #if defined(LIL_FEATURE_SHADOW) + float3 normalDirection = normalize(input.normalWS); + float ln = saturate(dot(lightDirection,normalDirection)*0.5+0.5); - // Shadow - #if defined(LIL_USE_SHADOW) || defined(LIL_LIGHTMODE_SHADOWMASK) - if(_ShadowReceive) ln *= saturate(attenuation + distance(lightDirection, _MainLightPosition.xyz)); - #endif + // Shadow + #if (defined(LIL_USE_SHADOW) || defined(LIL_LIGHTMODE_SHADOWMASK)) && defined(LIL_FEATURE_RECEIVE_SHADOW) + if(_ShadowReceive) ln *= saturate(attenuation + distance(lightDirection, _MainLightPosition.xyz)); + #endif - float lnB = ln; + float lnB = ln; - // Toon - ln = lilTooning(ln, _ShadowBorder, _ShadowBlur); - lnB = lilTooning(lnB, _ShadowBorder, _ShadowBlur, _ShadowBorderRange); + // Toon + ln = lilTooning(ln, _ShadowBorder, _ShadowBlur); + lnB = lilTooning(lnB, _ShadowBorder, _ShadowBlur, _ShadowBorderRange); - col.rgb = lerp(albedo * _ShadowColor.rgb, col.rgb, ln); - col.rgb = lerp(col.rgb, albedo, lnB * _ShadowBorderColor.rgb); + col.rgb = lerp(albedo * _ShadowColor.rgb, col.rgb, ln); + col.rgb = lerp(col.rgb, albedo, lnB * _ShadowBorderColor.rgb); - col.rgb *= lightColor; - col.rgb += albedo * addLightColor; - col.rgb = clamp(col.rgb, albedo * _LightMinLimit, albedo); + col.rgb *= lightColor; + col.rgb += albedo * addLightColor; + col.rgb = min(col.rgb, albedo); + #else + col.rgb *= saturate(lightColor + addLightColor); + #endif #else col.rgb *= lightColor; #endif //-------------------------------------------------------------------------------------------------------------------------- // Distance Fade - float depth = length(LIL_GET_VIEWDIR_WS(input.positionWS.xyz)); - float distFade = saturate((depth - _DistanceFade.x) / (_DistanceFade.y - _DistanceFade.x)) * _DistanceFade.z; - #if defined(LIL_PASS_FORWARDADD) - col.rgb = lerp(col.rgb, 0.0, distFade); - #else - col.rgb = lerp(col.rgb, _DistanceFadeColor.rgb, distFade); + #if defined(LIL_FEATURE_DISTANCE_FADE) + float depth = length(LIL_GET_VIEWDIR_WS(input.positionWS.xyz)); + float distFade = saturate((depth - _DistanceFade.x) / (_DistanceFade.y - _DistanceFade.x)) * _DistanceFade.z; + #if defined(LIL_PASS_FORWARDADD) + col.rgb = lerp(col.rgb, 0.0, distFade); + #else + col.rgb = lerp(col.rgb, _DistanceFadeColor.rgb, distFade); + #endif #endif //------------------------------------------------------------------------------------------------------------------------- diff --git a/Assets/lilFurGenerator/Shader/lil_fur_setting.hlsl b/Assets/lilFurGenerator/Shader/lil_fur_setting.hlsl new file mode 100644 index 0000000..48301e8 --- /dev/null +++ b/Assets/lilFurGenerator/Shader/lil_fur_setting.hlsl @@ -0,0 +1,6 @@ +#ifndef LIL_FUR_SETTING_INCLUDED +#define LIL_FUR_SETTING_INCLUDED + +#define LIL_FEATURE_SHADOW + +#endif \ No newline at end of file diff --git a/Assets/lilFurGenerator/Shader/lil_fur_setting.hlsl.meta b/Assets/lilFurGenerator/Shader/lil_fur_setting.hlsl.meta new file mode 100644 index 0000000..8295974 --- /dev/null +++ b/Assets/lilFurGenerator/Shader/lil_fur_setting.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f79e08f45a0f3b640b563a49ff855b0c +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/lilFurGenerator/package.json b/Assets/lilFurGenerator/package.json index 68884b6..072d688 100644 --- a/Assets/lilFurGenerator/package.json +++ b/Assets/lilFurGenerator/package.json @@ -1,7 +1,7 @@ { "name": "jp.lilxyzw.lilfurgenerator", "displayName": "lilFurGenerator", - "version": "1.0.0", + "version": "1.0.1", "unity": "2017.1", "description": "Fur generator for Unity.", "keywords": ["Fur", "Shader", "Material"], diff --git a/version.json b/version.json index 40f1738..6ea6f73 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"latest_vertion_name": "1.0.0", "latest_vertion_value": 1} \ No newline at end of file +{"latest_vertion_name": "1.0.1", "latest_vertion_value": 2} \ No newline at end of file