From c30b8479ea1ad2edbdbae3b01052d26b91bafc57 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Mon, 19 Apr 2021 18:49:01 -0400 Subject: [PATCH 01/30] fix inspector setting blend mode every frame to allow users to override the render queue --- Editor/XSToonInspector.cs | 106 +++++++++------ Main/Shaders/XSToon2.0 Outlined.shader | 2 + Main/Shaders/XSToon2.0.shader | 2 + Main/Test.mat | 18 ++- Refract.mat | 181 +++++++++++++++++++++++++ Refract.mat.meta | 8 ++ XSToon 2.0 _ StippledHalftone.mat | 17 ++- XSToon 2.0.mat | 61 ++++++++- 8 files changed, 344 insertions(+), 51 deletions(-) create mode 100644 Refract.mat create mode 100644 Refract.mat.meta diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 20fcc52..7400010 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -156,6 +156,8 @@ public class XSToonInspector : ShaderGUI private static bool showRefractionSettings = false; private static bool showDissolveSettings = false; + private static int BlendMode; + private bool isPatreonShader = false; private bool isEyeTracking = false; private bool isOutlined = false; @@ -218,50 +220,68 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro private void DoBlendModeSettings(Material material) { - int mode = material.GetInt("_BlendMode"); - switch (mode) + int currentBlendMode = material.GetInt("_BlendMode"); + if (BlendMode != currentBlendMode) { - case 0: //Opaque - SetBlend(material, (int)UnityEngine.Rendering.BlendMode.One, (int)UnityEngine.Rendering.BlendMode.Zero, (int)UnityEngine.Rendering.RenderQueue.Geometry, 1, 0); - material.DisableKeyword("_ALPHABLEND_ON"); - material.DisableKeyword("_ALPHATEST_ON"); - break; - - case 1: //Cutout - SetBlend(material, (int)UnityEngine.Rendering.BlendMode.One, (int)UnityEngine.Rendering.BlendMode.Zero, (int)UnityEngine.Rendering.RenderQueue.AlphaTest, 1, 0); - material.DisableKeyword("_ALPHABLEND_ON"); - material.EnableKeyword("_ALPHATEST_ON"); - break; - - case 2: //Dithered - SetBlend(material, (int)UnityEngine.Rendering.BlendMode.One, (int)UnityEngine.Rendering.BlendMode.Zero, (int)UnityEngine.Rendering.RenderQueue.AlphaTest, 1, 0); - material.DisableKeyword("_ALPHABLEND_ON"); - material.EnableKeyword("_ALPHATEST_ON"); - break; - - case 3: //Alpha To Coverage - SetBlend(material, (int)UnityEngine.Rendering.BlendMode.One, (int)UnityEngine.Rendering.BlendMode.Zero, (int)UnityEngine.Rendering.RenderQueue.AlphaTest, 1, 1); - material.DisableKeyword("_ALPHABLEND_ON"); - material.EnableKeyword("_ALPHATEST_ON"); - break; - - case 4: //Transparent - SetBlend(material, (int)UnityEngine.Rendering.BlendMode.One, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha, (int)UnityEngine.Rendering.RenderQueue.Transparent, 0, 0); - material.EnableKeyword("_ALPHABLEND_ON"); - material.DisableKeyword("_ALPHATEST_ON"); - break; - - case 5: //Fade - SetBlend(material, (int)UnityEngine.Rendering.BlendMode.SrcAlpha, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha, (int)UnityEngine.Rendering.RenderQueue.Transparent, 0, 0); - material.EnableKeyword("_ALPHABLEND_ON"); - material.DisableKeyword("_ALPHATEST_ON"); - break; - - case 6: //Additive - SetBlend(material, (int)UnityEngine.Rendering.BlendMode.One, (int)UnityEngine.Rendering.BlendMode.One, (int)UnityEngine.Rendering.RenderQueue.Transparent, 0, 0); - material.DisableKeyword("_ALPHABLEND_ON"); - material.DisableKeyword("_ALPHATEST_ON"); - break; + BlendMode = currentBlendMode; + switch (BlendMode) + { + case 0: //Opaque + SetBlend(material, (int) UnityEngine.Rendering.BlendMode.One, + (int) UnityEngine.Rendering.BlendMode.Zero, + (int) UnityEngine.Rendering.RenderQueue.Geometry, 1, 0); + material.DisableKeyword("_ALPHABLEND_ON"); + material.DisableKeyword("_ALPHATEST_ON"); + break; + + case 1: //Cutout + SetBlend(material, (int) UnityEngine.Rendering.BlendMode.One, + (int) UnityEngine.Rendering.BlendMode.Zero, + (int) UnityEngine.Rendering.RenderQueue.AlphaTest, 1, 0); + material.DisableKeyword("_ALPHABLEND_ON"); + material.EnableKeyword("_ALPHATEST_ON"); + break; + + case 2: //Dithered + SetBlend(material, (int) UnityEngine.Rendering.BlendMode.One, + (int) UnityEngine.Rendering.BlendMode.Zero, + (int) UnityEngine.Rendering.RenderQueue.AlphaTest, 1, 0); + material.DisableKeyword("_ALPHABLEND_ON"); + material.EnableKeyword("_ALPHATEST_ON"); + break; + + case 3: //Alpha To Coverage + SetBlend(material, (int) UnityEngine.Rendering.BlendMode.One, + (int) UnityEngine.Rendering.BlendMode.Zero, + (int) UnityEngine.Rendering.RenderQueue.AlphaTest, 1, 1); + material.DisableKeyword("_ALPHABLEND_ON"); + material.EnableKeyword("_ALPHATEST_ON"); + break; + + case 4: //Transparent + SetBlend(material, (int) UnityEngine.Rendering.BlendMode.One, + (int) UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha, + (int) UnityEngine.Rendering.RenderQueue.Transparent, 0, 0); + material.EnableKeyword("_ALPHABLEND_ON"); + material.DisableKeyword("_ALPHATEST_ON"); + break; + + case 5: //Fade + SetBlend(material, (int) UnityEngine.Rendering.BlendMode.SrcAlpha, + (int) UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha, + (int) UnityEngine.Rendering.RenderQueue.Transparent, 0, 0); + material.EnableKeyword("_ALPHABLEND_ON"); + material.DisableKeyword("_ALPHATEST_ON"); + break; + + case 6: //Additive + SetBlend(material, (int) UnityEngine.Rendering.BlendMode.One, + (int) UnityEngine.Rendering.BlendMode.One, + (int) UnityEngine.Rendering.RenderQueue.Transparent, 0, 0); + material.DisableKeyword("_ALPHABLEND_ON"); + material.DisableKeyword("_ALPHATEST_ON"); + break; + } } } diff --git a/Main/Shaders/XSToon2.0 Outlined.shader b/Main/Shaders/XSToon2.0 Outlined.shader index 8cbb342..853af2e 100644 --- a/Main/Shaders/XSToon2.0 Outlined.shader +++ b/Main/Shaders/XSToon2.0 Outlined.shader @@ -124,6 +124,8 @@ [Enum(UV1,0,UV2,1)] _UVSetDissolve("Dissolve Map UVs", Int) = 0 _ClipMap("Clip Map", 2D) = "black" {} + _WireColor("Wire Color", Color) = (0,0,0,0) + _WireWidth("Wire Width", Float) = 0 [HideInInspector][Enum(Basic, 0, Advanced, 1)]_AdvMode("Shader Mode", Int) = 0 [IntRange] _Stencil ("Stencil ID [0;255]", Range(0,255)) = 0 [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Comparison", Int) = 0 diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon2.0.shader index c6d5896..69754b6 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon2.0.shader @@ -124,6 +124,8 @@ [Enum(UV1,0,UV2,1)] _UVSetDissolve("Dissolve Map UVs", Int) = 0 _ClipMap("Clip Map", 2D) = "black" {} + _WireColor("Wire Color", Color) = (0,0,0,0) + _WireWidth("Wire Width", Float) = 0 [HideInInspector][Enum(Basic, 0, Advanced, 1)]_AdvMode("Shader Mode", Int) = 0 [IntRange] _Stencil ("Stencil ID [0;255]", Range(0,255)) = 0 [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Comparison", Int) = 0 diff --git a/Main/Test.mat b/Main/Test.mat index 518c347..697f6a8 100644 --- a/Main/Test.mat +++ b/Main/Test.mat @@ -15,7 +15,8 @@ Material: m_DoubleSidedGI: 0 m_CustomRenderQueue: 3000 stringTagMap: {} - disabledShaderPasses: [] + disabledShaderPasses: + - ALWAYS m_SavedProperties: serializedVersion: 3 m_TexEnvs: @@ -43,6 +44,10 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _DissolveTexture: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _EmissionMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -108,6 +113,9 @@ Material: - _Culling: 2 - _Cutoff: 0.5 - _DetailNormalMapScale: 1 + - _DissolveCoordinates: 0 + - _DissolveProgress: 0 + - _DissolveStrength: 1 - _DstBlend: 10 - _EmissionToDiffuse: 0 - _FadeDither: 0 @@ -121,6 +129,7 @@ Material: - _HalftoneLineIntensity: 1 - _HalftoneType: 3 - _Hue: 0 + - _IOR: 0 - _MatcapTintToDiffuse: 0 - _Metallic: 0 - _Mode: 0 @@ -130,11 +139,14 @@ Material: - _OcclusionStrength: 1 - _OutlineAlbedoTint: 0 - _OutlineLighting: 0 + - _OutlineNormalMode: 0 + - _OutlineUVSelect: 2 - _OutlineWidth: 1 - _Parallax: 0.02 - _ReflectionBlendMode: 0 - _ReflectionMode: 0 - _Reflectivity: 1 + - _RefractionModel: 0 - _RimAlbedoTint: 0 - _RimAttenEffect: 1 - _RimCubemapTint: 0 @@ -169,6 +181,7 @@ Material: - _UVSetClipMap: 0 - _UVSetDetMask: 0 - _UVSetDetNormal: 0 + - _UVSetDissolve: 0 - _UVSetEmission: 0 - _UVSetMetallic: 0 - _UVSetNormal: 0 @@ -176,6 +189,8 @@ Material: - _UVSetReflectivity: 0 - _UVSetSpecular: 0 - _UVSetThickness: 0 + - _UseClipsForDissolve: 0 + - _UseRefraction: 0 - _Value: 1 - _VertexColorAlbedo: 0 - _ZWrite: 0 @@ -183,6 +198,7 @@ Material: - _ClipAgainstVertexColorGreaterZeroFive: {r: 1, g: 1, b: 1, a: 1} - _ClipAgainstVertexColorLessZeroFive: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 0, g: 0, b: 0, a: 0} + - _DissolveColor: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _MatcapTint: {r: 1, g: 1, b: 1, a: 1} - _OcclusionColor: {r: 0, g: 0, b: 0, a: 0} diff --git a/Refract.mat b/Refract.mat new file mode 100644 index 0000000..9cbb2c6 --- /dev/null +++ b/Refract.mat @@ -0,0 +1,181 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Refract + m_Shader: {fileID: 4800000, guid: 85c615217d617204cb497ae6838b8bae, type: 3} + m_ShaderKeywords: _COLOROVERLAY_ON + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: 3999 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BakedCubemap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ClipMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _HSVMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Matcap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OutlineMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Ramp: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _RampSelectionMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ReflectivityMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecularMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ThicknessMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _AdvMode: 0 + - _AlphaToMask: 0 + - _AnisotropicReflection: 0 + - _AnisotropicSpecular: 0 + - _BlendMode: 0 + - _BumpScale: 1 + - _ClearCoat: 0 + - _ClearcoatSmoothness: 0.8 + - _ClearcoatStrength: 1 + - _Culling: 2 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _EmissionToDiffuse: 0 + - _FadeDither: 0 + - _FadeDitherDistance: 0 + - _Glossiness: 0.977 + - _HalftoneDotAmount: 5 + - _HalftoneDotSize: 0.5 + - _HalftoneLineAmount: 2000 + - _HalftoneLineIntensity: 1 + - _HalftoneType: 3 + - _Hue: 0 + - _IOR: 4 + - _MatcapTintToDiffuse: 0 + - _Metallic: 0 + - _NormalMapMode: 0 + - _OcclusionIntensity: 1 + - _OcclusionMode: 0 + - _OutlineAlbedoTint: 0 + - _OutlineLighting: 0 + - _OutlineNormalMode: 0 + - _OutlineUVSelect: 2 + - _OutlineWidth: 1 + - _ReflectionBlendMode: 0 + - _ReflectionMode: 0 + - _Reflectivity: 0.623 + - _RefractionModel: 2 + - _RimAlbedoTint: 0 + - _RimAttenEffect: 1 + - _RimCubemapTint: 0 + - _RimIntensity: 0 + - _RimRange: 0.7 + - _RimSharpness: 0.1 + - _RimThreshold: 0.1 + - _SSDistortion: 1 + - _SSPower: 1 + - _SSScale: 1 + - _Saturation: 1 + - _ScaleWithLight: 1 + - _ScaleWithLightSensitivity: 1 + - _ShadowRimAlbedoTint: 0 + - _ShadowRimRange: 1 + - _ShadowRimSharpness: 0.3 + - _ShadowRimThreshold: 0.1 + - _ShadowSharpness: 0.5 + - _SpecularAlbedoTint: 0 + - _SpecularArea: 0 + - _SpecularIntensity: 1 + - _SpecularSharpness: 0 + - _SrcBlend: 1 + - _Stencil: 0 + - _StencilComp: 0 + - _StencilOp: 0 + - _TilingMode: 0 + - _UVSetAlbedo: 0 + - _UVSetClipMap: 0 + - _UVSetDetMask: 0 + - _UVSetDetNormal: 0 + - _UVSetEmission: 0 + - _UVSetMetallic: 0 + - _UVSetNormal: 0 + - _UVSetOcclusion: 0 + - _UVSetReflectivity: 0 + - _UVSetSpecular: 0 + - _UVSetThickness: 0 + - _UseRefraction: 1 + - _Value: 1 + - _VertexColorAlbedo: 0 + - _ZWrite: 1 + - __dirty: 0 + m_Colors: + - _ClipAgainstVertexColorGreaterZeroFive: {r: 1, g: 1, b: 1, a: 1} + - _ClipAgainstVertexColorLessZeroFive: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 0.5962642, g: 0.647977, b: 0.6509434, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} + - _MatcapTint: {r: 1, g: 1, b: 1, a: 1} + - _OutlineColor: {r: 0, g: 0, b: 0, a: 1} + - _RimColor: {r: 1, g: 1, b: 1, a: 1} + - _SSColor: {r: 0, g: 0, b: 0, a: 0} + - _ShadowRim: {r: 1, g: 1, b: 1, a: 1} diff --git a/Refract.mat.meta b/Refract.mat.meta new file mode 100644 index 0000000..ddca69c --- /dev/null +++ b/Refract.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6e5ae873c031ae54ba21280aa0a52fe5 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/XSToon 2.0 _ StippledHalftone.mat b/XSToon 2.0 _ StippledHalftone.mat index 0d1845b..e122eb2 100644 --- a/XSToon 2.0 _ StippledHalftone.mat +++ b/XSToon 2.0 _ StippledHalftone.mat @@ -4,9 +4,10 @@ Material: serializedVersion: 6 m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_Name: XSToon 2.0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: XSToon 2.0 _ StippledHalftone m_Shader: {fileID: 4800000, guid: 85c615217d617204cb497ae6838b8bae, type: 3} m_ShaderKeywords: m_LightmapFlags: 6 @@ -94,11 +95,19 @@ Material: - _HalftoneDotAmount: 50 - _HalftoneDotSize: 1.7 - _HalftoneLineAmount: 150 + - _HalftoneLineIntensity: 1 + - _HalftoneType: 3 + - _MatcapTintToDiffuse: 0 - _Metallic: 0 + - _OutlineAlbedoTint: 0 + - _OutlineLighting: 0 - _OutlineWidth: 1 - _ReflectionBlendMode: 0 - _ReflectionMode: 3 - _Reflectivity: 1 + - _RimAlbedoTint: 0 + - _RimAttenEffect: 1 + - _RimCubemapTint: 0 - _RimIntensity: 0 - _RimRange: 0.7 - _RimSharpness: 0.1 @@ -111,6 +120,7 @@ Material: - _Saturation: 1 - _ScaleWithLight: 1 - _ScaleWithLightSensitivity: 1 + - _ShadowRimAlbedoTint: 0 - _ShadowRimRange: 0.7 - _ShadowRimSharpness: 0.3 - _ShadowRimThreshold: 0.1 @@ -134,6 +144,7 @@ Material: - _UVSetReflectivity: 0 - _UVSetSpecular: 0 - _UVSetThickness: 0 + - _VertexColorAlbedo: 0 m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} diff --git a/XSToon 2.0.mat b/XSToon 2.0.mat index 0d1845b..119f34d 100644 --- a/XSToon 2.0.mat +++ b/XSToon 2.0.mat @@ -4,17 +4,19 @@ Material: serializedVersion: 6 m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} m_Name: XSToon 2.0 m_Shader: {fileID: 4800000, guid: 85c615217d617204cb497ae6838b8bae, type: 3} m_ShaderKeywords: m_LightmapFlags: 6 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 + m_CustomRenderQueue: 2000 stringTagMap: {} - disabledShaderPasses: [] + disabledShaderPasses: + - ALWAYS m_SavedProperties: serializedVersion: 3 m_TexEnvs: @@ -26,6 +28,10 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _ClipMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _DetailMask: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -34,10 +40,18 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _DissolveTexture: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _EmissionMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _HSVMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _MainTex: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -80,8 +94,12 @@ Material: m_Offset: {x: 0, y: 0} m_Floats: - _AdvMode: 0 + - _AlphaToMask: 0 - _AnisotropicAX: 0.25 - _AnisotropicAY: 0.75 + - _AnisotropicReflection: 0 + - _AnisotropicSpecular: 0 + - _BlendMode: 0 - _BumpScale: 1 - _ClearCoat: 0 - _ClearcoatSmoothness: 0.8 @@ -89,16 +107,38 @@ Material: - _Culling: 2 - _Cutoff: 0.5 - _DetailNormalMapScale: 1 + - _DissolveCoordinates: 0 + - _DissolveProgress: 0 + - _DissolveStrength: 1 + - _DstBlend: 0 - _EmissionToDiffuse: 0 + - _FadeDither: 0 + - _FadeDitherDistance: 0 - _Glossiness: 0 - _HalftoneDotAmount: 50 - _HalftoneDotSize: 1.7 - _HalftoneLineAmount: 150 + - _HalftoneLineIntensity: 1 + - _HalftoneType: 3 + - _Hue: 0 + - _IOR: 0 + - _MatcapTintToDiffuse: 0 - _Metallic: 0 + - _NormalMapMode: 0 + - _OcclusionIntensity: 1 + - _OcclusionMode: 0 + - _OutlineAlbedoTint: 0 + - _OutlineLighting: 0 + - _OutlineNormalMode: 0 + - _OutlineUVSelect: 2 - _OutlineWidth: 1 - _ReflectionBlendMode: 0 - _ReflectionMode: 3 - _Reflectivity: 1 + - _RefractionModel: 0 + - _RimAlbedoTint: 0 + - _RimAttenEffect: 1 + - _RimCubemapTint: 0 - _RimIntensity: 0 - _RimRange: 0.7 - _RimSharpness: 0.1 @@ -111,6 +151,7 @@ Material: - _Saturation: 1 - _ScaleWithLight: 1 - _ScaleWithLightSensitivity: 1 + - _ShadowRimAlbedoTint: 0 - _ShadowRimRange: 0.7 - _ShadowRimSharpness: 0.3 - _ShadowRimThreshold: 0.1 @@ -119,14 +160,18 @@ Material: - _SpecularAlbedoTint: 1 - _SpecularArea: 0.5 - _SpecularIntensity: 0 + - _SpecularSharpness: 0 - _SpecularStyle: 0 + - _SrcBlend: 1 - _Stencil: 0 - _StencilComp: 0 - _StencilOp: 0 - _TilingMode: 0 - _UVSetAlbedo: 0 + - _UVSetClipMap: 0 - _UVSetDetMask: 0 - _UVSetDetNormal: 0 + - _UVSetDissolve: 0 - _UVSetEmission: 0 - _UVSetMetallic: 0 - _UVSetNormal: 0 @@ -134,8 +179,16 @@ Material: - _UVSetReflectivity: 0 - _UVSetSpecular: 0 - _UVSetThickness: 0 + - _UseClipsForDissolve: 0 + - _UseRefraction: 0 + - _Value: 1 + - _VertexColorAlbedo: 0 + - _ZWrite: 1 m_Colors: + - _ClipAgainstVertexColorGreaterZeroFive: {r: 1, g: 1, b: 1, a: 1} + - _ClipAgainstVertexColorLessZeroFive: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1} + - _DissolveColor: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} - _MatcapTint: {r: 1, g: 1, b: 1, a: 1} - _OcclusionColor: {r: 0, g: 0, b: 0, a: 0} From 7ffa8d241bc18e942596fe7159a858b830f5d868 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 28 Apr 2021 15:43:23 -0400 Subject: [PATCH 02/30] new masking stuff --- Editor/TextureList.cs | 11 ++ Editor/TextureList.cs.meta | 11 ++ Editor/XSClipMapEditor.cs | 227 ++++++++++++++++++++++++ Editor/XSClipMapEditor.cs.meta | 12 ++ Editor/XSStyles.cs | 19 +- Editor/XSToonInspector.cs | 127 +++++++++---- Main/CGIncludes/XSDefines.cginc | 7 + Main/CGIncludes/XSFrag.cginc | 17 +- Main/CGIncludes/XSHelperFunctions.cginc | 36 +++- Main/CGIncludes/XSVert.cginc | 5 +- Main/Shaders/XSToon2.0 Outlined.shader | 22 +++ Main/Shaders/XSToon2.0.shader | 22 +++ 12 files changed, 465 insertions(+), 51 deletions(-) create mode 100644 Editor/TextureList.cs create mode 100644 Editor/TextureList.cs.meta create mode 100644 Editor/XSClipMapEditor.cs create mode 100644 Editor/XSClipMapEditor.cs.meta diff --git a/Editor/TextureList.cs b/Editor/TextureList.cs new file mode 100644 index 0000000..da53b3d --- /dev/null +++ b/Editor/TextureList.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace XSToon +{ + public class TextureList : ScriptableObject + { + public Texture2D[] TexArray; + } +} diff --git a/Editor/TextureList.cs.meta b/Editor/TextureList.cs.meta new file mode 100644 index 0000000..aebb6d5 --- /dev/null +++ b/Editor/TextureList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35a9673cde67b134bb3a80750a72687d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/XSClipMapEditor.cs b/Editor/XSClipMapEditor.cs new file mode 100644 index 0000000..4221bb7 --- /dev/null +++ b/Editor/XSClipMapEditor.cs @@ -0,0 +1,227 @@ +using UnityEngine; +using UnityEditor; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System; +using UnityEditorInternal; + +namespace XSToon +{ + public class XSClipMapEditor : EditorWindow + { + [MenuItem("Tools/Xiexe/XSToon/Clip Map Editor")] + static public void Init() + { + XSClipMapEditor window = EditorWindow.GetWindow(false, "XSToon: Clip Map Editor", true); + window.minSize = new Vector2(350, 330); + window.minSize = new Vector2(350, 330); + } + + private Vector2 ClipScrollPos; + private int ClipMapCount = 1; + public Texture2D[] ClipMaps = new Texture2D[16]; + public static Renderer Rend; + + + public XSToon.TextureList TexList; + private XSToon.TextureList oldTexList; + public string[] filters = new string[] {"Point (No Filtering)", "Bilinear", "Trilinear"}; + public FilterMode filterMode = FilterMode.Bilinear; + + public bool copyMips = true; + public float mipMapBias = 0; + + public string[] wraps = new string[] {"Repeat", "Clamp", "Mirror", "Mirror Once", "Per Axis"}; + public int wrapMode = 0; + public string[] wrapsAxis = new string[] {"Repeat", "Clamp", "Mirror", "Mirror Once"}; + public TextureWrapMode wrapModeU = TextureWrapMode.Repeat; + public TextureWrapMode wrapModeV = TextureWrapMode.Repeat; + + public int anisoLevel = 1; + + public struct TextureSettings + { + public FilterMode filterMode; + public bool copyMips; + public float mipMapBias; + public TextureWrapMode wrapModeU; + public TextureWrapMode wrapModeV; + public int anisoLevel; + } + + public bool showProperties = false; + + public void OnGUI() + { + XSStyles.ShurikenHeaderCentered("Clip Map Editor"); + XSStyles.HelpBox("All images must have the exact same dimensions, format, and number of mip levels!", MessageType.Info); + + XSStyles.SeparatorThin(); + ClipMapCount = EditorGUILayout.IntSlider("Count: ", ClipMapCount, 1, 16); + XSStyles.SeparatorThin(); + ClipScrollPos = EditorGUILayout.BeginScrollView(ClipScrollPos); + for (int i = 0; i < ClipMapCount; i++) + { + ClipMaps[i] = (Texture2D)EditorGUILayout.ObjectField($"Clip Map {i}:", ClipMaps[i], typeof(Texture2D)); + } + EditorGUILayout.EndScrollView(); + XSStyles.SeparatorThin(); + GUI2DArray(); + XSStyles.SeparatorThin(); + if (GUILayout.Button("Create Array")) + { + CreateTextureArray(); + if (Rend != null) + { + for (int i = 0; i < Rend.sharedMaterials.Length; i++) + { + if (Rend.sharedMaterials[i].HasProperty("_ClipMaskArray")) + { + Debug.Log( + $"Material {Rend.sharedMaterials[i].name} is supported, auto assigning TexArray."); + } + } + } + } + GUILayout.Space(8); + } + + private void CreateTextureArray() + { + TextureSettings settings = new TextureSettings(); + settings.filterMode = filterMode; + settings.copyMips = copyMips; + settings.mipMapBias = mipMapBias; + settings.wrapModeU = wrapModeU; + settings.wrapModeV = wrapModeV; + settings.anisoLevel = anisoLevel; + CopyListIntoArray(TexList, settings); + } + + private void GUI2DArray() + { + /* Do we want mip maps? if so, copy them from the source textures **/ + copyMips = EditorGUILayout.Toggle("Copy Mip Maps", copyMips); + if (copyMips) + { + mipMapBias = EditorGUILayout.FloatField(" Mip Map Bias", mipMapBias); + } + + filterMode = (FilterMode) EditorGUILayout.Popup("Filter Mode", (int) filterMode, filters); + + /* Set the wrap mode to the same value on both axes unless wrapMode is 4 (Per Axis), then show separate options**/ + wrapMode = EditorGUILayout.Popup("Wrap Mode", wrapMode, wraps); + if (wrapMode == 4) + { + wrapModeU = (TextureWrapMode) EditorGUILayout.Popup(" U Axis", (int) wrapModeU, wrapsAxis); + wrapModeV = (TextureWrapMode) EditorGUILayout.Popup(" V Axis", (int) wrapModeV, wrapsAxis); + } + else + { + wrapModeU = (TextureWrapMode) wrapMode; + wrapModeV = (TextureWrapMode) wrapMode; + } + + anisoLevel = EditorGUILayout.IntSlider("Aniso Level", anisoLevel, 0, 16); + } + + private bool HasSameSettings(Texture2D first, Texture2D nth, int index) + { + + int fail = 0; + if (first.width == nth.width && first.height == nth.height) + { + if (first.format == nth.format) + { + if (first.mipmapCount != nth.mipmapCount) + fail = 3; + } + else fail = 2; + } + else fail = 1; + + switch (fail) + { + case 1: + EditorUtility.DisplayDialog("Textures not the same dimensions", + string.Format("Texture {0} has size of {1}x{2}, expected {3}x{4}", + index, nth.width, nth.height, first.width, first.height), + "ok"); + return false; + case 2: + EditorUtility.DisplayDialog("Textures not the format", + string.Format("Texture {0} has {1} format, expected {2}", + index, nth.format.ToString(), first.format.ToString()), + "ok"); + return false; + case 3: + EditorUtility.DisplayDialog("Not all Textures have the same number of mip levels", + string.Format("Texture {0} has {1} mip levels, expected {2}", + index, nth.mipmapCount, first.mipmapCount), + "ok"); + return false; + default: + return true; + } + } + + private void CopyListIntoArray(TextureList List, TextureSettings Settings) + { + if (ClipMaps.Length > 0) + { + if (ClipMaps[0] == null) + { + EditorUtility.DisplayDialog("First element unassigned", "Element 0 of the texture list is empty!", + "ok"); + return; + } + + Texture2DArray output = new Texture2DArray(ClipMaps[0].width, ClipMaps[0].height, ClipMaps.Length, ClipMaps[0].format, Settings.copyMips); + output.mipMapBias = Settings.mipMapBias; + output.filterMode = Settings.filterMode; + output.wrapModeU = Settings.wrapModeU; + output.wrapModeV = Settings.wrapModeV; + output.anisoLevel = Settings.anisoLevel; + + bool consistentSettings = true; + for (int i = 0; i < ClipMapCount; i++) + { + /* Stop if one of the elements in the list is empty **/ + if (ClipMaps[i] == null) + { + EditorUtility.DisplayDialog("Element unassigned", + string.Format("Element {0} of the texture list is empty!", i), "ok"); + return; + } + + /* Stop if the texture being copied doesn't have the same settings as the first element of the array **/ + consistentSettings = HasSameSettings(ClipMaps[0], ClipMaps[i], i); + if (consistentSettings == false) + return; + + /* Copy the contents of the texture into the corresponding slice of the Texture2DArray, and copy over all the mips if copyMips is true **/ + if (Settings.copyMips) + { + for (int j = 0; j < ClipMaps[0].mipmapCount; j++) + { + Graphics.CopyTexture(ClipMaps[i], 0, j, output, i, j); + } + } + else + { + Graphics.CopyTexture(ClipMaps[i], 0, 0, output, i, 0); + } + } + + output.Apply(false); + + string path = EditorUtility.SaveFilePanelInProject("Save Array", $"{Rend.name}_texarray.asset", "asset", "Please enter a file name to save the texture array to"); + if (path.Length != 0) + { + AssetDatabase.CreateAsset(output, path); + } + } + } + } +} \ No newline at end of file diff --git a/Editor/XSClipMapEditor.cs.meta b/Editor/XSClipMapEditor.cs.meta new file mode 100644 index 0000000..49e2f85 --- /dev/null +++ b/Editor/XSClipMapEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a58ac6d3f5e8f994ea564383dbcc9802 +timeCreated: 1535928638 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/XSStyles.cs b/Editor/XSStyles.cs index 9a1b4f8..f7d7b75 100644 --- a/Editor/XSStyles.cs +++ b/Editor/XSStyles.cs @@ -87,7 +87,7 @@ static public GUIStyle LineStyle } //GUI Buttons - static public void callGradientEditor(Material focusedMat = null) + static public void CallGradientEditor(Material focusedMat = null) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); @@ -101,6 +101,23 @@ static public void callGradientEditor(Material focusedMat = null) GUILayout.EndHorizontal(); } + static public void CallTexArrayManager() + { + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + GUI.skin = null; + if (GUILayout.Button("Clip Map Manager", GUILayout.Width(200), GUILayout.Height(20))) + { + Renderer rend = Selection.activeGameObject.GetComponent(); + if (rend != null) + XSClipMapEditor.Rend = rend; + + XSClipMapEditor.Init(); + } + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + } + static public void ResetAdv(Material material) { GUILayout.BeginHorizontal(); diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 7400010..2776066 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -129,6 +129,26 @@ public class XSToonInspector : ShaderGUI private MaterialProperty _WireColor = null; private MaterialProperty _WireWidth = null; + //Experimenting + private MaterialProperty _ClipMaskArray = null; + private MaterialProperty _ClipIndex = null; + private MaterialProperty _ClipSlider00 = null; + private MaterialProperty _ClipSlider01 = null; + private MaterialProperty _ClipSlider02 = null; + private MaterialProperty _ClipSlider03 = null; + private MaterialProperty _ClipSlider04 = null; + private MaterialProperty _ClipSlider05 = null; + private MaterialProperty _ClipSlider06 = null; + private MaterialProperty _ClipSlider07 = null; + private MaterialProperty _ClipSlider08 = null; + private MaterialProperty _ClipSlider09 = null; + private MaterialProperty _ClipSlider10 = null; + private MaterialProperty _ClipSlider11 = null; + private MaterialProperty _ClipSlider12 = null; + private MaterialProperty _ClipSlider13 = null; + private MaterialProperty _ClipSlider14 = null; + private MaterialProperty _ClipSlider15 = null; + //Material Properties for Patreon Plugins private MaterialProperty _LeftRightPan = null; private MaterialProperty _UpDownPan = null; @@ -190,32 +210,31 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro } EditorGUI.BeginChangeCheck(); - { - XSStyles.ShurikenHeaderCentered("XSToon v" + XSStyles.ver); - material.SetShaderPassEnabled("Always", isRefractive); - materialEditor.ShaderProperty(_AdvMode, new GUIContent("Shader Mode", "Setting this to 'Advanced' will give you access to things such as stenciling, and other expiremental/advanced features.")); - materialEditor.ShaderProperty(_Culling, new GUIContent("Culling Mode", "Changes the culling mode. 'Off' will result in a two sided material, while 'Front' and 'Back' will cull those sides respectively")); - materialEditor.ShaderProperty(_TilingMode, new GUIContent("Tiling Mode", "Setting this to Merged will tile and offset all textures based on the Main texture's Tiling/Offset.")); - materialEditor.ShaderProperty(_BlendMode, new GUIContent("Blend Mode", "Blend mode of the material. (Opaque, transparent, cutout, etc.)")); - materialEditor.ShaderProperty(_UseRefraction, new GUIContent("Refraction", "Should this material be refractive? (Warning, this can be expensive!)")); - - DoBlendModeSettings(material); - DrawMainSettings(materialEditor); - DrawDissolveSettings(materialEditor); - DrawShadowSettings(materialEditor, material); - DrawOutlineSettings(materialEditor); - DrawNormalSettings(materialEditor); - DrawSpecularSettings(materialEditor); - DrawReflectionsSettings(materialEditor, material); - DrawRefractionSettings(materialEditor); - DrawEmissionSettings(materialEditor); - DrawRimlightSettings(materialEditor); - DrawHalfToneSettings(materialEditor); - DrawTransmissionSettings(materialEditor); - DrawAdvancedSettings(materialEditor); - DrawPatreonSettings(materialEditor); - XSStyles.DoFooter(); - } + XSStyles.ShurikenHeaderCentered("XSToon v" + XSStyles.ver); + material.SetShaderPassEnabled("Always", isRefractive); + materialEditor.ShaderProperty(_AdvMode, new GUIContent("Shader Mode", "Setting this to 'Advanced' will give you access to things such as stenciling, and other expiremental/advanced features.")); + materialEditor.ShaderProperty(_Culling, new GUIContent("Culling Mode", "Changes the culling mode. 'Off' will result in a two sided material, while 'Front' and 'Back' will cull those sides respectively")); + materialEditor.ShaderProperty(_TilingMode, new GUIContent("Tiling Mode", "Setting this to Merged will tile and offset all textures based on the Main texture's Tiling/Offset.")); + materialEditor.ShaderProperty(_BlendMode, new GUIContent("Blend Mode", "Blend mode of the material. (Opaque, transparent, cutout, etc.)")); + materialEditor.ShaderProperty(_UseRefraction, new GUIContent("Refraction", "Should this material be refractive? (Warning, this can be expensive!)")); + + DoBlendModeSettings(material); + DrawMainSettings(materialEditor); + DrawDissolveSettings(materialEditor); + DrawShadowSettings(materialEditor, material); + DrawOutlineSettings(materialEditor); + DrawNormalSettings(materialEditor); + DrawSpecularSettings(materialEditor); + DrawReflectionsSettings(materialEditor, material); + DrawRefractionSettings(materialEditor); + DrawEmissionSettings(materialEditor); + DrawRimlightSettings(materialEditor); + DrawHalfToneSettings(materialEditor); + DrawTransmissionSettings(materialEditor); + DrawAdvancedSettings(materialEditor, material); + DrawPatreonSettings(materialEditor); + XSStyles.DoFooter(); + } private void DoBlendModeSettings(Material material) @@ -363,6 +382,7 @@ private void DrawShadowSettings(MaterialEditor materialEditor, Material material } } + XSStyles.CallGradientEditor(material); materialEditor.TexturePropertySingleLine(new GUIContent("Shadow Ramp", "Shadow Ramp, Dark to Light should be Left to Right"), _Ramp); materialEditor.ShaderProperty(_ShadowSharpness, new GUIContent("Shadow Sharpness", "Controls the sharpness of recieved shadows, as well as the sharpness of 'shadows' from Vertex Lighting.")); @@ -379,7 +399,7 @@ private void DrawShadowSettings(MaterialEditor materialEditor, Material material materialEditor.ShaderProperty(_ShadowRimRange, new GUIContent("Range", "Range of the Shadow Rim"), 2); materialEditor.ShaderProperty(_ShadowRimThreshold, new GUIContent("Threshold", "Threshold of the Shadow Rim"), 2); materialEditor.ShaderProperty(_ShadowRimSharpness, new GUIContent("Sharpness", "Sharpness of the Shadow Rim"), 2); - XSStyles.callGradientEditor(material); + } } @@ -436,8 +456,6 @@ private void DrawSpecularSettings(MaterialEditor materialEditor) showSpecular = XSStyles.ShurikenFoldout("Specular", showSpecular); if (showSpecular) { - XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Specular Map(R,G,B)", "Specular Map. Red channel controls Intensity, Green controls how much specular is tinted by Albedo, and Blue controls Smoothness (Only for Blinn-Phong, and GGX)."), _SpecularMap); materialEditor.TextureScaleOffsetProperty(_SpecularMap); materialEditor.ShaderProperty(_UVSetSpecular, new GUIContent("UV Set", "The UV set to use for the Specular Map"), 2); @@ -603,32 +621,54 @@ private void DrawRefractionSettings(MaterialEditor materialEditor) } } - private void DrawAdvancedSettings(MaterialEditor materialEditor) + private void DrawAdvancedSettings(MaterialEditor materialEditor, Material material) { if (_AdvMode.floatValue == 1) { showAdvanced = XSStyles.ShurikenFoldout("Advanced Settings", showAdvanced); if (showAdvanced) { - materialEditor.ShaderProperty(_VertexColorAlbedo, new GUIContent("Vertex Color Albedo", "Multiplies the vertex color of the mesh by the Albedo texture to derive the final Albedo color.")); if (isDithered || isCutout) { - materialEditor.ShaderProperty(_UseClipsForDissolve, new GUIContent("Control Dissolve With Clip")); - materialEditor.TexturePropertySingleLine(new GUIContent("Clip Map (RGBA)", "Used to control clipping in an advanced manner, read tooltip for Clip Mask Vectors below."), _ClipMap); - materialEditor.TextureScaleOffsetProperty(_ClipMap); + XSStyles.CallTexArrayManager(); + materialEditor.TexturePropertySingleLine(new GUIContent("Clip Map (RGBA | Tex2DArray)", "Texture Array used to control clipping based on the Clip Index parameter."), _ClipMaskArray); + materialEditor.ShaderProperty(_UseClipsForDissolve, new GUIContent("Use For Dissolve"), 2); + materialEditor.ShaderProperty(_ClipIndex, new GUIContent("Clip Index", "The index to use for referencing the clipping mask in the array. Can be 0 - 15, for a total of 16 unique masks."), 2); materialEditor.ShaderProperty(_UVSetClipMap, new GUIContent("UV Set", "The UV set to use for the Clip Map"), 2); - materialEditor.ShaderProperty(_ClipAgainstVertexColorGreaterZeroFive, new GUIContent("Clip Mask > 0.5 Opacity", "Uses the Clip Map RGBA channels as a multiplier for clipping.")); - _ClipAgainstVertexColorGreaterZeroFive.vectorValue = ClampVec4(_ClipAgainstVertexColorGreaterZeroFive.vectorValue); - materialEditor.ShaderProperty(_ClipAgainstVertexColorLessZeroFive, new GUIContent("Clip Mask Color < 0.5 Opacity", "Uses the Clip Map RGBA channels as a multiplier for clipping.")); - _ClipAgainstVertexColorLessZeroFive.vectorValue = ClampVec4(_ClipAgainstVertexColorLessZeroFive.vectorValue); + + int materialClipIndex = material.GetInt("_ClipIndex"); + switch (materialClipIndex) + { + case 0 : DrawVectorSliders(material, "_ClipSlider00", _ClipSlider00); break; + case 1 : DrawVectorSliders(material, "_ClipSlider01", _ClipSlider01); break; + case 2 : DrawVectorSliders(material, "_ClipSlider02", _ClipSlider02); break; + case 3 : DrawVectorSliders(material, "_ClipSlider03", _ClipSlider03); break; + case 4 : DrawVectorSliders(material, "_ClipSlider04", _ClipSlider04); break; + case 5 : DrawVectorSliders(material, "_ClipSlider05", _ClipSlider05); break; + case 6 : DrawVectorSliders(material, "_ClipSlider06", _ClipSlider06); break; + case 7 : DrawVectorSliders(material, "_ClipSlider07", _ClipSlider07); break; + case 8 : DrawVectorSliders(material, "_ClipSlider08", _ClipSlider08); break; + case 9 : DrawVectorSliders(material, "_ClipSlider09", _ClipSlider09); break; + case 10: DrawVectorSliders(material, "_ClipSlider10", _ClipSlider10); break; + case 11: DrawVectorSliders(material, "_ClipSlider11", _ClipSlider11); break; + case 12: DrawVectorSliders(material, "_ClipSlider12", _ClipSlider12); break; + case 13: DrawVectorSliders(material, "_ClipSlider13", _ClipSlider13); break; + case 14: DrawVectorSliders(material, "_ClipSlider14", _ClipSlider14); break; + case 15: DrawVectorSliders(material, "_ClipSlider15", _ClipSlider15); break; + } } + XSStyles.SeparatorThin(); + materialEditor.ShaderProperty(_VertexColorAlbedo, new GUIContent("Vertex Color Albedo", "Multiplies the vertex color of the mesh by the Albedo texture to derive the final Albedo color.")); materialEditor.ShaderProperty(_WireColor, new GUIContent("Wire Color On UV2", "This will only work with a specific second uv channel setup.")); materialEditor.ShaderProperty(_WireWidth, new GUIContent("Wire Width", "Controls the above wire width.")); + + XSStyles.SeparatorThin(); materialEditor.ShaderProperty(_Stencil, _Stencil.displayName); materialEditor.ShaderProperty(_StencilComp, _StencilComp.displayName); materialEditor.ShaderProperty(_StencilOp, _StencilOp.displayName); + XSStyles.SeparatorThin(); materialEditor.RenderQueueField(); } } @@ -663,6 +703,17 @@ private void DrawPatreonSettings(MaterialEditor materialEditor) // } + private void DrawVectorSliders(Material material, string vectorPropName, MaterialProperty property) + { + EditorGUI.BeginChangeCheck(); + Vector4 prop = property.vectorValue; + prop.x = EditorGUILayout.Slider(new GUIContent("Clip R", "Clip on mask channel R"), prop.x, 0, 1); + prop.y = EditorGUILayout.Slider(new GUIContent("Clip G", "Clip on mask channel G"), prop.y, 0, 1); + prop.z = EditorGUILayout.Slider(new GUIContent("Clip B", "Clip on mask channel B"), prop.z, 0, 1); + prop.w = EditorGUILayout.Slider(new GUIContent("Clip A", "Clip on mask channel A"), prop.w, 0, 1); + property.vectorValue = prop; + } + private Vector4 ClampVec4(Vector4 vec) { Vector4 value = vec; diff --git a/Main/CGIncludes/XSDefines.cginc b/Main/CGIncludes/XSDefines.cginc index a4c0188..f6478e8 100644 --- a/Main/CGIncludes/XSDefines.cginc +++ b/Main/CGIncludes/XSDefines.cginc @@ -1,6 +1,7 @@ #include "UnityPBSLighting.cginc" #include "AutoLight.cginc" #include "UnityCG.cginc" +//!RDPSDefines struct VertexInput { @@ -155,6 +156,7 @@ struct VertexLightInformation { float Attenuation[4]; }; +UNITY_DECLARE_TEX2DARRAY(_ClipMaskArray); UNITY_DECLARE_TEX2D(_MainTex); half4 _MainTex_ST; UNITY_DECLARE_TEX2D_NOSAMPLER(_ClipMap); half4 _ClipMap_ST; UNITY_DECLARE_TEX2D_NOSAMPLER(_DissolveTexture); half4 _DissolveTexture_ST; @@ -206,7 +208,12 @@ half _RimRange, _RimThreshold, _RimIntensity, _RimSharpness, _RimAlbedoTint, _Ri half _ShadowRimRange, _ShadowRimThreshold, _ShadowRimSharpness, _ShadowSharpness, _ShadowRimAlbedoTint; half _SSDistortion, _SSPower, _SSScale; half _OutlineWidth; +half4 _ClipSlider00,_ClipSlider01,_ClipSlider02,_ClipSlider03, + _ClipSlider04,_ClipSlider05,_ClipSlider06,_ClipSlider07, + _ClipSlider08,_ClipSlider09,_ClipSlider10,_ClipSlider11, + _ClipSlider12,_ClipSlider13,_ClipSlider14,_ClipSlider15; +int _ClipIndex; int _HalftoneType; int _FadeDither; int _BlendMode; diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index 9f28277..565d644 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -14,7 +14,7 @@ float4 frag ( #ifdef UNITY_PASS_SHADOWCASTER XSLighting o = (XSLighting)0; //Populate Lighting Struct, but only with important shadowcaster stuff! o.albedo = UNITY_SAMPLE_TEX2D(_MainTex, t.albedoUV) * _Color * lerp(1, float4(i.color.rgb, 1), _VertexColorAlbedo); - o.clipMap = UNITY_SAMPLE_TEX2D_SAMPLER(_ClipMap, _MainTex, t.clipMapUV); + o.clipMap = UNITY_SAMPLE_TEX2DARRAY(_ClipMaskArray, float3(t.clipMapUV, _ClipIndex)); o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV); o.worldPos = i.worldPos; @@ -29,13 +29,11 @@ float4 frag ( #else UNITY_LIGHT_ATTENUATION(attenuation, i, i.worldPos.xyz); - // fix for rare bug where light atten is 0 when there is no directional light in the scene - #ifdef UNITY_PASS_FORWARDBASE - if(all(_LightColor0.rgb == 0.0)) - { - attenuation = 1.0; - } - #endif + // fix for rare bug where light atten is 0 when there is no directional light in the scene + #ifdef UNITY_PASS_FORWARDBASE + if(all(_LightColor0.rgb == 0.0)) + attenuation = 1.0; + #endif #if defined(DIRECTIONAL) half sharp = _ShadowSharpness * 0.5; @@ -65,7 +63,7 @@ float4 frag ( o.emissionMap = UNITY_SAMPLE_TEX2D_SAMPLER(_EmissionMap, _MainTex, t.emissionMapUV) * _EmissionColor; o.rampMask = UNITY_SAMPLE_TEX2D_SAMPLER(_RampSelectionMask, _MainTex, i.uv); // This texture doesn't need to ever be on a second uv channel, and doesn't need tiling, convince me otherwise. o.hsvMask = UNITY_SAMPLE_TEX2D_SAMPLER(_HSVMask, _MainTex, t.albedoUV); - o.clipMap = UNITY_SAMPLE_TEX2D_SAMPLER(_ClipMap, _MainTex, t.clipMapUV); + o.clipMap = UNITY_SAMPLE_TEX2DARRAY(_ClipMaskArray, float3(t.clipMapUV, _ClipIndex)); o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV); o.diffuseColor = o.albedo.rgb; //Store this to separate the texture color and diffuse color for later. @@ -84,6 +82,7 @@ float4 frag ( calcAlpha(o); calcDissolve(o, col); UNITY_APPLY_FOG(i.fogCoord, col); + // return lerp(float4(col.rgb, 1), float4(o.clipMap.rgb, 1), 0.9999); return float4(col.rgb, o.alpha); #endif } \ No newline at end of file diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 011fe0f..7b5a547 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -266,11 +266,43 @@ float AlphaAdjust(float alphaToAdj, float3 vColor) return alphaToAdj; } +float AdjustAlphaUsingTextureArray(XSLighting i, float alphaToAdj) +{ + half4 compVal = 0; + switch (_ClipIndex) + { + case 0 : compVal = _ClipSlider00; break; + case 1 : compVal = _ClipSlider01; break; + case 2 : compVal = _ClipSlider02; break; + case 3 : compVal = _ClipSlider03; break; + case 4 : compVal = _ClipSlider04; break; + case 5 : compVal = _ClipSlider05; break; + case 6 : compVal = _ClipSlider06; break; + case 7 : compVal = _ClipSlider07; break; + case 8 : compVal = _ClipSlider08; break; + case 9 : compVal = _ClipSlider09; break; + case 10: compVal = _ClipSlider10; break; + case 11: compVal = _ClipSlider11; break; + case 12: compVal = _ClipSlider12; break; + case 13: compVal = _ClipSlider13; break; + case 14: compVal = _ClipSlider14; break; + case 15: compVal = _ClipSlider15; break; + } + + //I fuckin hate this lol + alphaToAdj *= lerp(0, 1, lerp(1, compVal.r, step(0.01, i.clipMap.r))); + alphaToAdj *= lerp(0, 1, lerp(1, compVal.g, step(0.01, i.clipMap.g))); + alphaToAdj *= lerp(0, 1, lerp(1, compVal.b, step(0.01, i.clipMap.b))); + alphaToAdj *= lerp(0, 1, lerp(1, compVal.a, step(0.01, i.clipMap.a))); + + return alphaToAdj; +} + void calcDissolve(inout XSLighting i, inout float4 col) { #ifdef _ALPHATEST_ON half dissolveAmt = Remap_Float(i.dissolveMask.x, float2(0,1), float2(0.1, 0.9)); - half dissolveProgress = saturate(_DissolveProgress + lerp(0, 1-AlphaAdjust(1, i.clipMap.rgb), _UseClipsForDissolve)); + half dissolveProgress = saturate(_DissolveProgress + lerp(0, 1-AdjustAlphaUsingTextureArray(i, 1), _UseClipsForDissolve)); half dissolve = 0; if (_DissolveCoordinates == 0) { @@ -320,7 +352,7 @@ void calcAlpha(inout XSLighting i) #endif #ifdef _ALPHATEST_ON - float modifiedAlpha = lerp(AlphaAdjust(i.albedo.a, i.clipMap.rgb), i.albedo.a, _UseClipsForDissolve); + float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); if(_BlendMode >= 3) { half dither = calcDither(i.screenUV.xy); diff --git a/Main/CGIncludes/XSVert.cginc b/Main/CGIncludes/XSVert.cginc index e6b03bb..8289f2d 100644 --- a/Main/CGIncludes/XSVert.cginc +++ b/Main/CGIncludes/XSVert.cginc @@ -1,7 +1,8 @@ +//!RDPSFunctions + VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; - #if !defined(Geometry) UNITY_SETUP_INSTANCE_ID(v); UNITY_INITIALIZE_OUTPUT(VertexOutput, o); @@ -12,6 +13,8 @@ VertexOutput vert (VertexInput v) UNITY_TRANSFER_INSTANCE_ID(v, o); #endif + //!RDPSVertInject + float3 wnormal = UnityObjectToWorldNormal(v.normal); float3 tangent = UnityObjectToWorldDir(v.tangent.xyz); half tangentSign = v.tangent.w * unity_WorldTransformParams.w; diff --git a/Main/Shaders/XSToon2.0 Outlined.shader b/Main/Shaders/XSToon2.0 Outlined.shader index 853af2e..91a9ef7 100644 --- a/Main/Shaders/XSToon2.0 Outlined.shader +++ b/Main/Shaders/XSToon2.0 Outlined.shader @@ -135,6 +135,28 @@ [HideInInspector] _DstBlend ("__dst", int) = 0 [HideInInspector] _ZWrite ("__zw", int) = 1 [HideInInspector] _AlphaToMask("__am", int) = 0 + + //A bit of a hack, but, a pretty okay hack? + _ClipMaskArray("Clip Mask Array", 2DArray) = "black" {} + [IntRange]_ClipIndex("Clip Index", Range(0,15)) = 0 + _ClipSlider00("", Vector) = (1,1,1,1) + _ClipSlider01("", Vector) = (1,1,1,1) + _ClipSlider02("", Vector) = (1,1,1,1) + _ClipSlider03("", Vector) = (1,1,1,1) + _ClipSlider04("", Vector) = (1,1,1,1) + _ClipSlider05("", Vector) = (1,1,1,1) + _ClipSlider06("", Vector) = (1,1,1,1) + _ClipSlider07("", Vector) = (1,1,1,1) + _ClipSlider08("", Vector) = (1,1,1,1) + _ClipSlider09("", Vector) = (1,1,1,1) + _ClipSlider10("", Vector) = (1,1,1,1) + _ClipSlider11("", Vector) = (1,1,1,1) + _ClipSlider12("", Vector) = (1,1,1,1) + _ClipSlider13("", Vector) = (1,1,1,1) + _ClipSlider14("", Vector) = (1,1,1,1) + _ClipSlider15("", Vector) = (1,1,1,1) + + //!RDPSProps } SubShader diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon2.0.shader index 69754b6..c1f9653 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon2.0.shader @@ -135,6 +135,28 @@ [HideInInspector] _DstBlend ("__dst", int) = 0 [HideInInspector] _ZWrite ("__zw", int) = 1 [HideInInspector] _AlphaToMask("__am", int) = 0 + + //A bit of a hack, but, a pretty okay hack? + _ClipMaskArray("Clip Mask Array", 2DArray) = "black" {} + [IntRange]_ClipIndex("Clip Index", Range(0,15)) = 0 + _ClipSlider00("", Vector) = (1,1,1,1) + _ClipSlider01("", Vector) = (1,1,1,1) + _ClipSlider02("", Vector) = (1,1,1,1) + _ClipSlider03("", Vector) = (1,1,1,1) + _ClipSlider04("", Vector) = (1,1,1,1) + _ClipSlider05("", Vector) = (1,1,1,1) + _ClipSlider06("", Vector) = (1,1,1,1) + _ClipSlider07("", Vector) = (1,1,1,1) + _ClipSlider08("", Vector) = (1,1,1,1) + _ClipSlider09("", Vector) = (1,1,1,1) + _ClipSlider10("", Vector) = (1,1,1,1) + _ClipSlider11("", Vector) = (1,1,1,1) + _ClipSlider12("", Vector) = (1,1,1,1) + _ClipSlider13("", Vector) = (1,1,1,1) + _ClipSlider14("", Vector) = (1,1,1,1) + _ClipSlider15("", Vector) = (1,1,1,1) + + //!RDPSProps } SubShader From 921907f0ded40d113e8d91736b6cb92978059757 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 28 Apr 2021 17:30:22 -0400 Subject: [PATCH 03/30] more injector stuff --- Editor/XSStyles.cs | 4 ++-- Main/Shaders/XSToon2.0.shader | 3 +++ .../{XSToon2.0 Outlined.shader => XSToon2.0_Outlined.shader} | 3 +++ ....0 Outlined.shader.meta => XSToon2.0_Outlined.shader.meta} | 0 4 files changed, 8 insertions(+), 2 deletions(-) rename Main/Shaders/{XSToon2.0 Outlined.shader => XSToon2.0_Outlined.shader} (99%) rename Main/Shaders/{XSToon2.0 Outlined.shader.meta => XSToon2.0_Outlined.shader.meta} (100%) diff --git a/Editor/XSStyles.cs b/Editor/XSStyles.cs index f7d7b75..289202f 100644 --- a/Editor/XSStyles.cs +++ b/Editor/XSStyles.cs @@ -7,7 +7,7 @@ namespace XSToon [InitializeOnLoad] public class XSStyles : MonoBehaviour { - public static string ver = "2.5"; + public static string ver = "2.6"; //Help URLs public static string mainURL = "https://docs.google.com/document/d/1xJ4PID_nwqVm_UCsO2c2gEdiEoWoCGeM_GDK_L8-aZE/edit#bookmark=id.xh0nk8x7ws1g"; @@ -111,7 +111,7 @@ static public void CallTexArrayManager() Renderer rend = Selection.activeGameObject.GetComponent(); if (rend != null) XSClipMapEditor.Rend = rend; - + XSClipMapEditor.Init(); } GUILayout.FlexibleSpace(); diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon2.0.shader index c1f9653..16df1ad 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon2.0.shader @@ -182,6 +182,7 @@ Blend [_SrcBlend] [_DstBlend] ZWrite [_ZWrite] CGPROGRAM + //#!RDPSTypeDefine #pragma target 3.0 #pragma vertex vert #pragma fragment frag @@ -215,6 +216,7 @@ ZTest LEqual Fog { Color (0,0,0,0) } CGPROGRAM + //#!RDPSTypeDefine #pragma target 3.0 #pragma vertex vert #pragma fragment frag @@ -242,6 +244,7 @@ Tags{ "LightMode" = "ShadowCaster" } ZWrite On ZTest LEqual CGPROGRAM + //#!RDPSTypeDefine #pragma target 3.0 #pragma vertex vert #pragma fragment frag diff --git a/Main/Shaders/XSToon2.0 Outlined.shader b/Main/Shaders/XSToon2.0_Outlined.shader similarity index 99% rename from Main/Shaders/XSToon2.0 Outlined.shader rename to Main/Shaders/XSToon2.0_Outlined.shader index 91a9ef7..a158f56 100644 --- a/Main/Shaders/XSToon2.0 Outlined.shader +++ b/Main/Shaders/XSToon2.0_Outlined.shader @@ -183,6 +183,7 @@ ZWrite [_ZWrite] CGPROGRAM #define Geometry + //#!RDPSTypeDefine #pragma target 4.0 #pragma vertex vert #pragma geometry geom @@ -219,6 +220,7 @@ Fog { Color (0,0,0,0) } CGPROGRAM #define Geometry + //#!RDPSTypeDefine #pragma target 4.0 #pragma vertex vert #pragma geometry geom @@ -249,6 +251,7 @@ ZWrite On ZTest LEqual CGPROGRAM #define Geometry + //#!RDPSTypeDefine #pragma target 4.0 #pragma vertex vert #pragma geometry geom diff --git a/Main/Shaders/XSToon2.0 Outlined.shader.meta b/Main/Shaders/XSToon2.0_Outlined.shader.meta similarity index 100% rename from Main/Shaders/XSToon2.0 Outlined.shader.meta rename to Main/Shaders/XSToon2.0_Outlined.shader.meta From c0b5a1a790e23701e9e4355d9af75b057ce9f889 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 28 Apr 2021 17:39:12 -0400 Subject: [PATCH 04/30] Update XSDefines.cginc --- Main/CGIncludes/XSDefines.cginc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Main/CGIncludes/XSDefines.cginc b/Main/CGIncludes/XSDefines.cginc index f6478e8..8c56803 100644 --- a/Main/CGIncludes/XSDefines.cginc +++ b/Main/CGIncludes/XSDefines.cginc @@ -1,7 +1,6 @@ #include "UnityPBSLighting.cginc" #include "AutoLight.cginc" #include "UnityCG.cginc" -//!RDPSDefines struct VertexInput { @@ -228,6 +227,8 @@ int _UVSetAlbedo, _UVSetNormal, _UVSetDetNormal, _UVSetEmission, _UVSetClipMap, _UVSetDissolve; int _NormalMapMode, _OutlineUVSelect; +//!RDPSDefines + //Defines for helper functions #define grayscaleVec float3(0.2125, 0.7154, 0.0721) -#define WorldNormalVector(normal0, normal) half3(dot(normal0,normal), dot(normal0, normal), dot(normal0,normal)) \ No newline at end of file +#define WorldNormalVector(normal0, normal) half3(dot(normal0,normal), dot(normal0, normal), dot(normal0,normal)) From a59495905afb3d779f9176618146332adb1ddcb5 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 28 Apr 2021 17:48:49 -0400 Subject: [PATCH 05/30] add vertex id --- Main/CGIncludes/XSDefines.cginc | 1 + 1 file changed, 1 insertion(+) diff --git a/Main/CGIncludes/XSDefines.cginc b/Main/CGIncludes/XSDefines.cginc index 8c56803..6046390 100644 --- a/Main/CGIncludes/XSDefines.cginc +++ b/Main/CGIncludes/XSDefines.cginc @@ -11,6 +11,7 @@ struct VertexInput float3 normal : NORMAL; float4 tangent : TANGENT; float4 color : COLOR; + uint vertexId : SV_VertexID; UNITY_VERTEX_INPUT_INSTANCE_ID }; From 84d410d039f73d60df84b50106977897dffa9bd4 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 28 Apr 2021 20:47:42 -0400 Subject: [PATCH 06/30] Add injection flags to inspector --- Editor/XSToonInspector.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 2776066..39063e1 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -161,6 +161,8 @@ public class XSToonInspector : ShaderGUI private MaterialProperty _EyeOffsetLimit = null; //-- + //!RDPSPropsInjection + private static bool showMainSettings = true; private static bool showNormalMapSettings = false; private static bool showShadows = true; @@ -186,6 +188,7 @@ public class XSToonInspector : ShaderGUI private bool isDithered = false; private bool isRefractive = false; + public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { Material material = materialEditor.target as Material; @@ -233,12 +236,16 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro DrawTransmissionSettings(materialEditor); DrawAdvancedSettings(materialEditor, material); DrawPatreonSettings(materialEditor); - XSStyles.DoFooter(); + //!RDPSFunctionCallInject + + XSStyles.DoFooter(); } private void DoBlendModeSettings(Material material) { + //!RDPSBlendModeInjection + int currentBlendMode = material.GetInt("_BlendMode"); if (BlendMode != currentBlendMode) { @@ -703,6 +710,8 @@ private void DrawPatreonSettings(MaterialEditor materialEditor) // } + //!RDPSFunctionInject + private void DrawVectorSliders(Material material, string vectorPropName, MaterialProperty property) { EditorGUI.BeginChangeCheck(); From 7379a88b00a1df336a8269a789a1e86b50e782c7 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 28 Apr 2021 21:46:50 -0400 Subject: [PATCH 07/30] whitespace cleanup --- Editor/XSToonInspector.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 39063e1..888077e 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -245,7 +245,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro private void DoBlendModeSettings(Material material) { //!RDPSBlendModeInjection - + int currentBlendMode = material.GetInt("_BlendMode"); if (BlendMode != currentBlendMode) { @@ -733,4 +733,4 @@ private Vector4 ClampVec4(Vector4 vec) return value; } } -} \ No newline at end of file +} From 595048f72d8f35075df9f660ade4c9cc5f40d8c7 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 28 Apr 2021 23:17:06 -0400 Subject: [PATCH 08/30] move a line because ordering matters --- Editor/XSToonInspector.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 888077e..498f4a1 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -244,9 +244,9 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro private void DoBlendModeSettings(Material material) { - //!RDPSBlendModeInjection - int currentBlendMode = material.GetInt("_BlendMode"); + //!RDPSBlendModeInjection + if (BlendMode != currentBlendMode) { BlendMode = currentBlendMode; From da9aabba84cc9689f39eb47b1065c69a5b934cf5 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Fri, 30 Apr 2021 23:00:11 -0400 Subject: [PATCH 09/30] Bugfixes and Clip Map Changes - Inspector no longer opens the same tab on all materials - Clip map can now store up to 8 toggles per texture - Fix an issue with mipmapping on clip maps --- Editor/XSClipMapEditor.cs | 7 +- Editor/XSStyles.cs | 10 ++ Editor/XSToonInspector.cs | 184 ++++++++++++------------ Main/CGIncludes/XSFrag.cginc | 4 +- Main/CGIncludes/XSHelperFunctions.cginc | 52 ++++--- Main/Shaders/XSToon2.0.shader | 6 +- Main/Shaders/XSToon2.0_Outlined.shader | 6 +- 7 files changed, 150 insertions(+), 119 deletions(-) diff --git a/Editor/XSClipMapEditor.cs b/Editor/XSClipMapEditor.cs index 4221bb7..3d2890b 100644 --- a/Editor/XSClipMapEditor.cs +++ b/Editor/XSClipMapEditor.cs @@ -216,7 +216,12 @@ private void CopyListIntoArray(TextureList List, TextureSettings Settings) output.Apply(false); - string path = EditorUtility.SaveFilePanelInProject("Save Array", $"{Rend.name}_texarray.asset", "asset", "Please enter a file name to save the texture array to"); + string path = ""; + if(Rend != null) + path = EditorUtility.SaveFilePanelInProject("Save Array", $"{Rend.name}_texarray.asset", "asset", "Please enter a file name to save the texture array to"); + else + path = EditorUtility.SaveFilePanelInProject("Save Array", "SwapMask_texarray.asset", "asset", "Please enter a file name to save the texture array to"); + if (path.Length != 0) { AssetDatabase.CreateAsset(output, path); diff --git a/Editor/XSStyles.cs b/Editor/XSStyles.cs index 289202f..92337b6 100644 --- a/Editor/XSStyles.cs +++ b/Editor/XSStyles.cs @@ -39,6 +39,16 @@ public static void DoHeader(GUIContent HeaderText) }); } + public static void DoHeaderLeft(string text) + { + GUILayout.Label(text, new GUIStyle(EditorStyles.boldLabel) + { + alignment = TextAnchor.MiddleLeft, + wordWrap = true, + fontSize = 12 + }); + } + public static void doLabel(string text) { GUILayout.Label(text, new GUIStyle(EditorStyles.label) diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 498f4a1..03a722e 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -8,8 +8,27 @@ namespace XSToon { + public class FoldoutToggles + { + public bool ShowMain = true; + public bool ShowNormal = false; + public bool ShowShadows = true; + public bool ShowSpecular = false; + public bool ShowReflection = false; + public bool ShowRimlight = false; + public bool ShowHalftones = false; + public bool ShowSubsurface = false; + public bool ShowOutlines = false; + public bool ShowEmission = false; + public bool ShowAdvanced = false; + public bool ShowEyeTracking = false; + public bool ShowRefraction = false; + public bool ShowDissolve = false; + } + public class XSToonInspector : ShaderGUI { + private static Dictionary Foldouts = new Dictionary(); BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | @@ -163,23 +182,7 @@ public class XSToonInspector : ShaderGUI //!RDPSPropsInjection - private static bool showMainSettings = true; - private static bool showNormalMapSettings = false; - private static bool showShadows = true; - private static bool showSpecular = false; - private static bool showReflection = false; - private static bool showRimlight = false; - private static bool showHalftones = false; - private static bool showSubsurface = false; - private static bool showOutlines = false; - private static bool showEmission = false; - private static bool showAdvanced = false; - private static bool showEyeTracking = false; - private static bool showRefractionSettings = false; - private static bool showDissolveSettings = false; - private static int BlendMode; - private bool isPatreonShader = false; private bool isEyeTracking = false; private bool isOutlined = false; @@ -201,6 +204,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro isPatreonShader = shader.name.Contains("Patreon"); isEyeTracking = shader.name.Contains("EyeTracking"); + SetupFoldoutDictionary(material); //Find all material properties listed in the script using reflection, and set them using a loop only if they're of type MaterialProperty. //This makes things a lot nicer to maintain and cleaner to look at. @@ -222,26 +226,35 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro materialEditor.ShaderProperty(_UseRefraction, new GUIContent("Refraction", "Should this material be refractive? (Warning, this can be expensive!)")); DoBlendModeSettings(material); - DrawMainSettings(materialEditor); - DrawDissolveSettings(materialEditor); + DrawMainSettings(materialEditor, material); + DrawDissolveSettings(materialEditor, material); DrawShadowSettings(materialEditor, material); - DrawOutlineSettings(materialEditor); - DrawNormalSettings(materialEditor); - DrawSpecularSettings(materialEditor); + DrawOutlineSettings(materialEditor, material); + DrawNormalSettings(materialEditor, material); + DrawSpecularSettings(materialEditor, material); DrawReflectionsSettings(materialEditor, material); - DrawRefractionSettings(materialEditor); - DrawEmissionSettings(materialEditor); - DrawRimlightSettings(materialEditor); - DrawHalfToneSettings(materialEditor); - DrawTransmissionSettings(materialEditor); + DrawRefractionSettings(materialEditor, material); + DrawEmissionSettings(materialEditor, material); + DrawRimlightSettings(materialEditor, material); + DrawHalfToneSettings(materialEditor, material); + DrawTransmissionSettings(materialEditor, material); DrawAdvancedSettings(materialEditor, material); - DrawPatreonSettings(materialEditor); + DrawPatreonSettings(materialEditor, material); //!RDPSFunctionCallInject XSStyles.DoFooter(); } + private void SetupFoldoutDictionary(Material material) + { + if (Foldouts.ContainsKey(material)) + return; + + FoldoutToggles toggles = new FoldoutToggles(); + Foldouts.Add(material, toggles); + } + private void DoBlendModeSettings(Material material) { int currentBlendMode = material.GetInt("_BlendMode"); @@ -321,10 +334,10 @@ private void SetBlend(Material material, int src, int dst, int renderQueue, int material.renderQueue = isRefractive ? (int)UnityEngine.Rendering.RenderQueue.Overlay - 1 : renderQueue; } - private void DrawMainSettings(MaterialEditor materialEditor) + private void DrawMainSettings(MaterialEditor materialEditor, Material material) { - showMainSettings = XSStyles.ShurikenFoldout("Main Settings", showMainSettings); - if (showMainSettings) + Foldouts[material].ShowMain = XSStyles.ShurikenFoldout("Main Settings", Foldouts[material].ShowMain); + if (Foldouts[material].ShowMain) { materialEditor.TexturePropertySingleLine(new GUIContent("Main Texture", "The main Albedo texture."), _MainTex, _Color); if (isCutout) @@ -348,12 +361,12 @@ private void DrawMainSettings(MaterialEditor materialEditor) } } - private void DrawDissolveSettings(MaterialEditor materialEditor) + private void DrawDissolveSettings(MaterialEditor materialEditor, Material material) { if (isCutout || isDithered) { - showDissolveSettings = XSStyles.ShurikenFoldout("Dissolve", showDissolveSettings); - if (showDissolveSettings) + Foldouts[material].ShowDissolve = XSStyles.ShurikenFoldout("Dissolve", Foldouts[material].ShowDissolve); + if (Foldouts[material].ShowDissolve) { materialEditor.ShaderProperty(_DissolveCoordinates, new GUIContent("Dissolve Coordinates", "Should Dissolve happen in world space, texture space, or vertically?")); materialEditor.TexturePropertySingleLine(new GUIContent("Dissolve Texture", "Noise texture used to control up dissolve pattern"), _DissolveTexture, _DissolveColor); @@ -368,8 +381,8 @@ private void DrawDissolveSettings(MaterialEditor materialEditor) private void DrawShadowSettings(MaterialEditor materialEditor, Material material) { - showShadows = XSStyles.ShurikenFoldout("Shadows", showShadows); - if (showShadows) + Foldouts[material].ShowShadows = XSStyles.ShurikenFoldout("Shadows", Foldouts[material].ShowShadows); + if (Foldouts[material].ShowShadows) { materialEditor.TexturePropertySingleLine(new GUIContent("Ramp Selection Mask", "A black to white mask that determins how far up on the multi ramp to sample. 0 for bottom, 1 for top, 0.5 for middle, 0.25, and 0.75 for mid bottom and mid top respectively."), _RampSelectionMask); @@ -410,12 +423,12 @@ private void DrawShadowSettings(MaterialEditor materialEditor, Material material } } - private void DrawOutlineSettings(MaterialEditor materialEditor) + private void DrawOutlineSettings(MaterialEditor materialEditor, Material material) { if (isOutlined) { - showOutlines = XSStyles.ShurikenFoldout("Outlines", showOutlines); - if (showOutlines) + Foldouts[material].ShowOutlines = XSStyles.ShurikenFoldout("Outlines", Foldouts[material].ShowOutlines); + if (Foldouts[material].ShowOutlines) { materialEditor.ShaderProperty(_OutlineNormalMode, new GUIContent("Outline Normal Mode", "How to calcuate the outline expand direction. Using mesh normals may result in split edges.")); @@ -431,10 +444,10 @@ private void DrawOutlineSettings(MaterialEditor materialEditor) } } - private void DrawNormalSettings(MaterialEditor materialEditor) + private void DrawNormalSettings(MaterialEditor materialEditor, Material material) { - showNormalMapSettings = XSStyles.ShurikenFoldout("Normal Maps", showNormalMapSettings); - if (showNormalMapSettings) + Foldouts[material].ShowNormal = XSStyles.ShurikenFoldout("Normal Maps", Foldouts[material].ShowNormal); + if (Foldouts[material].ShowNormal) { materialEditor.ShaderProperty(_NormalMapMode, new GUIContent("Normal Map Source", "How to alter the normals of the mesh, using which source?")); if (_NormalMapMode.floatValue == 0) @@ -458,10 +471,10 @@ private void DrawNormalSettings(MaterialEditor materialEditor) } } - private void DrawSpecularSettings(MaterialEditor materialEditor) + private void DrawSpecularSettings(MaterialEditor materialEditor, Material material) { - showSpecular = XSStyles.ShurikenFoldout("Specular", showSpecular); - if (showSpecular) + Foldouts[material].ShowSpecular = XSStyles.ShurikenFoldout("Specular", Foldouts[material].ShowSpecular); + if (Foldouts[material].ShowSpecular) { materialEditor.TexturePropertySingleLine(new GUIContent("Specular Map(R,G,B)", "Specular Map. Red channel controls Intensity, Green controls how much specular is tinted by Albedo, and Blue controls Smoothness (Only for Blinn-Phong, and GGX)."), _SpecularMap); materialEditor.TextureScaleOffsetProperty(_SpecularMap); @@ -476,8 +489,8 @@ private void DrawSpecularSettings(MaterialEditor materialEditor) private void DrawReflectionsSettings(MaterialEditor materialEditor, Material material) { - showReflection = XSStyles.ShurikenFoldout("Reflections", showReflection); - if (showReflection) + Foldouts[material].ShowReflection = XSStyles.ShurikenFoldout("Reflections", Foldouts[material].ShowReflection); + if (Foldouts[material].ShowReflection) { materialEditor.ShaderProperty(_ReflectionMode, new GUIContent("Reflection Mode", "Reflection Mode.")); @@ -546,10 +559,10 @@ private void DrawReflectionsSettings(MaterialEditor materialEditor, Material mat } } - private void DrawEmissionSettings(MaterialEditor materialEditor) + private void DrawEmissionSettings(MaterialEditor materialEditor, Material material) { - showEmission = XSStyles.ShurikenFoldout("Emission", showEmission); - if (showEmission) + Foldouts[material].ShowEmission = XSStyles.ShurikenFoldout("Emission", Foldouts[material].ShowEmission); + if (Foldouts[material].ShowEmission) { materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map", "Emissive map. White to black, unless you want multiple colors."), _EmissionMap, _EmissionColor); materialEditor.TextureScaleOffsetProperty(_EmissionMap); @@ -563,10 +576,10 @@ private void DrawEmissionSettings(MaterialEditor materialEditor) } } - private void DrawRimlightSettings(MaterialEditor materialEditor) + private void DrawRimlightSettings(MaterialEditor materialEditor, Material material) { - showRimlight = XSStyles.ShurikenFoldout("Rimlight", showRimlight); - if (showRimlight) + Foldouts[material].ShowRimlight = XSStyles.ShurikenFoldout("Rimlight", Foldouts[material].ShowRimlight); + if (Foldouts[material].ShowRimlight) { materialEditor.ShaderProperty(_RimColor, new GUIContent("Rimlight Tint", "The Tint of the Rimlight.")); materialEditor.ShaderProperty(_RimAlbedoTint, new GUIContent("Rim Albedo Tint", "How much the Albedo texture should effect the rimlight color.")); @@ -579,10 +592,10 @@ private void DrawRimlightSettings(MaterialEditor materialEditor) } } - private void DrawHalfToneSettings(MaterialEditor materialEditor) + private void DrawHalfToneSettings(MaterialEditor materialEditor, Material material) { - showHalftones = XSStyles.ShurikenFoldout("Halftones", showHalftones); - if (showHalftones) + Foldouts[material].ShowHalftones = XSStyles.ShurikenFoldout("Halftones", Foldouts[material].ShowHalftones); + if (Foldouts[material].ShowHalftones) { materialEditor.ShaderProperty(_HalftoneType, new GUIContent("Halftone Style", "Controls where halftone and stippling effects are drawn.")); @@ -600,10 +613,10 @@ private void DrawHalfToneSettings(MaterialEditor materialEditor) } } - private void DrawTransmissionSettings(MaterialEditor materialEditor) + private void DrawTransmissionSettings(MaterialEditor materialEditor, Material material) { - showSubsurface = XSStyles.ShurikenFoldout("Transmission", showSubsurface); - if (showSubsurface) + Foldouts[material].ShowSubsurface = XSStyles.ShurikenFoldout("Transmission", Foldouts[material].ShowSubsurface); + if (Foldouts[material].ShowSubsurface) { materialEditor.TexturePropertySingleLine(new GUIContent("Thickness Map", "Thickness Map, used to mask areas where transmission can happen"), _ThicknessMap); materialEditor.TextureScaleOffsetProperty(_ThicknessMap); @@ -615,12 +628,12 @@ private void DrawTransmissionSettings(MaterialEditor materialEditor) } } - private void DrawRefractionSettings(MaterialEditor materialEditor) + private void DrawRefractionSettings(MaterialEditor materialEditor, Material material) { if (isRefractive) { - showRefractionSettings = XSStyles.ShurikenFoldout("Refraction", showRefractionSettings); - if (showRefractionSettings) + Foldouts[material].ShowRefraction = XSStyles.ShurikenFoldout("Refraction", Foldouts[material].ShowRefraction); + if (Foldouts[material].ShowRefraction) { materialEditor.ShaderProperty(_RefractionModel, new GUIContent("Refraction Model", "Refraction technique")); materialEditor.ShaderProperty(_IOR, new GUIContent("Index of Refraction", "The index of refraction of the material. Glass: 1.5, Crystal: 2.0, Ice: 1.309, Water: 1.325")); @@ -632,36 +645,29 @@ private void DrawAdvancedSettings(MaterialEditor materialEditor, Material materi { if (_AdvMode.floatValue == 1) { - showAdvanced = XSStyles.ShurikenFoldout("Advanced Settings", showAdvanced); - if (showAdvanced) + Foldouts[material].ShowAdvanced = XSStyles.ShurikenFoldout("Advanced Settings", Foldouts[material].ShowAdvanced); + if (Foldouts[material].ShowAdvanced) { if (isDithered || isCutout) { XSStyles.CallTexArrayManager(); - materialEditor.TexturePropertySingleLine(new GUIContent("Clip Map (RGBA | Tex2DArray)", "Texture Array used to control clipping based on the Clip Index parameter."), _ClipMaskArray); + materialEditor.TexturePropertySingleLine(new GUIContent("Clip Map (RGB | Tex2DArray)", "Texture Array used to control clipping based on the Clip Index parameter."), _ClipMaskArray); materialEditor.ShaderProperty(_UseClipsForDissolve, new GUIContent("Use For Dissolve"), 2); materialEditor.ShaderProperty(_ClipIndex, new GUIContent("Clip Index", "The index to use for referencing the clipping mask in the array. Can be 0 - 15, for a total of 16 unique masks."), 2); materialEditor.ShaderProperty(_UVSetClipMap, new GUIContent("UV Set", "The UV set to use for the Clip Map"), 2); + XSStyles.DoHeaderLeft("Clip Against"); int materialClipIndex = material.GetInt("_ClipIndex"); switch (materialClipIndex) { - case 0 : DrawVectorSliders(material, "_ClipSlider00", _ClipSlider00); break; - case 1 : DrawVectorSliders(material, "_ClipSlider01", _ClipSlider01); break; - case 2 : DrawVectorSliders(material, "_ClipSlider02", _ClipSlider02); break; - case 3 : DrawVectorSliders(material, "_ClipSlider03", _ClipSlider03); break; - case 4 : DrawVectorSliders(material, "_ClipSlider04", _ClipSlider04); break; - case 5 : DrawVectorSliders(material, "_ClipSlider05", _ClipSlider05); break; - case 6 : DrawVectorSliders(material, "_ClipSlider06", _ClipSlider06); break; - case 7 : DrawVectorSliders(material, "_ClipSlider07", _ClipSlider07); break; - case 8 : DrawVectorSliders(material, "_ClipSlider08", _ClipSlider08); break; - case 9 : DrawVectorSliders(material, "_ClipSlider09", _ClipSlider09); break; - case 10: DrawVectorSliders(material, "_ClipSlider10", _ClipSlider10); break; - case 11: DrawVectorSliders(material, "_ClipSlider11", _ClipSlider11); break; - case 12: DrawVectorSliders(material, "_ClipSlider12", _ClipSlider12); break; - case 13: DrawVectorSliders(material, "_ClipSlider13", _ClipSlider13); break; - case 14: DrawVectorSliders(material, "_ClipSlider14", _ClipSlider14); break; - case 15: DrawVectorSliders(material, "_ClipSlider15", _ClipSlider15); break; + case 0: DrawVectorSliders(material, _ClipSlider00, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider01, "Cyan", "Yellow", "Magenta", "Black"); break; + case 1: DrawVectorSliders(material, _ClipSlider02, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider03, "Cyan", "Yellow", "Magenta", "Black"); break; + case 2: DrawVectorSliders(material, _ClipSlider04, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider05, "Cyan", "Yellow", "Magenta", "Black"); break; + case 3: DrawVectorSliders(material, _ClipSlider06, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider07, "Cyan", "Yellow", "Magenta", "Black"); break; + case 4: DrawVectorSliders(material, _ClipSlider08, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider09, "Cyan", "Yellow", "Magenta", "Black"); break; + case 5: DrawVectorSliders(material, _ClipSlider10, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider11, "Cyan", "Yellow", "Magenta", "Black"); break; + case 6: DrawVectorSliders(material, _ClipSlider12, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider13, "Cyan", "Yellow", "Magenta", "Black"); break; + case 7: DrawVectorSliders(material, _ClipSlider14, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider15, "Cyan", "Yellow", "Magenta", "Black"); break; } } @@ -681,15 +687,15 @@ private void DrawAdvancedSettings(MaterialEditor materialEditor, Material materi } } - private void DrawPatreonSettings(MaterialEditor materialEditor) + private void DrawPatreonSettings(MaterialEditor materialEditor, Material material) { //Plugins for Patreon releases if (isPatreonShader) { if (isEyeTracking) { - showEyeTracking = XSStyles.ShurikenFoldout("Eye Tracking Settings", showEyeTracking); - if (showEyeTracking) + Foldouts[material].ShowEyeTracking = XSStyles.ShurikenFoldout("Eye Tracking Settings", Foldouts[material].ShowEyeTracking); + if (Foldouts[material].ShowEyeTracking) { materialEditor.ShaderProperty(_LeftRightPan, new GUIContent("Left Right Adj.", "Adjusts the eyes manually left or right.")); materialEditor.ShaderProperty(_UpDownPan, new GUIContent("Up Down Adj.", "Adjusts the eyes manually up or down.")); @@ -712,14 +718,16 @@ private void DrawPatreonSettings(MaterialEditor materialEditor) //!RDPSFunctionInject - private void DrawVectorSliders(Material material, string vectorPropName, MaterialProperty property) + private void DrawVectorSliders(Material material, MaterialProperty property, string nameR, string nameG, string nameB, string nameA) { EditorGUI.BeginChangeCheck(); Vector4 prop = property.vectorValue; - prop.x = EditorGUILayout.Slider(new GUIContent("Clip R", "Clip on mask channel R"), prop.x, 0, 1); - prop.y = EditorGUILayout.Slider(new GUIContent("Clip G", "Clip on mask channel G"), prop.y, 0, 1); - prop.z = EditorGUILayout.Slider(new GUIContent("Clip B", "Clip on mask channel B"), prop.z, 0, 1); - prop.w = EditorGUILayout.Slider(new GUIContent("Clip A", "Clip on mask channel A"), prop.w, 0, 1); + EditorGUI.indentLevel += 1; + prop.x = EditorGUILayout.Slider(new GUIContent(nameR, "Clip on mask channel R"), prop.x, 0, 1); + prop.y = EditorGUILayout.Slider(new GUIContent(nameG, "Clip on mask channel G"), prop.y, 0, 1); + prop.z = EditorGUILayout.Slider(new GUIContent(nameB, "Clip on mask channel B"), prop.z, 0, 1); + prop.w = EditorGUILayout.Slider(new GUIContent(nameA, "Clip on mask channel A"), prop.w, 0, 1); + EditorGUI.indentLevel -= 1; property.vectorValue = prop; } diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index 565d644..9e94b23 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -63,7 +63,7 @@ float4 frag ( o.emissionMap = UNITY_SAMPLE_TEX2D_SAMPLER(_EmissionMap, _MainTex, t.emissionMapUV) * _EmissionColor; o.rampMask = UNITY_SAMPLE_TEX2D_SAMPLER(_RampSelectionMask, _MainTex, i.uv); // This texture doesn't need to ever be on a second uv channel, and doesn't need tiling, convince me otherwise. o.hsvMask = UNITY_SAMPLE_TEX2D_SAMPLER(_HSVMask, _MainTex, t.albedoUV); - o.clipMap = UNITY_SAMPLE_TEX2DARRAY(_ClipMaskArray, float3(t.clipMapUV, _ClipIndex)); + o.clipMap = UNITY_SAMPLE_TEX2DARRAY_LOD(_ClipMaskArray, float3(t.clipMapUV, _ClipIndex), 0); o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV); o.diffuseColor = o.albedo.rgb; //Store this to separate the texture color and diffuse color for later. @@ -82,6 +82,8 @@ float4 frag ( calcAlpha(o); calcDissolve(o, col); UNITY_APPLY_FOG(i.fogCoord, col); + // float clipR = IsColorMatch(o.clipMap.rgb, float3(1,0,0)); + // return lerp(float4(col.rgb, 1), clipR, 0.9999); // return lerp(float4(col.rgb, 1), float4(o.clipMap.rgb, 1), 0.9999); return float4(col.rgb, o.alpha); #endif diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 7b5a547..a04ea5e 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -266,34 +266,40 @@ float AlphaAdjust(float alphaToAdj, float3 vColor) return alphaToAdj; } +bool IsColorMatch(float3 color1, float3 color2) +{ + float epsilon = 0.1; + float3 delta = abs(color1.rgb - color2.rgb); + return step((delta.r + delta.g + delta.b), epsilon); +} + float AdjustAlphaUsingTextureArray(XSLighting i, float alphaToAdj) { - half4 compVal = 0; - switch (_ClipIndex) + half4 compValRGBW = 0; // Red Green Blue White + half4 compValCYMB = 0; // Cyan Yellow Magenta Black + switch (_ClipIndex) // Each of these is a Vector / 4 masks, 2 per material, so 8 masks per material, 16 total. { - case 0 : compVal = _ClipSlider00; break; - case 1 : compVal = _ClipSlider01; break; - case 2 : compVal = _ClipSlider02; break; - case 3 : compVal = _ClipSlider03; break; - case 4 : compVal = _ClipSlider04; break; - case 5 : compVal = _ClipSlider05; break; - case 6 : compVal = _ClipSlider06; break; - case 7 : compVal = _ClipSlider07; break; - case 8 : compVal = _ClipSlider08; break; - case 9 : compVal = _ClipSlider09; break; - case 10: compVal = _ClipSlider10; break; - case 11: compVal = _ClipSlider11; break; - case 12: compVal = _ClipSlider12; break; - case 13: compVal = _ClipSlider13; break; - case 14: compVal = _ClipSlider14; break; - case 15: compVal = _ClipSlider15; break; + case 0 : compValRGBW = _ClipSlider00; compValCYMB = _ClipSlider01; break; + case 1 : compValRGBW = _ClipSlider02; compValCYMB = _ClipSlider03; break; + case 2 : compValRGBW = _ClipSlider04; compValCYMB = _ClipSlider05; break; + case 3 : compValRGBW = _ClipSlider06; compValCYMB = _ClipSlider07; break; + case 4 : compValRGBW = _ClipSlider08; compValCYMB = _ClipSlider09; break; + case 5 : compValRGBW = _ClipSlider10; compValCYMB = _ClipSlider11; break; + case 6 : compValRGBW = _ClipSlider12; compValCYMB = _ClipSlider13; break; + case 7 : compValRGBW = _ClipSlider14; compValCYMB = _ClipSlider15; break; } - //I fuckin hate this lol - alphaToAdj *= lerp(0, 1, lerp(1, compVal.r, step(0.01, i.clipMap.r))); - alphaToAdj *= lerp(0, 1, lerp(1, compVal.g, step(0.01, i.clipMap.g))); - alphaToAdj *= lerp(0, 1, lerp(1, compVal.b, step(0.01, i.clipMap.b))); - alphaToAdj *= lerp(0, 1, lerp(1, compVal.a, step(0.01, i.clipMap.a))); + //Compares to Red, Green, Blue, and White against the first slider set + alphaToAdj *= lerp(1, compValRGBW.r, IsColorMatch(i.clipMap.rgb, float3(1,0,0))); + alphaToAdj *= lerp(1, compValRGBW.g, IsColorMatch(i.clipMap.rgb, float3(0,1,0))); + alphaToAdj *= lerp(1, compValRGBW.b, IsColorMatch(i.clipMap.rgb, float3(0,0,1))); + alphaToAdj *= lerp(1, compValRGBW.w, IsColorMatch(i.clipMap.rgb, float3(1,1,1))); + + //Compares to Cyan, Yellow, Magenta, and Black against the second slider set + alphaToAdj *= lerp(1, compValCYMB.r, IsColorMatch(i.clipMap.rgb, float3(0,1,1))); + alphaToAdj *= lerp(1, compValCYMB.g, IsColorMatch(i.clipMap.rgb, float3(1,1,0))); + alphaToAdj *= lerp(1, compValCYMB.b, IsColorMatch(i.clipMap.rgb, float3(1,0,1))); + alphaToAdj *= lerp(1, compValCYMB.w, IsColorMatch(i.clipMap.rgb, float3(0,0,0))); return alphaToAdj; } diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon2.0.shader index 16df1ad..4601d77 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon2.0.shader @@ -183,7 +183,7 @@ ZWrite [_ZWrite] CGPROGRAM //#!RDPSTypeDefine - #pragma target 3.0 + #pragma target 5.0 #pragma vertex vert #pragma fragment frag #pragma shader_feature _ALPHABLEND_ON @@ -217,7 +217,7 @@ Fog { Color (0,0,0,0) } CGPROGRAM //#!RDPSTypeDefine - #pragma target 3.0 + #pragma target 5.0 #pragma vertex vert #pragma fragment frag #pragma shader_feature _ALPHABLEND_ON @@ -245,7 +245,7 @@ ZWrite On ZTest LEqual CGPROGRAM //#!RDPSTypeDefine - #pragma target 3.0 + #pragma target 5.0 #pragma vertex vert #pragma fragment frag #pragma shader_feature _ALPHABLEND_ON diff --git a/Main/Shaders/XSToon2.0_Outlined.shader b/Main/Shaders/XSToon2.0_Outlined.shader index a158f56..a35de33 100644 --- a/Main/Shaders/XSToon2.0_Outlined.shader +++ b/Main/Shaders/XSToon2.0_Outlined.shader @@ -184,7 +184,7 @@ CGPROGRAM #define Geometry //#!RDPSTypeDefine - #pragma target 4.0 + #pragma target 5.0 #pragma vertex vert #pragma geometry geom #pragma fragment frag @@ -221,7 +221,7 @@ CGPROGRAM #define Geometry //#!RDPSTypeDefine - #pragma target 4.0 + #pragma target 5.0 #pragma vertex vert #pragma geometry geom #pragma fragment frag @@ -252,7 +252,7 @@ CGPROGRAM #define Geometry //#!RDPSTypeDefine - #pragma target 4.0 + #pragma target 5.0 #pragma vertex vert #pragma geometry geom #pragma fragment frag From 3ed8c893df0ee87cc963d2821a45698ab1267e56 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Fri, 30 Apr 2021 23:37:41 -0400 Subject: [PATCH 10/30] Remove Tex Array Requirement and Fix Alpha To Coverage --- Editor/XSClipMapEditor.cs | 15 +++------------ Editor/XSStyles.cs | 12 ++++++------ Editor/XSToonInspector.cs | 18 ++++++++++-------- Main/CGIncludes/XSDefines.cginc | 4 +++- Main/CGIncludes/XSFrag.cginc | 4 ++-- Main/CGIncludes/XSHelperFunctions.cginc | 2 +- Main/Shaders/XSToon2.0.shader | 5 ++--- 7 files changed, 27 insertions(+), 33 deletions(-) diff --git a/Editor/XSClipMapEditor.cs b/Editor/XSClipMapEditor.cs index 3d2890b..527a428 100644 --- a/Editor/XSClipMapEditor.cs +++ b/Editor/XSClipMapEditor.cs @@ -20,7 +20,7 @@ static public void Init() private Vector2 ClipScrollPos; private int ClipMapCount = 1; - public Texture2D[] ClipMaps = new Texture2D[16]; + public Texture2D[] ClipMaps = new Texture2D[8]; public static Renderer Rend; @@ -39,6 +39,7 @@ static public void Init() public TextureWrapMode wrapModeV = TextureWrapMode.Repeat; public int anisoLevel = 1; + public bool AutoAssignToMaterials = false; public struct TextureSettings { @@ -72,17 +73,7 @@ public void OnGUI() if (GUILayout.Button("Create Array")) { CreateTextureArray(); - if (Rend != null) - { - for (int i = 0; i < Rend.sharedMaterials.Length; i++) - { - if (Rend.sharedMaterials[i].HasProperty("_ClipMaskArray")) - { - Debug.Log( - $"Material {Rend.sharedMaterials[i].name} is supported, auto assigning TexArray."); - } - } - } + } GUILayout.Space(8); } diff --git a/Editor/XSStyles.cs b/Editor/XSStyles.cs index 92337b6..6df35d7 100644 --- a/Editor/XSStyles.cs +++ b/Editor/XSStyles.cs @@ -189,18 +189,18 @@ public static void HelpBox(string message, MessageType type) //GUI Lines static public void Separator() { - GUILayout.Space(4); - GUILine(new Color(.3f, .3f, .3f), 1); - GUILine(new Color(.9f, .9f, .9f), 1); - GUILayout.Space(4); + GUILayout.Space(10); + GUILine(new Color(.1f, .1f, .1f), 1f); + GUILine(new Color(.3f, .3f, .3f), 2f); + GUILayout.Space(10); } static public void SeparatorThin() { - GUILayout.Space(2); + GUILayout.Space(6); GUILine(new Color(.1f, .1f, .1f), 1f); GUILine(new Color(.3f, .3f, .3f), 1f); - GUILayout.Space(2); + GUILayout.Space(6); } static public void SeparatorBig() diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 03a722e..c6b70ec 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -149,7 +149,7 @@ public class XSToonInspector : ShaderGUI private MaterialProperty _WireWidth = null; //Experimenting - private MaterialProperty _ClipMaskArray = null; + private MaterialProperty _ClipMask = null; private MaterialProperty _ClipIndex = null; private MaterialProperty _ClipSlider00 = null; private MaterialProperty _ClipSlider01 = null; @@ -329,7 +329,7 @@ private void SetBlend(Material material, int src, int dst, int renderQueue, int material.SetInt("_SrcBlend", src); material.SetInt("_DstBlend", dst); material.SetInt("_ZWrite", zwrite); - material.SetInt("_AlphaToCoverage", alphatocoverage); + material.SetInt("_AlphaToMask", alphatocoverage); material.renderQueue = isRefractive ? (int)UnityEngine.Rendering.RenderQueue.Overlay - 1 : renderQueue; } @@ -650,13 +650,15 @@ private void DrawAdvancedSettings(MaterialEditor materialEditor, Material materi { if (isDithered || isCutout) { - XSStyles.CallTexArrayManager(); - materialEditor.TexturePropertySingleLine(new GUIContent("Clip Map (RGB | Tex2DArray)", "Texture Array used to control clipping based on the Clip Index parameter."), _ClipMaskArray); + //XSStyles.CallTexArrayManager(); + materialEditor.TexturePropertySingleLine(new GUIContent("Clip Map (RGB)", "Texture used to control clipping based on the Clip Index parameter."), _ClipMask); materialEditor.ShaderProperty(_UseClipsForDissolve, new GUIContent("Use For Dissolve"), 2); - materialEditor.ShaderProperty(_ClipIndex, new GUIContent("Clip Index", "The index to use for referencing the clipping mask in the array. Can be 0 - 15, for a total of 16 unique masks."), 2); + materialEditor.ShaderProperty(_UVSetClipMap, new GUIContent("UV Set", "The UV set to use for the Clip Map"), 2); XSStyles.DoHeaderLeft("Clip Against"); + materialEditor.ShaderProperty(_ClipIndex, new GUIContent("Clip Index", "Should be unique per material, controls which set of slider values to use for clipping. Can be 0 - 8(materials), with 8 masks in each texture, for a total of 64 unique masks."), 1); + XSStyles.SeparatorThin(); int materialClipIndex = material.GetInt("_ClipIndex"); switch (materialClipIndex) { @@ -671,17 +673,17 @@ private void DrawAdvancedSettings(MaterialEditor materialEditor, Material materi } } - XSStyles.SeparatorThin(); + XSStyles.Separator(); materialEditor.ShaderProperty(_VertexColorAlbedo, new GUIContent("Vertex Color Albedo", "Multiplies the vertex color of the mesh by the Albedo texture to derive the final Albedo color.")); materialEditor.ShaderProperty(_WireColor, new GUIContent("Wire Color On UV2", "This will only work with a specific second uv channel setup.")); materialEditor.ShaderProperty(_WireWidth, new GUIContent("Wire Width", "Controls the above wire width.")); - XSStyles.SeparatorThin(); + XSStyles.Separator(); materialEditor.ShaderProperty(_Stencil, _Stencil.displayName); materialEditor.ShaderProperty(_StencilComp, _StencilComp.displayName); materialEditor.ShaderProperty(_StencilOp, _StencilOp.displayName); - XSStyles.SeparatorThin(); + XSStyles.Separator(); materialEditor.RenderQueueField(); } } diff --git a/Main/CGIncludes/XSDefines.cginc b/Main/CGIncludes/XSDefines.cginc index 6046390..ac88eda 100644 --- a/Main/CGIncludes/XSDefines.cginc +++ b/Main/CGIncludes/XSDefines.cginc @@ -156,7 +156,7 @@ struct VertexLightInformation { float Attenuation[4]; }; -UNITY_DECLARE_TEX2DARRAY(_ClipMaskArray); + UNITY_DECLARE_TEX2D(_MainTex); half4 _MainTex_ST; UNITY_DECLARE_TEX2D_NOSAMPLER(_ClipMap); half4 _ClipMap_ST; UNITY_DECLARE_TEX2D_NOSAMPLER(_DissolveTexture); half4 _DissolveTexture_ST; @@ -172,6 +172,7 @@ UNITY_DECLARE_TEX2D_NOSAMPLER(_RampSelectionMask); UNITY_DECLARE_TEX2D_NOSAMPLER(_HSVMask); sampler2D _OcclusionMap; half4 _OcclusionMap_ST; sampler2D _OutlineMask; +sampler2D _ClipMask; sampler2D _Matcap; sampler2D _Ramp; samplerCUBE _BakedCubemap; @@ -227,6 +228,7 @@ int _UVSetAlbedo, _UVSetNormal, _UVSetDetNormal, _UVSetThickness, _UVSetOcclusion, _UVSetReflectivity, _UVSetEmission, _UVSetClipMap, _UVSetDissolve; int _NormalMapMode, _OutlineUVSelect; +int _AlphaToMask; //!RDPSDefines diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index 9e94b23..1bdc2ef 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -14,7 +14,7 @@ float4 frag ( #ifdef UNITY_PASS_SHADOWCASTER XSLighting o = (XSLighting)0; //Populate Lighting Struct, but only with important shadowcaster stuff! o.albedo = UNITY_SAMPLE_TEX2D(_MainTex, t.albedoUV) * _Color * lerp(1, float4(i.color.rgb, 1), _VertexColorAlbedo); - o.clipMap = UNITY_SAMPLE_TEX2DARRAY(_ClipMaskArray, float3(t.clipMapUV, _ClipIndex)); + o.clipMap = tex2Dlod(_ClipMask, float4(t.clipMapUV, 0, 0)); o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV); o.worldPos = i.worldPos; @@ -63,7 +63,7 @@ float4 frag ( o.emissionMap = UNITY_SAMPLE_TEX2D_SAMPLER(_EmissionMap, _MainTex, t.emissionMapUV) * _EmissionColor; o.rampMask = UNITY_SAMPLE_TEX2D_SAMPLER(_RampSelectionMask, _MainTex, i.uv); // This texture doesn't need to ever be on a second uv channel, and doesn't need tiling, convince me otherwise. o.hsvMask = UNITY_SAMPLE_TEX2D_SAMPLER(_HSVMask, _MainTex, t.albedoUV); - o.clipMap = UNITY_SAMPLE_TEX2DARRAY_LOD(_ClipMaskArray, float3(t.clipMapUV, _ClipIndex), 0); + o.clipMap = tex2Dlod(_ClipMask, float4(t.clipMapUV, 0, 0)); o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV); o.diffuseColor = o.albedo.rgb; //Store this to separate the texture color and diffuse color for later. diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index a04ea5e..0ef1fae 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -359,7 +359,7 @@ void calcAlpha(inout XSLighting i) #ifdef _ALPHATEST_ON float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); - if(_BlendMode >= 3) + if(_BlendMode == 3 || _AlphaToMask == 1) { half dither = calcDither(i.screenUV.xy); i.alpha = modifiedAlpha - (dither * (1-i.albedo.a) * 0.15); diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon2.0.shader index 4601d77..07de7c2 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon2.0.shader @@ -136,9 +136,8 @@ [HideInInspector] _ZWrite ("__zw", int) = 1 [HideInInspector] _AlphaToMask("__am", int) = 0 - //A bit of a hack, but, a pretty okay hack? - _ClipMaskArray("Clip Mask Array", 2DArray) = "black" {} - [IntRange]_ClipIndex("Clip Index", Range(0,15)) = 0 + _ClipMask("Clip Mask", 2D) = "black" {} + [IntRange]_ClipIndex("Clip Index", Range(0,8)) = 0 _ClipSlider00("", Vector) = (1,1,1,1) _ClipSlider01("", Vector) = (1,1,1,1) _ClipSlider02("", Vector) = (1,1,1,1) From 43580d2cc513643552085f24e7fd3c16126a796b Mon Sep 17 00:00:00 2001 From: Xiexe Date: Sat, 1 May 2021 00:02:27 -0400 Subject: [PATCH 11/30] Add support for scrolling dissolve layers --- Editor/XSToonInspector.cs | 17 +++++++++++++++-- Main/CGIncludes/XSDefines.cginc | 3 +++ Main/CGIncludes/XSFrag.cginc | 3 ++- Main/CGIncludes/XSHelperFunctions.cginc | 3 ++- Main/Shaders/XSToon2.0.shader | 6 ++++++ Main/Shaders/XSToon2.0_Outlined.shader | 6 ++++++ 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index c6b70ec..3b7498b 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -149,6 +149,11 @@ public class XSToonInspector : ShaderGUI private MaterialProperty _WireWidth = null; //Experimenting + private MaterialProperty _DissolveBlendPower = null; + private MaterialProperty _DissolveLayer1Scale = null; + private MaterialProperty _DissolveLayer2Scale = null; + private MaterialProperty _DissolveLayer1Speed = null; + private MaterialProperty _DissolveLayer2Speed = null; private MaterialProperty _ClipMask = null; private MaterialProperty _ClipIndex = null; private MaterialProperty _ClipSlider00 = null; @@ -363,7 +368,7 @@ private void DrawMainSettings(MaterialEditor materialEditor, Material material) private void DrawDissolveSettings(MaterialEditor materialEditor, Material material) { - if (isCutout || isDithered) + if (isCutout || isDithered || material.GetInt("_AlphaToMask") > 0) { Foldouts[material].ShowDissolve = XSStyles.ShurikenFoldout("Dissolve", Foldouts[material].ShowDissolve); if (Foldouts[material].ShowDissolve) @@ -373,6 +378,14 @@ private void DrawDissolveSettings(MaterialEditor materialEditor, Material materi materialEditor.TextureScaleOffsetProperty(_DissolveTexture); materialEditor.ShaderProperty(_UVSetDissolve, new GUIContent("UV Set", "The UV set to use for the Dissolve Texture."), 2); + + materialEditor.ShaderProperty(_DissolveBlendPower, new GUIContent("Layer Blend", "How much to boost the blended layers")); + materialEditor.ShaderProperty(_DissolveLayer1Scale, new GUIContent("Layer 1 Scale", "How much tiling to apply to the layer.")); + materialEditor.ShaderProperty(_DissolveLayer1Speed, new GUIContent("Layer 1 Speed", "Scroll Speed of the layer, can be negative.")); + + materialEditor.ShaderProperty(_DissolveLayer2Scale, new GUIContent("Layer 2 Scale", "How much tiling to apply to the layer.")); + materialEditor.ShaderProperty(_DissolveLayer2Speed, new GUIContent("Layer 2 Speed", "Scroll Speed of the layer, can be negative.")); + materialEditor.ShaderProperty(_DissolveStrength, new GUIContent("Dissolve Sharpness", "Sharpness of the dissolve texture.")); materialEditor.ShaderProperty(_DissolveProgress, new GUIContent("Dissolve Progress", "Progress of the dissolve effect.")); } @@ -648,7 +661,7 @@ private void DrawAdvancedSettings(MaterialEditor materialEditor, Material materi Foldouts[material].ShowAdvanced = XSStyles.ShurikenFoldout("Advanced Settings", Foldouts[material].ShowAdvanced); if (Foldouts[material].ShowAdvanced) { - if (isDithered || isCutout) + if (isDithered || isCutout || material.GetInt("_AlphaToMask") > 0) { //XSStyles.CallTexArrayManager(); materialEditor.TexturePropertySingleLine(new GUIContent("Clip Map (RGB)", "Texture used to control clipping based on the Clip Index parameter."), _ClipMask); diff --git a/Main/CGIncludes/XSDefines.cginc b/Main/CGIncludes/XSDefines.cginc index ac88eda..6b3a826 100644 --- a/Main/CGIncludes/XSDefines.cginc +++ b/Main/CGIncludes/XSDefines.cginc @@ -104,6 +104,7 @@ struct XSLighting half4 hsvMask; half4 clipMap; half4 dissolveMask; + half4 dissolveMaskSecondLayer; half3 diffuseColor; half attenuation; half3 normal; @@ -209,6 +210,8 @@ half _RimRange, _RimThreshold, _RimIntensity, _RimSharpness, _RimAlbedoTint, _Ri half _ShadowRimRange, _ShadowRimThreshold, _ShadowRimSharpness, _ShadowSharpness, _ShadowRimAlbedoTint; half _SSDistortion, _SSPower, _SSScale; half _OutlineWidth; +half _DissolveBlendPower, _DissolveLayer1Scale, _DissolveLayer2Scale, _DissolveLayer1Speed, _DissolveLayer2Speed; + half4 _ClipSlider00,_ClipSlider01,_ClipSlider02,_ClipSlider03, _ClipSlider04,_ClipSlider05,_ClipSlider06,_ClipSlider07, _ClipSlider08,_ClipSlider09,_ClipSlider10,_ClipSlider11, diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index 1bdc2ef..cb991c6 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -64,7 +64,8 @@ float4 frag ( o.rampMask = UNITY_SAMPLE_TEX2D_SAMPLER(_RampSelectionMask, _MainTex, i.uv); // This texture doesn't need to ever be on a second uv channel, and doesn't need tiling, convince me otherwise. o.hsvMask = UNITY_SAMPLE_TEX2D_SAMPLER(_HSVMask, _MainTex, t.albedoUV); o.clipMap = tex2Dlod(_ClipMask, float4(t.clipMapUV, 0, 0)); - o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV); + o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV * _DissolveLayer1Scale + (_Time.y * _DissolveLayer1Speed)); + o.dissolveMaskSecondLayer = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV * _DissolveLayer2Scale + (_Time.y * _DissolveLayer2Speed)); o.diffuseColor = o.albedo.rgb; //Store this to separate the texture color and diffuse color for later. o.attenuation = attenuation; diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 0ef1fae..d28d541 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -307,7 +307,8 @@ float AdjustAlphaUsingTextureArray(XSLighting i, float alphaToAdj) void calcDissolve(inout XSLighting i, inout float4 col) { #ifdef _ALPHATEST_ON - half dissolveAmt = Remap_Float(i.dissolveMask.x, float2(0,1), float2(0.1, 0.9)); + float4 mask = i.dissolveMask.x * i.dissolveMaskSecondLayer.x * _DissolveBlendPower; + half dissolveAmt = Remap_Float(mask, float2(0,1), float2(0.25, 0.75)); half dissolveProgress = saturate(_DissolveProgress + lerp(0, 1-AdjustAlphaUsingTextureArray(i, 1), _UseClipsForDissolve)); half dissolve = 0; if (_DissolveCoordinates == 0) diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon2.0.shader index 07de7c2..ffc80dc 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon2.0.shader @@ -102,6 +102,12 @@ [Enum(UV, 0, Root Distance (Spherical), 1, Height, 2)]_DissolveCoordinates("Dissolve Shape", Int) = 0 _DissolveTexture("Dissolve Texture", 2D) = "black" {} + _DissolveBlendPower("Layer Blend Power", Float) = 1 + _DissolveLayer1Scale("Layer1 Scale", Float) = 1 + _DissolveLayer2Scale("Layer2 Scale", Float) = 0.5 + _DissolveLayer1Speed("Layer1 Speed", Float) = 0 + _DissolveLayer2Speed("Layer2 Speed", Float) = 0 + _DissolveStrength("Dissolve Sharpness", Float) = 1 [HDR]_DissolveColor("Dissolve Color", Color) = (1,1,1,1) _DissolveProgress("Dissolve Amount", Range(0,1)) = 0 diff --git a/Main/Shaders/XSToon2.0_Outlined.shader b/Main/Shaders/XSToon2.0_Outlined.shader index a35de33..717476e 100644 --- a/Main/Shaders/XSToon2.0_Outlined.shader +++ b/Main/Shaders/XSToon2.0_Outlined.shader @@ -102,6 +102,12 @@ [Enum(UV, 0, Root Distance (Spherical), 1, Height, 2)]_DissolveCoordinates("Dissolve Shape", Int) = 0 _DissolveTexture("Dissolve Texture", 2D) = "black" {} + _DissolveBlendPower("Layer Blend Power", Float) = 1 + _DissolveLayer1Scale("Layer1 Scale", float) = 1 + _DissolveLayer2Scale("Layer2 Scale", float) = 0.5 + _DissolveLayer1Speed("Layer1 Speed", float) = 0 + _DissolveLayer2Speed("Layer2 Speed", float) = 0 + _DissolveStrength("Dissolve Sharpness", Float) = 1 [HDR]_DissolveColor("Dissolve Color", Color) = (1,1,1,1) _DissolveProgress("Dissolve Amount", Range(0,1)) = 0 From 38575ab408e83be3cd05fac7618c883ec899624a Mon Sep 17 00:00:00 2001 From: Xiexe Date: Sat, 1 May 2021 00:20:48 -0400 Subject: [PATCH 12/30] streamline a2c check --- Editor/XSToonInspector.cs | 6 ++++-- Main/Shaders/XSToon2.0_Outlined.shader | 13 ++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 3b7498b..742b38b 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -194,6 +194,7 @@ public class XSToonInspector : ShaderGUI private bool isCutout = false; private bool isCutoutMasked = false; private bool isDithered = false; + private bool isA2C = false; private bool isRefractive = false; @@ -204,6 +205,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro isCutout = material.GetInt("_BlendMode") == 1; isDithered = material.GetInt("_BlendMode") == 2; + isA2C = material.GetInt("_BlendMode") == 3; isRefractive = material.GetInt("_UseRefraction") == 1; isOutlined = shader.name.Contains("Outline"); isPatreonShader = shader.name.Contains("Patreon"); @@ -368,7 +370,7 @@ private void DrawMainSettings(MaterialEditor materialEditor, Material material) private void DrawDissolveSettings(MaterialEditor materialEditor, Material material) { - if (isCutout || isDithered || material.GetInt("_AlphaToMask") > 0) + if (isCutout || isDithered || isA2C) { Foldouts[material].ShowDissolve = XSStyles.ShurikenFoldout("Dissolve", Foldouts[material].ShowDissolve); if (Foldouts[material].ShowDissolve) @@ -661,7 +663,7 @@ private void DrawAdvancedSettings(MaterialEditor materialEditor, Material materi Foldouts[material].ShowAdvanced = XSStyles.ShurikenFoldout("Advanced Settings", Foldouts[material].ShowAdvanced); if (Foldouts[material].ShowAdvanced) { - if (isDithered || isCutout || material.GetInt("_AlphaToMask") > 0) + if (isDithered || isCutout || isA2C) { //XSStyles.CallTexArrayManager(); materialEditor.TexturePropertySingleLine(new GUIContent("Clip Map (RGB)", "Texture used to control clipping based on the Clip Index parameter."), _ClipMask); diff --git a/Main/Shaders/XSToon2.0_Outlined.shader b/Main/Shaders/XSToon2.0_Outlined.shader index 717476e..ad8107d 100644 --- a/Main/Shaders/XSToon2.0_Outlined.shader +++ b/Main/Shaders/XSToon2.0_Outlined.shader @@ -103,10 +103,10 @@ [Enum(UV, 0, Root Distance (Spherical), 1, Height, 2)]_DissolveCoordinates("Dissolve Shape", Int) = 0 _DissolveTexture("Dissolve Texture", 2D) = "black" {} _DissolveBlendPower("Layer Blend Power", Float) = 1 - _DissolveLayer1Scale("Layer1 Scale", float) = 1 - _DissolveLayer2Scale("Layer2 Scale", float) = 0.5 - _DissolveLayer1Speed("Layer1 Speed", float) = 0 - _DissolveLayer2Speed("Layer2 Speed", float) = 0 + _DissolveLayer1Scale("Layer1 Scale", Float) = 1 + _DissolveLayer2Scale("Layer2 Scale", Float) = 0.5 + _DissolveLayer1Speed("Layer1 Speed", Float) = 0 + _DissolveLayer2Speed("Layer2 Speed", Float) = 0 _DissolveStrength("Dissolve Sharpness", Float) = 1 [HDR]_DissolveColor("Dissolve Color", Color) = (1,1,1,1) @@ -142,9 +142,8 @@ [HideInInspector] _ZWrite ("__zw", int) = 1 [HideInInspector] _AlphaToMask("__am", int) = 0 - //A bit of a hack, but, a pretty okay hack? - _ClipMaskArray("Clip Mask Array", 2DArray) = "black" {} - [IntRange]_ClipIndex("Clip Index", Range(0,15)) = 0 + _ClipMask("Clip Mask", 2D) = "black" {} + [IntRange]_ClipIndex("Clip Index", Range(0,8)) = 0 _ClipSlider00("", Vector) = (1,1,1,1) _ClipSlider01("", Vector) = (1,1,1,1) _ClipSlider02("", Vector) = (1,1,1,1) From 2d82ec65c2b06fea3991e6a77e4cfadc00a4255b Mon Sep 17 00:00:00 2001 From: Xiexe Date: Sat, 1 May 2021 00:21:55 -0400 Subject: [PATCH 13/30] limit index slider --- Main/Shaders/XSToon2.0.shader | 2 +- Main/Shaders/XSToon2.0_Outlined.shader | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon2.0.shader index ffc80dc..91aad67 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon2.0.shader @@ -143,7 +143,7 @@ [HideInInspector] _AlphaToMask("__am", int) = 0 _ClipMask("Clip Mask", 2D) = "black" {} - [IntRange]_ClipIndex("Clip Index", Range(0,8)) = 0 + [IntRange]_ClipIndex("Clip Index", Range(0,7)) = 0 _ClipSlider00("", Vector) = (1,1,1,1) _ClipSlider01("", Vector) = (1,1,1,1) _ClipSlider02("", Vector) = (1,1,1,1) diff --git a/Main/Shaders/XSToon2.0_Outlined.shader b/Main/Shaders/XSToon2.0_Outlined.shader index ad8107d..a323855 100644 --- a/Main/Shaders/XSToon2.0_Outlined.shader +++ b/Main/Shaders/XSToon2.0_Outlined.shader @@ -143,7 +143,7 @@ [HideInInspector] _AlphaToMask("__am", int) = 0 _ClipMask("Clip Mask", 2D) = "black" {} - [IntRange]_ClipIndex("Clip Index", Range(0,8)) = 0 + [IntRange]_ClipIndex("Clip Index", Range(0,7)) = 0 _ClipSlider00("", Vector) = (1,1,1,1) _ClipSlider01("", Vector) = (1,1,1,1) _ClipSlider02("", Vector) = (1,1,1,1) From 20ded267774476092d4a86c65bd306d874d41ff9 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Sat, 1 May 2021 00:53:04 -0400 Subject: [PATCH 14/30] Invert sliders to make Unity animator happy --- Main/CGIncludes/XSHelperFunctions.cginc | 16 ++++++------- Main/Shaders/XSToon2.0.shader | 32 ++++++++++++------------- Main/Shaders/XSToon2.0_Outlined.shader | 32 ++++++++++++------------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index d28d541..2b6a66c 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -290,16 +290,16 @@ float AdjustAlphaUsingTextureArray(XSLighting i, float alphaToAdj) } //Compares to Red, Green, Blue, and White against the first slider set - alphaToAdj *= lerp(1, compValRGBW.r, IsColorMatch(i.clipMap.rgb, float3(1,0,0))); - alphaToAdj *= lerp(1, compValRGBW.g, IsColorMatch(i.clipMap.rgb, float3(0,1,0))); - alphaToAdj *= lerp(1, compValRGBW.b, IsColorMatch(i.clipMap.rgb, float3(0,0,1))); - alphaToAdj *= lerp(1, compValRGBW.w, IsColorMatch(i.clipMap.rgb, float3(1,1,1))); + alphaToAdj *= lerp(1, 1-compValRGBW.r, IsColorMatch(i.clipMap.rgb, float3(1,0,0))); + alphaToAdj *= lerp(1, 1-compValRGBW.g, IsColorMatch(i.clipMap.rgb, float3(0,1,0))); + alphaToAdj *= lerp(1, 1-compValRGBW.b, IsColorMatch(i.clipMap.rgb, float3(0,0,1))); + alphaToAdj *= lerp(1, 1-compValRGBW.w, IsColorMatch(i.clipMap.rgb, float3(1,1,1))); //Compares to Cyan, Yellow, Magenta, and Black against the second slider set - alphaToAdj *= lerp(1, compValCYMB.r, IsColorMatch(i.clipMap.rgb, float3(0,1,1))); - alphaToAdj *= lerp(1, compValCYMB.g, IsColorMatch(i.clipMap.rgb, float3(1,1,0))); - alphaToAdj *= lerp(1, compValCYMB.b, IsColorMatch(i.clipMap.rgb, float3(1,0,1))); - alphaToAdj *= lerp(1, compValCYMB.w, IsColorMatch(i.clipMap.rgb, float3(0,0,0))); + alphaToAdj *= lerp(1, 1-compValCYMB.r, IsColorMatch(i.clipMap.rgb, float3(0,1,1))); + alphaToAdj *= lerp(1, 1-compValCYMB.g, IsColorMatch(i.clipMap.rgb, float3(1,1,0))); + alphaToAdj *= lerp(1, 1-compValCYMB.b, IsColorMatch(i.clipMap.rgb, float3(1,0,1))); + alphaToAdj *= lerp(1, 1-compValCYMB.w, IsColorMatch(i.clipMap.rgb, float3(0,0,0))); return alphaToAdj; } diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon2.0.shader index 91aad67..3e9c97f 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon2.0.shader @@ -144,22 +144,22 @@ _ClipMask("Clip Mask", 2D) = "black" {} [IntRange]_ClipIndex("Clip Index", Range(0,7)) = 0 - _ClipSlider00("", Vector) = (1,1,1,1) - _ClipSlider01("", Vector) = (1,1,1,1) - _ClipSlider02("", Vector) = (1,1,1,1) - _ClipSlider03("", Vector) = (1,1,1,1) - _ClipSlider04("", Vector) = (1,1,1,1) - _ClipSlider05("", Vector) = (1,1,1,1) - _ClipSlider06("", Vector) = (1,1,1,1) - _ClipSlider07("", Vector) = (1,1,1,1) - _ClipSlider08("", Vector) = (1,1,1,1) - _ClipSlider09("", Vector) = (1,1,1,1) - _ClipSlider10("", Vector) = (1,1,1,1) - _ClipSlider11("", Vector) = (1,1,1,1) - _ClipSlider12("", Vector) = (1,1,1,1) - _ClipSlider13("", Vector) = (1,1,1,1) - _ClipSlider14("", Vector) = (1,1,1,1) - _ClipSlider15("", Vector) = (1,1,1,1) + _ClipSlider00("", Vector) = (0,0,0,0) + _ClipSlider01("", Vector) = (0,0,0,0) + _ClipSlider02("", Vector) = (0,0,0,0) + _ClipSlider03("", Vector) = (0,0,0,0) + _ClipSlider04("", Vector) = (0,0,0,0) + _ClipSlider05("", Vector) = (0,0,0,0) + _ClipSlider06("", Vector) = (0,0,0,0) + _ClipSlider07("", Vector) = (0,0,0,0) + _ClipSlider08("", Vector) = (0,0,0,0) + _ClipSlider09("", Vector) = (0,0,0,0) + _ClipSlider10("", Vector) = (0,0,0,0) + _ClipSlider11("", Vector) = (0,0,0,0) + _ClipSlider12("", Vector) = (0,0,0,0) + _ClipSlider13("", Vector) = (0,0,0,0) + _ClipSlider14("", Vector) = (0,0,0,0) + _ClipSlider15("", Vector) = (0,0,0,0) //!RDPSProps } diff --git a/Main/Shaders/XSToon2.0_Outlined.shader b/Main/Shaders/XSToon2.0_Outlined.shader index a323855..4e394f5 100644 --- a/Main/Shaders/XSToon2.0_Outlined.shader +++ b/Main/Shaders/XSToon2.0_Outlined.shader @@ -144,22 +144,22 @@ _ClipMask("Clip Mask", 2D) = "black" {} [IntRange]_ClipIndex("Clip Index", Range(0,7)) = 0 - _ClipSlider00("", Vector) = (1,1,1,1) - _ClipSlider01("", Vector) = (1,1,1,1) - _ClipSlider02("", Vector) = (1,1,1,1) - _ClipSlider03("", Vector) = (1,1,1,1) - _ClipSlider04("", Vector) = (1,1,1,1) - _ClipSlider05("", Vector) = (1,1,1,1) - _ClipSlider06("", Vector) = (1,1,1,1) - _ClipSlider07("", Vector) = (1,1,1,1) - _ClipSlider08("", Vector) = (1,1,1,1) - _ClipSlider09("", Vector) = (1,1,1,1) - _ClipSlider10("", Vector) = (1,1,1,1) - _ClipSlider11("", Vector) = (1,1,1,1) - _ClipSlider12("", Vector) = (1,1,1,1) - _ClipSlider13("", Vector) = (1,1,1,1) - _ClipSlider14("", Vector) = (1,1,1,1) - _ClipSlider15("", Vector) = (1,1,1,1) + _ClipSlider00("", Vector) = (0,0,0,0) + _ClipSlider01("", Vector) = (0,0,0,0) + _ClipSlider02("", Vector) = (0,0,0,0) + _ClipSlider03("", Vector) = (0,0,0,0) + _ClipSlider04("", Vector) = (0,0,0,0) + _ClipSlider05("", Vector) = (0,0,0,0) + _ClipSlider06("", Vector) = (0,0,0,0) + _ClipSlider07("", Vector) = (0,0,0,0) + _ClipSlider08("", Vector) = (0,0,0,0) + _ClipSlider09("", Vector) = (0,0,0,0) + _ClipSlider10("", Vector) = (0,0,0,0) + _ClipSlider11("", Vector) = (0,0,0,0) + _ClipSlider12("", Vector) = (0,0,0,0) + _ClipSlider13("", Vector) = (0,0,0,0) + _ClipSlider14("", Vector) = (0,0,0,0) + _ClipSlider15("", Vector) = (0,0,0,0) //!RDPSProps } From 771c4aa4b882a2dc216745aa071b2842b6d88b99 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Sat, 1 May 2021 01:07:02 -0400 Subject: [PATCH 15/30] make a comment more clear --- Main/CGIncludes/XSHelperFunctions.cginc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 2b6a66c..57de84e 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -277,7 +277,7 @@ float AdjustAlphaUsingTextureArray(XSLighting i, float alphaToAdj) { half4 compValRGBW = 0; // Red Green Blue White half4 compValCYMB = 0; // Cyan Yellow Magenta Black - switch (_ClipIndex) // Each of these is a Vector / 4 masks, 2 per material, so 8 masks per material, 16 total. + switch (_ClipIndex) // Each of these is a Vector / 4 masks, 2 per material, so 8 masks per material, 8 materials max, 64 total masks { case 0 : compValRGBW = _ClipSlider00; compValCYMB = _ClipSlider01; break; case 1 : compValRGBW = _ClipSlider02; compValCYMB = _ClipSlider03; break; From 8eb0fcafcc4ce7438ce65548ab892d4b3f78423d Mon Sep 17 00:00:00 2001 From: Xiexe Date: Tue, 4 May 2021 21:19:22 -0400 Subject: [PATCH 16/30] Fix shadowcasting... again... why is this so stupid --- Editor/XSToonInspector.cs | 2 +- Main/CGIncludes/XSFrag.cginc | 24 +++++------ Main/CGIncludes/XSHelperFunctions.cginc | 32 ++++++++------ Main/Test.mat | 57 +++++++++++++++---------- 4 files changed, 65 insertions(+), 50 deletions(-) diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 742b38b..3549039 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -300,7 +300,7 @@ private void DoBlendModeSettings(Material material) SetBlend(material, (int) UnityEngine.Rendering.BlendMode.One, (int) UnityEngine.Rendering.BlendMode.Zero, (int) UnityEngine.Rendering.RenderQueue.AlphaTest, 1, 1); - material.DisableKeyword("_ALPHABLEND_ON"); + material.EnableKeyword("_ALPHABLEND_ON"); material.EnableKeyword("_ALPHATEST_ON"); break; diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index cb991c6..cd666f2 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -13,19 +13,21 @@ float4 frag ( #ifdef UNITY_PASS_SHADOWCASTER XSLighting o = (XSLighting)0; //Populate Lighting Struct, but only with important shadowcaster stuff! - o.albedo = UNITY_SAMPLE_TEX2D(_MainTex, t.albedoUV) * _Color * lerp(1, float4(i.color.rgb, 1), _VertexColorAlbedo); + o.albedo = UNITY_SAMPLE_TEX2D(_MainTex, t.albedoUV) * _Color; o.clipMap = tex2Dlod(_ClipMask, float4(t.clipMapUV, 0, 0)); - o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV); + o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV * _DissolveLayer1Scale + (_Time.y * _DissolveLayer1Speed)); + o.dissolveMaskSecondLayer = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV * _DissolveLayer2Scale + (_Time.y * _DissolveLayer2Speed)); o.worldPos = i.worldPos; o.screenUV = calcScreenUVs(i.screenPos); o.screenPos = i.screenPos; o.objPos = i.objPos; - float4 outCol = 0; - calcAlpha(o); - calcDissolve(o, outCol); - SHADOW_CASTER_FRAGMENT(i); + float alpha = o.albedo.a; + calcAlpha(o, alpha); + calcDissolve(o, o.albedo.rgb); + return alpha; + #else UNITY_LIGHT_ATTENUATION(attenuation, i, i.worldPos.xyz); @@ -80,12 +82,10 @@ float4 frag ( o.objPos = i.objPos; float4 col = BRDF_XSLighting(o); - calcAlpha(o); - calcDissolve(o, col); + float alpha = 1; + calcAlpha(o, alpha); + calcDissolve(o, col.rgb); UNITY_APPLY_FOG(i.fogCoord, col); - // float clipR = IsColorMatch(o.clipMap.rgb, float3(1,0,0)); - // return lerp(float4(col.rgb, 1), clipR, 0.9999); - // return lerp(float4(col.rgb, 1), float4(o.clipMap.rgb, 1), 0.9999); - return float4(col.rgb, o.alpha); + return float4(col.rgb, alpha); #endif } \ No newline at end of file diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 57de84e..8ff5e16 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -304,7 +304,7 @@ float AdjustAlphaUsingTextureArray(XSLighting i, float alphaToAdj) return alphaToAdj; } -void calcDissolve(inout XSLighting i, inout float4 col) +void calcDissolve(inout XSLighting i, inout float3 col) { #ifdef _ALPHATEST_ON float4 mask = i.dissolveMask.x * i.dissolveMaskSecondLayer.x * _DissolveBlendPower; @@ -340,32 +340,26 @@ void calcDissolve(inout XSLighting i, inout float4 col) dissCol.rgb = hsv2rgb(dissCol.rgb); half dissolveEdge = smoothstep(dissolve, dissolve - (_DissolveStrength * 0.01), dissolve * dissolveAmt); + dissCol.rgb *= saturate(sin(dissolveProgress * 4) * 3); col.rgb += (1-dissolveEdge) * dissCol.rgb; #endif #endif } -void calcAlpha(inout XSLighting i) +//todo: What the fuck is going on here? +void calcAlpha(inout XSLighting i, inout float alpha) { - i.alpha = 1; - - #ifdef _ALPHABLEND_ON - i.alpha = i.albedo.a; + #if defined(_ALPHABLEND_ON) && !defined(_ALPHATEST_ON) // Traditional Alphablended / Fade blending + alpha = i.albedo.a; #ifdef UNITY_PASS_SHADOWCASTER half dither = calcDither(i.screenUV.xy); - clip(i.alpha - dither); + clip(alpha - dither); #endif #endif - #ifdef _ALPHATEST_ON + #if !defined(_ALPHABLEND_ON) && defined(_ALPHATEST_ON) // Dithered / Cutout transparency float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); - if(_BlendMode == 3 || _AlphaToMask == 1) - { - half dither = calcDither(i.screenUV.xy); - i.alpha = modifiedAlpha - (dither * (1-i.albedo.a) * 0.15); - } - if(_BlendMode == 2) { half dither = calcDither(i.screenUV.xy); @@ -382,6 +376,16 @@ void calcAlpha(inout XSLighting i) clip(modifiedAlpha - _Cutoff); } #endif + + #if defined(_ALPHABLEND_ON) && defined(_ALPHATEST_ON) // Alpha to Coverage + float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); + half dither = calcDither(i.screenUV.xy); + alpha = modifiedAlpha - (dither * (1-i.albedo.a) * 0.15); + + #if defined(UNITY_PASS_SHADOWCASTER) + clip(modifiedAlpha - dither); + #endif + #endif } // //Halftone functions, finish implementing later.. Not correct right now. diff --git a/Main/Test.mat b/Main/Test.mat index 697f6a8..cf618ee 100644 --- a/Main/Test.mat +++ b/Main/Test.mat @@ -32,7 +32,7 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - - _DetailAlbedoMap: + - _ClipMask: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} @@ -76,10 +76,6 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - - _ParallaxMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - _Ramp: m_Texture: {fileID: 2800000, guid: 529b95e318b684643b47bd73e037118a, type: 3} m_Scale: {x: 1, y: 1} @@ -101,7 +97,7 @@ Material: m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} m_Floats: - - _AdvMode: 1 + - _AdvMode: 0 - _AlphaToMask: 0 - _AnisotropicReflection: 0 - _AnisotropicSpecular: 0 @@ -110,19 +106,23 @@ Material: - _ClearCoat: 0 - _ClearcoatSmoothness: 0.8 - _ClearcoatStrength: 1 + - _ClipIndex: 0 - _Culling: 2 - _Cutoff: 0.5 - _DetailNormalMapScale: 1 + - _DissolveBlendPower: 1 - _DissolveCoordinates: 0 + - _DissolveLayer1Scale: 1 + - _DissolveLayer1Speed: 0 + - _DissolveLayer2Scale: 0.5 + - _DissolveLayer2Speed: 0 - _DissolveProgress: 0 - _DissolveStrength: 1 - _DstBlend: 10 - _EmissionToDiffuse: 0 - _FadeDither: 0 - _FadeDitherDistance: 0 - - _GlossMapScale: 1 - - _Glossiness: 0.832 - - _GlossyReflections: 1 + - _Glossiness: 0 - _HalftoneDotAmount: 5 - _HalftoneDotSize: 0.5 - _HalftoneLineAmount: 2000 @@ -132,20 +132,17 @@ Material: - _IOR: 0 - _MatcapTintToDiffuse: 0 - _Metallic: 0 - - _Mode: 0 - _NormalMapMode: 0 - _OcclusionIntensity: 1 - _OcclusionMode: 0 - - _OcclusionStrength: 1 - _OutlineAlbedoTint: 0 - _OutlineLighting: 0 - _OutlineNormalMode: 0 - _OutlineUVSelect: 2 - _OutlineWidth: 1 - - _Parallax: 0.02 - _ReflectionBlendMode: 0 - - _ReflectionMode: 0 - - _Reflectivity: 1 + - _ReflectionMode: 3 + - _Reflectivity: 0.5 - _RefractionModel: 0 - _RimAlbedoTint: 0 - _RimAttenEffect: 1 @@ -165,18 +162,15 @@ Material: - _ShadowRimSharpness: 0.3 - _ShadowRimThreshold: 0.1 - _ShadowSharpness: 0.5 - - _SmoothnessTextureChannel: 0 - - _SpecularAlbedoTint: 0 - - _SpecularArea: 0.045 - - _SpecularHighlights: 1 - - _SpecularIntensity: 1 + - _SpecularAlbedoTint: 1 + - _SpecularArea: 0.5 + - _SpecularIntensity: 0 - _SpecularSharpness: 0 - _SrcBlend: 1 - _Stencil: 0 - _StencilComp: 0 - _StencilOp: 0 - _TilingMode: 0 - - _UVSec: 0 - _UVSetAlbedo: 0 - _UVSetClipMap: 0 - _UVSetDetMask: 0 @@ -193,16 +187,33 @@ Material: - _UseRefraction: 0 - _Value: 1 - _VertexColorAlbedo: 0 + - _WireWidth: 0 - _ZWrite: 0 m_Colors: - _ClipAgainstVertexColorGreaterZeroFive: {r: 1, g: 1, b: 1, a: 1} - _ClipAgainstVertexColorLessZeroFive: {r: 1, g: 1, b: 1, a: 1} - - _Color: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider00: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider01: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider02: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider03: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider04: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider05: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider06: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider07: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider08: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider09: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider10: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider11: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider12: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider13: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider14: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider15: {r: 0, g: 0, b: 0, a: 0} + - _Color: {r: 0, g: 0, b: 0, a: 1} - _DissolveColor: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} - _MatcapTint: {r: 1, g: 1, b: 1, a: 1} - - _OcclusionColor: {r: 0, g: 0, b: 0, a: 0} - _OutlineColor: {r: 0, g: 0, b: 0, a: 1} - _RimColor: {r: 1, g: 1, b: 1, a: 1} - _SSColor: {r: 0, g: 0, b: 0, a: 0} - _ShadowRim: {r: 1, g: 1, b: 1, a: 1} + - _WireColor: {r: 0, g: 0, b: 0, a: 0} From dae86936c5b5591d6375e24c34fc77e7ae959d3c Mon Sep 17 00:00:00 2001 From: Xiexe Date: Tue, 4 May 2021 21:27:37 -0400 Subject: [PATCH 17/30] fix alpha --- Main/CGIncludes/XSFrag.cginc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index cd666f2..e8bde0b 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -27,7 +27,6 @@ float4 frag ( calcAlpha(o, alpha); calcDissolve(o, o.albedo.rgb); return alpha; - #else UNITY_LIGHT_ATTENUATION(attenuation, i, i.worldPos.xyz); @@ -82,7 +81,7 @@ float4 frag ( o.objPos = i.objPos; float4 col = BRDF_XSLighting(o); - float alpha = 1; + float alpha = o.albedo.a; calcAlpha(o, alpha); calcDissolve(o, col.rgb); UNITY_APPLY_FOG(i.fogCoord, col); From 97984a19fdc752a747d0e4968417fd646ab14492 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 26 May 2021 02:14:52 -0400 Subject: [PATCH 18/30] Add support for audio link for emissions, remove refraction --- Editor/XSToonInspector.cs | 83 +++--- Main/CGIncludes/AudioLink.cginc | 321 ++++++++++++++++++++++ Main/CGIncludes/AudioLink.cginc.meta | 9 + Main/CGIncludes/XSDefines.cginc | 19 +- Main/CGIncludes/XSFrag.cginc | 4 +- Main/CGIncludes/XSHelperFunctions.cginc | 1 - Main/CGIncludes/XSLighting.cginc | 24 +- Main/CGIncludes/XSLightingFunctions.cginc | 36 ++- Main/Shaders/XSToon2.0.shader | 25 +- Main/Shaders/XSToon2.0_Outlined.shader | 24 +- 10 files changed, 454 insertions(+), 92 deletions(-) create mode 100644 Main/CGIncludes/AudioLink.cginc create mode 100644 Main/CGIncludes/AudioLink.cginc.meta diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 3549039..669a6d2 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -22,7 +22,7 @@ public class FoldoutToggles public bool ShowEmission = false; public bool ShowAdvanced = false; public bool ShowEyeTracking = false; - public bool ShowRefraction = false; + public bool ShowAudioLink = false; public bool ShowDissolve = false; } @@ -72,6 +72,8 @@ public class XSToonInspector : ShaderGUI private MaterialProperty _ScaleWithLight = null; private MaterialProperty _ScaleWithLightSensitivity = null; private MaterialProperty _EmissionColor = null; + private MaterialProperty _EmissionColor0 = null; + private MaterialProperty _EmissionColor1 = null; private MaterialProperty _EmissionToDiffuse = null; private MaterialProperty _RimColor = null; private MaterialProperty _RimIntensity = null; @@ -136,8 +138,6 @@ public class XSToonInspector : ShaderGUI private MaterialProperty _ClipAgainstVertexColorGreaterZeroFive = null; private MaterialProperty _ClipAgainstVertexColorLessZeroFive = null; private MaterialProperty _IOR = null; - private MaterialProperty _UseRefraction = null; - private MaterialProperty _RefractionModel = null; private MaterialProperty _NormalMapMode = null; private MaterialProperty _DissolveCoordinates = null; private MaterialProperty _DissolveTexture = null; @@ -148,6 +148,8 @@ public class XSToonInspector : ShaderGUI private MaterialProperty _WireColor = null; private MaterialProperty _WireWidth = null; + private MaterialProperty _EmissionAudioLinkChannel = null; + //Experimenting private MaterialProperty _DissolveBlendPower = null; private MaterialProperty _DissolveLayer1Scale = null; @@ -195,8 +197,6 @@ public class XSToonInspector : ShaderGUI private bool isCutoutMasked = false; private bool isDithered = false; private bool isA2C = false; - private bool isRefractive = false; - public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { @@ -206,7 +206,6 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro isCutout = material.GetInt("_BlendMode") == 1; isDithered = material.GetInt("_BlendMode") == 2; isA2C = material.GetInt("_BlendMode") == 3; - isRefractive = material.GetInt("_UseRefraction") == 1; isOutlined = shader.name.Contains("Outline"); isPatreonShader = shader.name.Contains("Patreon"); isEyeTracking = shader.name.Contains("EyeTracking"); @@ -225,12 +224,10 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro EditorGUI.BeginChangeCheck(); XSStyles.ShurikenHeaderCentered("XSToon v" + XSStyles.ver); - material.SetShaderPassEnabled("Always", isRefractive); materialEditor.ShaderProperty(_AdvMode, new GUIContent("Shader Mode", "Setting this to 'Advanced' will give you access to things such as stenciling, and other expiremental/advanced features.")); materialEditor.ShaderProperty(_Culling, new GUIContent("Culling Mode", "Changes the culling mode. 'Off' will result in a two sided material, while 'Front' and 'Back' will cull those sides respectively")); materialEditor.ShaderProperty(_TilingMode, new GUIContent("Tiling Mode", "Setting this to Merged will tile and offset all textures based on the Main texture's Tiling/Offset.")); materialEditor.ShaderProperty(_BlendMode, new GUIContent("Blend Mode", "Blend mode of the material. (Opaque, transparent, cutout, etc.)")); - materialEditor.ShaderProperty(_UseRefraction, new GUIContent("Refraction", "Should this material be refractive? (Warning, this can be expensive!)")); DoBlendModeSettings(material); DrawMainSettings(materialEditor, material); @@ -240,7 +237,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro DrawNormalSettings(materialEditor, material); DrawSpecularSettings(materialEditor, material); DrawReflectionsSettings(materialEditor, material); - DrawRefractionSettings(materialEditor, material); + // DrawAudioLinkSettings(materialEditor, material); DrawEmissionSettings(materialEditor, material); DrawRimlightSettings(materialEditor, material); DrawHalfToneSettings(materialEditor, material); @@ -337,8 +334,6 @@ private void SetBlend(Material material, int src, int dst, int renderQueue, int material.SetInt("_DstBlend", dst); material.SetInt("_ZWrite", zwrite); material.SetInt("_AlphaToMask", alphatocoverage); - - material.renderQueue = isRefractive ? (int)UnityEngine.Rendering.RenderQueue.Overlay - 1 : renderQueue; } private void DrawMainSettings(MaterialEditor materialEditor, Material material) @@ -579,10 +574,28 @@ private void DrawEmissionSettings(MaterialEditor materialEditor, Material materi Foldouts[material].ShowEmission = XSStyles.ShurikenFoldout("Emission", Foldouts[material].ShowEmission); if (Foldouts[material].ShowEmission) { - materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map", "Emissive map. White to black, unless you want multiple colors."), _EmissionMap, _EmissionColor); - materialEditor.TextureScaleOffsetProperty(_EmissionMap); - materialEditor.ShaderProperty(_UVSetEmission, new GUIContent("UV Set", "The UV set to use for the Emission Map"), 2); - materialEditor.ShaderProperty(_EmissionToDiffuse, new GUIContent("Tint To Diffuse", "Tints the emission to the Diffuse Color"), 2); + bool isAudioLink = material.GetInt("_EmissionAudioLinkChannel") > 0; + bool isPackedMapLink = material.GetInt("_EmissionAudioLinkChannel") == 5; + materialEditor.ShaderProperty(_EmissionAudioLinkChannel, new GUIContent("Emission Audio Link", "Use Audio Link for Emission Brightness")); + + if (!isPackedMapLink) + { + materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map", "Emissive map. White to black, unless you want multiple colors."), _EmissionMap, _EmissionColor); + materialEditor.TextureScaleOffsetProperty(_EmissionMap); + materialEditor.ShaderProperty(_UVSetEmission, new GUIContent("UV Set", "The UV set to use for the Emission Map"), 2); + materialEditor.ShaderProperty(_EmissionToDiffuse, new GUIContent("Tint To Diffuse", "Tints the emission to the Diffuse Color"), 2); + } + else + { + materialEditor.ColorProperty(_EmissionColor, "Red Ch. Color (Bass)"); + materialEditor.ColorProperty(_EmissionColor0, "Green Ch. Color (Mids)"); + materialEditor.ColorProperty(_EmissionColor1, "Blue Ch. Color (Highs)"); + + materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map", "Emissive map. White to black, unless you want multiple colors. Setting to Packed Map for Audio Link will change the color per channel."), _EmissionMap); + materialEditor.TextureScaleOffsetProperty(_EmissionMap); + materialEditor.ShaderProperty(_UVSetEmission, new GUIContent("UV Set", "The UV set to use for the Emission Map"), 2); + materialEditor.ShaderProperty(_EmissionToDiffuse, new GUIContent("Tint To Diffuse", "Tints the emission to the Diffuse Color"), 2); + } XSStyles.SeparatorThin(); materialEditor.ShaderProperty(_ScaleWithLight, new GUIContent("Scale w/ Light", "Scales the emission intensity based on how dark or bright the environment is.")); @@ -643,18 +656,15 @@ private void DrawTransmissionSettings(MaterialEditor materialEditor, Material ma } } - private void DrawRefractionSettings(MaterialEditor materialEditor, Material material) - { - if (isRefractive) - { - Foldouts[material].ShowRefraction = XSStyles.ShurikenFoldout("Refraction", Foldouts[material].ShowRefraction); - if (Foldouts[material].ShowRefraction) - { - materialEditor.ShaderProperty(_RefractionModel, new GUIContent("Refraction Model", "Refraction technique")); - materialEditor.ShaderProperty(_IOR, new GUIContent("Index of Refraction", "The index of refraction of the material. Glass: 1.5, Crystal: 2.0, Ice: 1.309, Water: 1.325")); - } - } - } + // private void DrawAudioLinkSettings(MaterialEditor materialEditor, Material material) + // { + // Foldouts[material].ShowAudioLink = XSStyles.ShurikenFoldout("Audio Link", Foldouts[material].ShowAudioLink); + // if (Foldouts[material].ShowAudioLink) + // { + // materialEditor.ShaderProperty(_EmissionAudioLinkChannel, new GUIContent("Emission Audio Link", "Use Audio Link for Emission Brightness")); + // // materialEditor.ShaderProperty(_IOR, new GUIContent("Index of Refraction", "The index of refraction of the material. Glass: 1.5, Crystal: 2.0, Ice: 1.309, Water: 1.325")); + // } + // } private void DrawAdvancedSettings(MaterialEditor materialEditor, Material material) { @@ -677,14 +687,14 @@ private void DrawAdvancedSettings(MaterialEditor materialEditor, Material materi int materialClipIndex = material.GetInt("_ClipIndex"); switch (materialClipIndex) { - case 0: DrawVectorSliders(material, _ClipSlider00, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider01, "Cyan", "Yellow", "Magenta", "Black"); break; - case 1: DrawVectorSliders(material, _ClipSlider02, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider03, "Cyan", "Yellow", "Magenta", "Black"); break; - case 2: DrawVectorSliders(material, _ClipSlider04, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider05, "Cyan", "Yellow", "Magenta", "Black"); break; - case 3: DrawVectorSliders(material, _ClipSlider06, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider07, "Cyan", "Yellow", "Magenta", "Black"); break; - case 4: DrawVectorSliders(material, _ClipSlider08, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider09, "Cyan", "Yellow", "Magenta", "Black"); break; - case 5: DrawVectorSliders(material, _ClipSlider10, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider11, "Cyan", "Yellow", "Magenta", "Black"); break; - case 6: DrawVectorSliders(material, _ClipSlider12, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider13, "Cyan", "Yellow", "Magenta", "Black"); break; - case 7: DrawVectorSliders(material, _ClipSlider14, "Red", "Green", "Blue", "White"); DrawVectorSliders(material, _ClipSlider15, "Cyan", "Yellow", "Magenta", "Black"); break; + case 0: DrawVectorSliders(materialEditor, material, _ClipSlider00, "Red", "Green", "Blue", "White"); DrawVectorSliders(materialEditor, material, _ClipSlider01, "Cyan", "Yellow", "Magenta", "Black"); break; + case 1: DrawVectorSliders(materialEditor, material, _ClipSlider02, "Red", "Green", "Blue", "White"); DrawVectorSliders(materialEditor, material, _ClipSlider03, "Cyan", "Yellow", "Magenta", "Black"); break; + case 2: DrawVectorSliders(materialEditor, material, _ClipSlider04, "Red", "Green", "Blue", "White"); DrawVectorSliders(materialEditor, material, _ClipSlider05, "Cyan", "Yellow", "Magenta", "Black"); break; + case 3: DrawVectorSliders(materialEditor, material, _ClipSlider06, "Red", "Green", "Blue", "White"); DrawVectorSliders(materialEditor, material, _ClipSlider07, "Cyan", "Yellow", "Magenta", "Black"); break; + case 4: DrawVectorSliders(materialEditor, material, _ClipSlider08, "Red", "Green", "Blue", "White"); DrawVectorSliders(materialEditor, material, _ClipSlider09, "Cyan", "Yellow", "Magenta", "Black"); break; + case 5: DrawVectorSliders(materialEditor, material, _ClipSlider10, "Red", "Green", "Blue", "White"); DrawVectorSliders(materialEditor, material, _ClipSlider11, "Cyan", "Yellow", "Magenta", "Black"); break; + case 6: DrawVectorSliders(materialEditor, material, _ClipSlider12, "Red", "Green", "Blue", "White"); DrawVectorSliders(materialEditor, material, _ClipSlider13, "Cyan", "Yellow", "Magenta", "Black"); break; + case 7: DrawVectorSliders(materialEditor, material, _ClipSlider14, "Red", "Green", "Blue", "White"); DrawVectorSliders(materialEditor, material, _ClipSlider15, "Cyan", "Yellow", "Magenta", "Black"); break; } } @@ -735,11 +745,12 @@ private void DrawPatreonSettings(MaterialEditor materialEditor, Material materia //!RDPSFunctionInject - private void DrawVectorSliders(Material material, MaterialProperty property, string nameR, string nameG, string nameB, string nameA) + private void DrawVectorSliders(MaterialEditor materialEditor, Material material, MaterialProperty property, string nameR, string nameG, string nameB, string nameA) { EditorGUI.BeginChangeCheck(); Vector4 prop = property.vectorValue; EditorGUI.indentLevel += 1; + // materialEditor.ShaderProperty(property, new GUIContent($"{nameR}|{nameG}|{nameB}|{nameA}", "")); prop.x = EditorGUILayout.Slider(new GUIContent(nameR, "Clip on mask channel R"), prop.x, 0, 1); prop.y = EditorGUILayout.Slider(new GUIContent(nameG, "Clip on mask channel G"), prop.y, 0, 1); prop.z = EditorGUILayout.Slider(new GUIContent(nameB, "Clip on mask channel B"), prop.z, 0, 1); diff --git a/Main/CGIncludes/AudioLink.cginc b/Main/CGIncludes/AudioLink.cginc new file mode 100644 index 0000000..dee8aff --- /dev/null +++ b/Main/CGIncludes/AudioLink.cginc @@ -0,0 +1,321 @@ +// Map of where features in AudioLink are. +#define ALPASS_DFT int2(0,4) +#define ALPASS_WAVEFORM int2(0,6) +#define ALPASS_AUDIOLINK int2(0,0) +#define ALPASS_AUDIOLINKHISTORY int2(1,0) +#define ALPASS_GENERALVU int2(0,22) +#define ALPASS_AUDIOLINK_BASS int2(0,0) +#define ALPASS_AUDIOLINK_LOWMID int2(32,0) +#define ALPASS_AUDIOLINK_HIMID int2(64,0) +#define ALPASS_AUDIOLINK_TREBLE int2(96,0) + +#define ALPASS_GENERALVU_INSTANCE_TIME int2(2,22) +#define ALPASS_GENERALVU_LOCAL_TIME int2(3,22) + +#define ALPASS_CCINTERNAL int2(12,22) +#define ALPASS_CCSTRIP int2(0,24) +#define ALPASS_CCLIGHTS int2(0,25) +#define ALPASS_AUTOCORRELATOR int2(0,27) + +// Some basic constants to use (Note, these should be compatible with +// future version of AudioLink, but may change. +#define CCMAXNOTES 10 +#define SAMPHIST 3069 //Internal use for algos, do not change. +#define SAMPLEDATA24 2046 +#define EXPBINS 24 +#define EXPOCT 10 +#define ETOTALBINS ((EXPBINS)*(EXPOCT)) +#define AUDIOLINK_WIDTH 128 +#define _SamplesPerSecond 48000 +#define _RootNote 0 + +// We use glsl_mod for most calculations because it behaves better +// on negative numbers, and in some situations actually outperforms +// HLSL's modf(). +#ifndef glsl_mod +#define glsl_mod(x,y) (((x)-(y)*floor((x)/(y)))) +#endif + +uniform float4 _AudioTexture_TexelSize; + +#ifdef SHADER_TARGET_SURFACE_ANALYSIS +#define AUDIOLINK_STANDARD_INDEXING +#endif + +// Mechanism to index into texture. +#ifdef AUDIOLINK_STANDARD_INDEXING + sampler2D _AudioTexture; + #define AudioLinkData(xycoord) tex2Dlod( _AudioTexture, float4( uint2(xycoord) * _AudioTexture_TexelSize.xy, 0, 0 ) ) +#else + uniform Texture2D _AudioTexture; + #define AudioLinkData(xycoord) _AudioTexture[uint2(xycoord)] +#endif + +// Convenient mechanism to read from the AudioLink texture that handles reading off the end of one line and onto the next above it. +float4 AudioLinkDataMultiline( uint2 xycoord) { return AudioLinkData(uint2(xycoord.x % AUDIOLINK_WIDTH, xycoord.y + xycoord.x/AUDIOLINK_WIDTH)); } + +// Mechanism to sample between two adjacent pixels and lerp between them, like "linear" supesampling +float4 AudioLinkLerp(float2 xy) { return lerp( AudioLinkData(xy), AudioLinkData(xy+int2(1,0)), frac( xy.x ) ); } + +// Same as AudioLinkLerp but properly handles multiline reading. +float4 AudioLinkLerpMultiline(float2 xy) { return lerp( AudioLinkDataMultiline(xy), AudioLinkDataMultiline(xy+float2(1,0)), frac( xy.x ) ); } + +// Decompress a RGBA FP16 into a really big number, this is used in some sections of the info block. +#define DecodeLongFloat( vALValue ) (vALValue.r + vALValue.g*1024 + vALValue.b * 1048576 + vALValue.a * 1073741824 ) + + +// Extra utility functions for time. +uint ALDecodeDataAsUInt( uint2 sample ) +{ + half4 rpx = AudioLinkData( sample ); + return DecodeLongFloat( rpx ); +} + + +//Note: This will truncate time to every 134,217.728 seconds (~1.5 days of an instance being up) to prevent floating point aliasing. +// if your code will alias sooner, you will need to use a different function. +float ALDecodeDataAsFloat( uint2 sample ) +{ + return (ALDecodeDataAsUInt( sample ) & 0x7ffffff) / 1000.; +} + + + +// ColorChord features + +#ifndef CCclamp +#define CCclamp(x,y,z) clamp( x, y, z ) +#endif + +float CCRemap(float t, float a, float b, float u, float v) {return ( (t-a) / (b-a) ) * (v-u) + u;} + +float3 CCHSVtoRGB(float3 HSV) +{ + float3 RGB = 0; + float C = HSV.z * HSV.y; + float H = HSV.x * 6; + float X = C * (1 - abs(fmod(H, 2) - 1)); + if (HSV.y != 0) + { + float I = floor(H); + if (I == 0) { RGB = float3(C, X, 0); } + else if (I == 1) { RGB = float3(X, C, 0); } + else if (I == 2) { RGB = float3(0, C, X); } + else if (I == 3) { RGB = float3(0, X, C); } + else if (I == 4) { RGB = float3(X, 0, C); } + else { RGB = float3(C, 0, X); } + } + float M = HSV.z - C; + return RGB + M; +} + +float3 CCtoRGB( float bin, float intensity, int RootNote ) +{ + float note = bin / EXPBINS; + + float hue = 0.0; + note *= 12.0; + note = glsl_mod( 4.-note + RootNote, 12.0 ); + { + if( note < 4.0 ) + { + //Needs to be YELLOW->RED + hue = (note) / 24.0; + } + else if( note < 8.0 ) + { + // [4] [8] + //Needs to be RED->BLUE + hue = ( note-2.0 ) / 12.0; + } + else + { + // [8] [12] + //Needs to be BLUE->YELLOW + hue = ( note - 4.0 ) / 8.0; + } + } + float val = intensity-.1; + return CCHSVtoRGB( float3( fmod(hue,1.0), 1.0, CCclamp( val, 0.0, 1.0 ) ) ); +} + + + + + + + +//////////////////////////////////////////////////////////////////// +// General debug functions below here + + + + +// Shockingly, including the ability to render text doesn't +// slow down number printing if text isn't used. +// A basic versino of the debug screen without text was only 134 +// instructions. + +float PrintChar( uint selchar, float2 mxy ) +{ + const static uint BitmapNumberFont[40] = { + 15379168, // '0' 1110 1010 1010 1010 1110 0000 + 4473920, // '1' 0100 0100 0100 0100 0100 0000 + 14870752, // '2' 1110 0010 1110 1000 1110 0000 + 14836448, // '3' 1110 0010 0110 0010 1110 0000 + 11199008, // '4' 1010 1010 1110 0010 0010 0000 + 15262432, // '5' 1110 1000 1110 0010 1110 0000 + 15264480, // '6' 1110 1000 1110 1010 1110 0000 + 14836800, // '7' 1110 0010 0110 0100 0100 0000 + 15395552, // '8' 1110 1010 1110 1010 1110 0000 + 15393376, // '9' 1110 1010 1110 0010 0110 0000 + 64, // '.' 0000 0000 0000 0000 0100 0000 + 57344, // '-' 0000 0000 1110 0000 0000 0000 + 0, // ' ' + 15395488, // 'A' 1110 1010 1110 1010 1010 0000 + 15395552, // 'B' 1110 1010 1110 1010 1110 0000 + 15239392, // 'C' 1110 1000 1000 1000 1110 0000 + 15379168, // 'D' 1110 1010 1010 1010 1110 0000 + 15255776, // 'E' 1110 1000 1100 1000 1110 0000 + 15255680, // 'F' 1110 1000 1100 1000 1000 0000 + 15264480, // 'G' 1110 1000 1110 1010 1110 0000 + 11201184, // 'H' 1010 1010 1110 1010 1010 0000 + 14959840, // 'I' 1110 0100 0100 0100 1110 0000 + 14823136, // 'J' 1110 0010 0010 1110 1110 0000 + 11201184, // 'K' 1010 1010 1110 1010 1010 0000 + 8947936 , // 'L' 1000 1000 1000 1000 1110 0000 + 11446944, // 'M' 1010 1110 1010 1010 1010 0000 + 9349792 , // 'N' 1000 1110 1010 1010 1010 0000 + 15379168, // 'O' 1110 1010 1010 1010 1110 0000 + 15394944, // 'P' 1110 1010 1110 1000 1000 0000 + 15380192, // 'Q' 1110 1010 1010 1110 1110 0000 + 15395488, // 'R' 1110 1010 1110 1010 1010 0000 + 15262432, // 'S' 1110 1000 1110 0010 1110 0000 + 14959680, // 'T' 1110 0100 0100 0100 0100 0000 + 11184864, // 'U' 1010 1010 1010 1010 1110 0000 + 11184704, // 'V' 1010 1010 1010 1010 0100 0000 + 11464256, // 'W' 1010 1010 1110 1110 0100 0000 + 11160224, // 'X' 1010 1010 0100 1010 1010 0000 + 11199552, // 'Y' 1010 1010 1110 0100 0100 0000 + 14829792, // 'Z' 1110 0010 0100 1000 1110 0000 + 658144, // ':)'0000 1010 0000 1010 1110 0000 + }; + const static uint BitmapNumberFontPartial[40] = { + 15379168, // '0' 1110 1010 1010 1010 1110 0000 + 4473920, // '1' 0100 0100 0100 0100 0100 0000 + 14870752, // '2' 1110 0010 1110 1000 1110 0000 + 14836448, // '3' 1110 0010 0110 0010 1110 0000 + 11199008, // '4' 1010 1010 1110 0010 0010 0000 + 15262432, // '5' 1110 1000 1110 0010 1110 0000 + 15264480, // '6' 1110 1000 1110 1010 1110 0000 + 14836800, // '7' 1110 0010 0110 0100 0100 0000 + 15395552, // '8' 1110 1010 1110 1010 1110 0000 + 15393376, // '9' 1110 1010 1110 0010 0110 0000 + 64, // '.' 0000 0000 0000 0000 0100 0000 + 57344, // '-' 0000 0000 1110 0000 0000 0000 + 0, // ' ' + 15395488, // 'A' 1110 1010 1110 1010 1010 0000 + 13298368, // 'B' 1100 1010 1110 1010 1100 0000 + 15239392, // 'C' 1110 1000 1000 1000 1110 0000 + 13281984, // 'D' 1100 1010 1010 1010 1100 0000 + 15255776, // 'E' 1110 1000 1100 1000 1110 0000 + 15255680, // 'F' 1110 1000 1100 1000 1000 0000 + 15248096, // 'G' 1110 1000 1010 1010 1110 0000 + 11201184, // 'H' 1010 1010 1110 1010 1010 0000 + 14959840, // 'I' 1110 0100 0100 0100 0100 0000 + 14822080, // 'J' 1110 0010 0010 1010 1100 0000 + 11192992, // 'K' 1010 1010 1100 1010 1010 0000 + 8947936 , // 'L' 1000 1000 1000 1000 1110 0000 + 11446944, // 'M' 1010 1110 1010 1010 1010 0000 + 9218720 , // 'N' 1000 1100 1010 1010 1010 0000 + 15379168, // 'O' 1110 1010 1010 1010 1110 0000 + 15394944, // 'P' 1110 1010 1110 1000 1000 0000 + 15379040, // 'Q' 1110 1010 1010 1010 0110 0000 + 15387296, // 'R' 1110 1010 1100 1010 1010 0000 + 15262432, // 'S' 1110 1000 1110 0010 1110 0000 + 14959680, // 'T' 1110 0100 0100 0100 0100 0000 + 11184864, // 'U' 1010 1010 1010 1010 1110 0000 + 11185728, // 'V' 1010 1010 1010 1110 0100 0000 + 11464256, // 'W' 1010 1010 1110 1110 0100 0000 + 11160224, // 'X' 1010 1010 0100 1010 1010 0000 + 11199552, // 'Y' 1010 1010 1110 0100 0100 0000 + 14829792, // 'Z' 1110 0010 0100 1000 1110 0000 + 657984, // ':)'0000 1010 0000 1010 0100 0000 + }; + + uint bitmap = BitmapNumberFont[selchar]; + uint bitmappartial = BitmapNumberFontPartial[selchar]; + if( 0 ) + { + // Ugly, line-drawing + int2 lumx = mxy; + return ((bitmap >> (lumx.x+lumx.y*4)) & 1)?1.0:0.0; + } + else + { + // Smooth style drawing. + int2 lumx = mxy; + int index = lumx.x + lumx.y * 4; + int4 tolerp = (int4( + ((bitmap >> (index + 0))), + ((bitmap >> (index + 1))), + ((bitmap >> (index + 4))), + ((bitmap >> (index + 5))) ) & 1) + + + (int4( + ((bitmappartial >> (index + 0))), + ((bitmappartial >> (index + 1))), + ((bitmappartial >> (index + 4))), + ((bitmappartial >> (index + 5))) ) & 1) + ; + float2 shift = smoothstep( 0, 1, frac(mxy) ); + float ov = lerp( + lerp( tolerp.x, tolerp.y, shift.x ), + lerp( tolerp.z, tolerp.w, shift.x ), shift.y ) / 2.; + return saturate( ov * 20 - 10 ); + } +} + + +// Used for debugging +float PrintNumberOnLine( float number, uint fixeddiv, uint digit, float2 mxy, int offset, bool leadzero ) +{ + uint selnum; + if( number < 0 && digit == 0 ) + { + selnum = 11; + } + else + { + number = abs( number ); + + if( digit == fixeddiv ) + { + selnum = 10; + } + else + { + int dmfd = (int)digit - (int)fixeddiv; + if( dmfd > 0 ) + { + //fractional part. + float l10 = pow( 10., dmfd ); + selnum = ((uint)( number * l10 )) % 10; + } + else + { + float l10 = pow( 10., (float)(dmfd + 1) ); + selnum = ((uint)( number * l10 )); + + //Disable leading 0's? + if( !leadzero && dmfd != -1 && selnum == 0 && dmfd < 0.5 ) + selnum = 12; + else + selnum %= (uint)10; + } + } + } + + return PrintChar( selnum, mxy ); +} + diff --git a/Main/CGIncludes/AudioLink.cginc.meta b/Main/CGIncludes/AudioLink.cginc.meta new file mode 100644 index 0000000..eb2594b --- /dev/null +++ b/Main/CGIncludes/AudioLink.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 18778b93ee6cc214a9c69d45e3fc4c91 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/CGIncludes/XSDefines.cginc b/Main/CGIncludes/XSDefines.cginc index 6b3a826..687b90b 100644 --- a/Main/CGIncludes/XSDefines.cginc +++ b/Main/CGIncludes/XSDefines.cginc @@ -112,7 +112,6 @@ struct XSLighting half3 bitangent; half4 worldPos; half3 color; - half alpha; float isOutline; float4 screenPos; float2 screenUV; @@ -136,6 +135,7 @@ struct TextureUV half2 outlineMaskUV; half2 clipMapUV; half2 dissolveUV; + half2 audioLinkUV; }; struct DotProducts @@ -177,8 +177,6 @@ sampler2D _ClipMask; sampler2D _Matcap; sampler2D _Ramp; samplerCUBE _BakedCubemap; -sampler2D _GrabTexture; -float4 _GrabTexture_TexelSize; #if defined(UNITY_PASS_SHADOWCASTER) sampler3D _DitherMaskLOD; @@ -191,10 +189,9 @@ half _DissolveProgress, _DissolveStrength; int _DissolveCoordinates; int _UseClipsForDissolve; -half4 _ShadowRim, - _OutlineColor, _SSColor, - _EmissionColor, _MatcapTint, - _RimColor, _DissolveColor; +half4 _ShadowRim, _OutlineColor, _SSColor, + _EmissionColor, _EmissionColor0, _EmissionColor1, + _MatcapTint, _RimColor, _DissolveColor; half _MatcapTintToDiffuse; @@ -213,16 +210,16 @@ half _OutlineWidth; half _DissolveBlendPower, _DissolveLayer1Scale, _DissolveLayer2Scale, _DissolveLayer1Speed, _DissolveLayer2Speed; half4 _ClipSlider00,_ClipSlider01,_ClipSlider02,_ClipSlider03, - _ClipSlider04,_ClipSlider05,_ClipSlider06,_ClipSlider07, - _ClipSlider08,_ClipSlider09,_ClipSlider10,_ClipSlider11, - _ClipSlider12,_ClipSlider13,_ClipSlider14,_ClipSlider15; + _ClipSlider04,_ClipSlider05,_ClipSlider06,_ClipSlider07, + _ClipSlider08,_ClipSlider09,_ClipSlider10,_ClipSlider11, + _ClipSlider12,_ClipSlider13,_ClipSlider14,_ClipSlider15; int _ClipIndex; int _HalftoneType; int _FadeDither; int _BlendMode; int _OcclusionMode; -int _UseRefraction; +int _EmissionAudioLink, _EmissionAudioLinkChannel; int _ReflectionMode, _ReflectionBlendMode, _ClearCoat; int _TilingMode, _VertexColorAlbedo, _ScaleWithLight; int _OutlineAlbedoTint, _OutlineLighting, _OutlineNormalMode; diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index e8bde0b..9cebc2c 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -61,7 +61,7 @@ float4 frag ( o.thickness = UNITY_SAMPLE_TEX2D_SAMPLER(_ThicknessMap, _MainTex, t.thicknessMapUV); o.occlusion = tex2D(_OcclusionMap, t.occlusionUV); o.reflectivityMask = UNITY_SAMPLE_TEX2D_SAMPLER(_ReflectivityMask, _MainTex, t.reflectivityMaskUV) * _Reflectivity; - o.emissionMap = UNITY_SAMPLE_TEX2D_SAMPLER(_EmissionMap, _MainTex, t.emissionMapUV) * _EmissionColor; + o.emissionMap = UNITY_SAMPLE_TEX2D_SAMPLER(_EmissionMap, _MainTex, t.emissionMapUV); o.rampMask = UNITY_SAMPLE_TEX2D_SAMPLER(_RampSelectionMask, _MainTex, i.uv); // This texture doesn't need to ever be on a second uv channel, and doesn't need tiling, convince me otherwise. o.hsvMask = UNITY_SAMPLE_TEX2D_SAMPLER(_HSVMask, _MainTex, t.albedoUV); o.clipMap = tex2Dlod(_ClipMask, float4(t.clipMapUV, 0, 0)); @@ -80,7 +80,7 @@ float4 frag ( o.screenPos = i.screenPos; o.objPos = i.objPos; - float4 col = BRDF_XSLighting(o); + float4 col = BRDF_XSLighting(o,t); float alpha = o.albedo.a; calcAlpha(o, alpha); calcDissolve(o, col.rgb); diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 8ff5e16..74dbd17 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -381,7 +381,6 @@ void calcAlpha(inout XSLighting i, inout float alpha) float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); half dither = calcDither(i.screenUV.xy); alpha = modifiedAlpha - (dither * (1-i.albedo.a) * 0.15); - #if defined(UNITY_PASS_SHADOWCASTER) clip(modifiedAlpha - dither); #endif diff --git a/Main/CGIncludes/XSLighting.cginc b/Main/CGIncludes/XSLighting.cginc index fead4f8..d7c92d7 100644 --- a/Main/CGIncludes/XSLighting.cginc +++ b/Main/CGIncludes/XSLighting.cginc @@ -1,4 +1,4 @@ -half4 BRDF_XSLighting(XSLighting i) +half4 BRDF_XSLighting(XSLighting i, TextureUV t) { float3 untouchedNormal = i.normal; i.tangent = normalize(i.tangent); @@ -91,28 +91,14 @@ half4 BRDF_XSLighting(XSLighting i) indirectSpecular *= lerp(0.5, 1, stipplingIndirect); // Don't want these to go completely black, looks weird } - #if defined(_COLOROVERLAY_ON) - float refractFresnel = 1-d.vdn; - float distanceToPixel = distance(_WorldSpaceCameraPos, i.worldPos); - float distanceScalar = saturate(1 / distanceToPixel) * saturate(distanceToPixel); - float3 refractDir = refract(viewDir, i.normal, max(0, _IOR - 1) * 0.03 * distanceScalar * refractFresnel); - float3x3 worldToTangentMatrix = float3x3(i.tangent, i.bitangent, i.normal); - refractDir = mul(worldToTangentMatrix, refractDir); - float4 backgroundColor = tex2Dproj(_GrabTexture, float4(i.screenPos.xyz + refractDir, i.screenPos.w)); - #endif - - half4 col; - #if !defined(_COLOROVERLAY_ON) - col = diffuse * shadowRim; - #else - col = backgroundColor * diffuse * shadowRim; - #endif + half4 col = diffuse * shadowRim; calcReflectionBlending(i, col, indirectSpecular.xyzz); col += max(directSpecular.xyzz, rimLight); col.rgb += max(vertexLightSpec.rgb, rimLight); col += subsurface; calcClearcoat(col, i, d, untouchedNormal, indirectDiffuse, lightCol, viewDir, lightDir, ramp); - col += calcEmission(i, lightAvg); + col += calcEmission(i, d, lightAvg); float4 finalColor = lerp(col, outlineColor, i.isOutline) * lerp(1, lineHalftone, _HalftoneLineIntensity * usingLineHalftone); + return finalColor; -} \ No newline at end of file +} diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index f28f6f2..49fb889 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -377,10 +377,42 @@ half4 calcSubsurfaceScattering(XSLighting i, DotProducts d, half3 lightDir, half } } -half4 calcEmission(XSLighting i, half lightAvg) +half4 calcEmission(XSLighting i, DotProducts d, half lightAvg) { #if defined(UNITY_PASS_FORWARDBASE) // Emission only in Base Pass, and vertex lights - float4 emission = lerp(i.emissionMap, i.emissionMap * i.diffuseColor.xyzz, _EmissionToDiffuse); + float4 emission = 0; + if(_EmissionAudioLinkChannel == 0) + { + emission = lerp(i.emissionMap, i.emissionMap * i.diffuseColor.xyzz, _EmissionToDiffuse) * _EmissionColor; + } + else + { + int width, height; + _AudioTexture.GetDimensions(width, height); + bool hasAudioLink = width > 16; + if(hasAudioLink) + { + if(_EmissionAudioLinkChannel != 5) + { + int2 aluv = int2(0, (_EmissionAudioLinkChannel-1)); + float alink = lerp(1, AudioLinkData(aluv).x , saturate(_EmissionAudioLinkChannel)); + emission = lerp(i.emissionMap, i.emissionMap * i.diffuseColor.xyzz, _EmissionToDiffuse) * _EmissionColor * alink; + } + else + { + + float audioDataBass = AudioLinkData(int2(0,0)).x; + float audioDataMids = (AudioLinkData(int2(0,1)).x + AudioLinkData(int2(0,2)).x) / 2; + float audioDataHighs = AudioLinkData(int2(0,3)).x; + + float4 emissionChannelRed = i.emissionMap.r * _EmissionColor * audioDataBass; + float4 emissionChannelGreen = i.emissionMap.g * _EmissionColor0 * audioDataMids; + float4 emissionChannelBlue = i.emissionMap.b * _EmissionColor1 * audioDataHighs; + emission = (emissionChannelRed + emissionChannelGreen + emissionChannelBlue) * lerp(1, i.diffuseColor.rgbb, _EmissionToDiffuse); + } + } + } + float4 scaledEmission = emission * saturate(smoothstep(1-_ScaleWithLightSensitivity, 1+_ScaleWithLightSensitivity, 1-lightAvg)); float4 em = lerp(scaledEmission, emission, _ScaleWithLight); diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon2.0.shader index 3e9c97f..a8c8443 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon2.0.shader @@ -6,8 +6,7 @@ [Enum(Separated, 0, Merged, 1)] _TilingMode ("Tiling Mode", Int) = 0 [Enum(Off,0,Front,1,Back,2)] _Culling ("Culling Mode", Int) = 2 [Enum(Opaque, 0, Cutout, 1, Dithered, 2, Alpha To Coverage, 3, Transparent, 4, Fade, 5, Additive, 6)]_BlendMode("Blend Mode", Int) = 0 - [Enum(None, 0, Plane, 1, Sphere, 2)]_RefractionModel("Refraction Model", Int) = 0 - [Toggle(_COLOROVERLAY_ON)]_UseRefraction("Refraction", Int) = 0 + _MainTex("Texture", 2D) = "white" {} _HSVMask("HSV Mask", 2D) = "white" {} _Hue("Hue", Range(0,1)) = 0 @@ -46,7 +45,6 @@ [Enum(Yes,0, No,1)] _ScaleWithLight("Emission Scale w/ Light", Int) = 1 _EmissionMap("Emission Map", 2D) = "white" {} - [HDR]_EmissionColor("Emission Color", Color) = (0,0,0,0) _EmissionToDiffuse("Emission Tint To Diffuse", Range(0,1)) = 0 _ScaleWithLightSensitivity("Scaling Sensitivity", Range(0,1)) = 1 @@ -129,6 +127,11 @@ [Enum(UV1,0,UV2,1)] _UVSetClipMap("Clip Map UVs", Int) = 0 [Enum(UV1,0,UV2,1)] _UVSetDissolve("Dissolve Map UVs", Int) = 0 + [Enum(None,0,Bass,1,Low Mids,2,High Mids,3,Treble,4,Packed Map,5)]_EmissionAudioLinkChannel("Emisssion Audio Link Channel", int) = 0 + [HDR]_EmissionColor("Emission Color", Color) = (0,0,0,0) + [HDR]_EmissionColor0("Emission Packed Color 1", Color) = (0,0,0,0) + [HDR]_EmissionColor1("Emission Packed Color 2", Color) = (0,0,0,0) + _ClipMap("Clip Map", 2D) = "black" {} _WireColor("Wire Color", Color) = (0,0,0,0) _WireWidth("Wire Width", Float) = 0 @@ -175,11 +178,11 @@ Comp [_StencilComp] Pass [_StencilOp] } - Grabpass // Gets disabled via the editor script when not in use through the Lightmode Tag. - { - Tags{"LightMode" = "Always"} - "_GrabTexture" - } +// Grabpass // Gets disabled via the editor script when not in use through the Lightmode Tag. +// { +// Tags{"LightMode" = "Always"} +// "_AudioTexture" +// } Pass { Name "FORWARD" @@ -194,7 +197,6 @@ #pragma shader_feature _ALPHABLEND_ON #pragma shader_feature _ALPHATEST_ON #pragma multi_compile _ VERTEXLIGHT_ON - #pragma shader_feature _COLOROVERLAY_ON #pragma multi_compile_fog #pragma multi_compile_fwdbase #pragma multi_compile_instancing @@ -203,6 +205,7 @@ #define UNITY_PASS_FORWARDBASE #endif + #include "../CGIncludes/AudioLink.cginc" #include "../CGIncludes/XSDefines.cginc" #include "../CGIncludes/XSHelperFunctions.cginc" #include "../CGIncludes/XSLightingFunctions.cginc" @@ -227,13 +230,13 @@ #pragma fragment frag #pragma shader_feature _ALPHABLEND_ON #pragma shader_feature _ALPHATEST_ON - #pragma shader_feature _COLOROVERLAY_ON #pragma multi_compile_fog #pragma multi_compile_fwdadd_fullshadows #ifndef UNITY_PASS_FORWARDADD #define UNITY_PASS_FORWARDADD #endif + #include "../CGIncludes/AudioLink.cginc" #include "../CGIncludes/XSDefines.cginc" #include "../CGIncludes/XSHelperFunctions.cginc" #include "../CGIncludes/XSLightingFunctions.cginc" @@ -255,7 +258,6 @@ #pragma fragment frag #pragma shader_feature _ALPHABLEND_ON #pragma shader_feature _ALPHATEST_ON - #pragma shader_feature _COLOROVERLAY_ON #pragma multi_compile_shadowcaster #pragma multi_compile_instancing #ifndef UNITY_PASS_SHADOWCASTER @@ -263,6 +265,7 @@ #endif #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2 + #include "../CGIncludes/AudioLink.cginc" #include "../CGIncludes/XSDefines.cginc" #include "../CGIncludes/XSHelperFunctions.cginc" #include "../CGIncludes/XSLightingFunctions.cginc" diff --git a/Main/Shaders/XSToon2.0_Outlined.shader b/Main/Shaders/XSToon2.0_Outlined.shader index 4e394f5..b843ff5 100644 --- a/Main/Shaders/XSToon2.0_Outlined.shader +++ b/Main/Shaders/XSToon2.0_Outlined.shader @@ -6,8 +6,7 @@ [Enum(Separated, 0, Merged, 1)] _TilingMode ("Tiling Mode", Int) = 0 [Enum(Off,0,Front,1,Back,2)] _Culling ("Culling Mode", Int) = 2 [Enum(Opaque, 0, Cutout, 1, Dithered, 2, Alpha To Coverage, 3, Transparent, 4, Fade, 5, Additive, 6)]_BlendMode("Blend Mode", Int) = 0 - [Enum(None, 0, Plane, 1, Sphere, 2)]_RefractionModel("Refraction Model", Int) = 0 - [Toggle(_COLOROVERLAY_ON)]_UseRefraction("Refraction", Int) = 0 + _MainTex("Texture", 2D) = "white" {} _HSVMask("HSV Mask", 2D) = "white" {} _Hue("Hue", Range(0,1)) = 0 @@ -129,6 +128,11 @@ [Enum(UV1,0,UV2,1)] _UVSetClipMap("Clip Map UVs", Int) = 0 [Enum(UV1,0,UV2,1)] _UVSetDissolve("Dissolve Map UVs", Int) = 0 + [Enum(None,0,Bass,1,Low Mids,2,High Mids,3,Treble,4,Packed Map,5)]_EmissionAudioLinkChannel("Emisssion Audio Link Channel", int) = 0 + [HDR]_EmissionColor("Emission Color", Color) = (0,0,0,0) + [HDR]_EmissionColor0("Emission Packed Color 1", Color) = (0,0,0,0) + [HDR]_EmissionColor1("Emission Packed Color 2", Color) = (0,0,0,0) + _ClipMap("Clip Map", 2D) = "black" {} _WireColor("Wire Color", Color) = (0,0,0,0) _WireWidth("Wire Width", Float) = 0 @@ -175,11 +179,11 @@ Comp [_StencilComp] Pass [_StencilOp] } - Grabpass // Gets disabled via the editor script when not in use through the Lightmode Tag. - { - Tags{"LightMode" = "Always"} - "_GrabTexture" - } +// Grabpass // Gets disabled via the editor script when not in use through the Lightmode Tag. +// { +// Tags{"LightMode" = "Always"} +// "_AudioTexture" +// } Pass { Name "FORWARD" @@ -196,7 +200,6 @@ #pragma shader_feature _ALPHABLEND_ON #pragma shader_feature _ALPHATEST_ON #pragma multi_compile _ VERTEXLIGHT_ON - #pragma shader_feature _COLOROVERLAY_ON #pragma multi_compile_fog #pragma multi_compile_fwdbase #pragma multi_compile_instancing @@ -205,6 +208,7 @@ #define UNITY_PASS_FORWARDBASE #endif + #include "../CGIncludes/AudioLink.cginc" #include "../CGIncludes/XSDefines.cginc" #include "../CGIncludes/XSHelperFunctions.cginc" #include "../CGIncludes/XSLightingFunctions.cginc" @@ -232,13 +236,13 @@ #pragma fragment frag #pragma shader_feature _ALPHABLEND_ON #pragma shader_feature _ALPHATEST_ON - #pragma shader_feature _COLOROVERLAY_ON #pragma multi_compile_fog #pragma multi_compile_fwdadd_fullshadows #ifndef UNITY_PASS_FORWARDADD #define UNITY_PASS_FORWARDADD #endif + #include "../CGIncludes/AudioLink.cginc" #include "../CGIncludes/XSDefines.cginc" #include "../CGIncludes/XSHelperFunctions.cginc" #include "../CGIncludes/XSLightingFunctions.cginc" @@ -263,7 +267,6 @@ #pragma fragment frag #pragma shader_feature _ALPHABLEND_ON #pragma shader_feature _ALPHATEST_ON - #pragma shader_feature _COLOROVERLAY_ON #pragma multi_compile_shadowcaster #pragma multi_compile_instancing #ifndef UNITY_PASS_SHADOWCASTER @@ -271,6 +274,7 @@ #endif #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2 + #include "../CGIncludes/AudioLink.cginc" #include "../CGIncludes/XSDefines.cginc" #include "../CGIncludes/XSHelperFunctions.cginc" #include "../CGIncludes/XSLightingFunctions.cginc" From b339bc75a2dfaa9da7e5f76b781119696615be74 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 26 May 2021 14:24:38 -0400 Subject: [PATCH 19/30] adjust where high mids get placed in emission --- Main/CGIncludes/XSLightingFunctions.cginc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index 49fb889..2a49167 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -402,8 +402,8 @@ half4 calcEmission(XSLighting i, DotProducts d, half lightAvg) { float audioDataBass = AudioLinkData(int2(0,0)).x; - float audioDataMids = (AudioLinkData(int2(0,1)).x + AudioLinkData(int2(0,2)).x) / 2; - float audioDataHighs = AudioLinkData(int2(0,3)).x; + float audioDataMids = AudioLinkData(int2(0,1)).x; + float audioDataHighs = (AudioLinkData(int2(0,2)).x + AudioLinkData(int2(0,3)).x) * 0.5; float4 emissionChannelRed = i.emissionMap.r * _EmissionColor * audioDataBass; float4 emissionChannelGreen = i.emissionMap.g * _EmissionColor0 * audioDataMids; From 5794e3186aeafccdc8a05f915aaf14d85d5e76dc Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 26 May 2021 14:49:17 -0400 Subject: [PATCH 20/30] Update AudioLink cginc --- Main/CGIncludes/AudioLink.cginc | 78 +++++++++++++---------- Main/CGIncludes/XSLightingFunctions.cginc | 5 +- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/Main/CGIncludes/AudioLink.cginc b/Main/CGIncludes/AudioLink.cginc index dee8aff..9d1fad1 100644 --- a/Main/CGIncludes/AudioLink.cginc +++ b/Main/CGIncludes/AudioLink.cginc @@ -1,21 +1,21 @@ // Map of where features in AudioLink are. -#define ALPASS_DFT int2(0,4) -#define ALPASS_WAVEFORM int2(0,6) -#define ALPASS_AUDIOLINK int2(0,0) -#define ALPASS_AUDIOLINKHISTORY int2(1,0) -#define ALPASS_GENERALVU int2(0,22) -#define ALPASS_AUDIOLINK_BASS int2(0,0) -#define ALPASS_AUDIOLINK_LOWMID int2(32,0) -#define ALPASS_AUDIOLINK_HIMID int2(64,0) -#define ALPASS_AUDIOLINK_TREBLE int2(96,0) +#define ALPASS_DFT int2(0,4) +#define ALPASS_WAVEFORM int2(0,6) +#define ALPASS_AUDIOLINK int2(0,0) +#define ALPASS_AUDIOBASS int2(0,0) +#define ALPASS_AUDIOLOWMIDS int2(0,1) +#define ALPASS_AUDIOHIGHMIDS int2(0,2) +#define ALPASS_AUDIOTREBLE int2(0,3) +#define ALPASS_AUDIOLINKHISTORY int2(1,0) +#define ALPASS_GENERALVU int2(0,22) #define ALPASS_GENERALVU_INSTANCE_TIME int2(2,22) #define ALPASS_GENERALVU_LOCAL_TIME int2(3,22) -#define ALPASS_CCINTERNAL int2(12,22) -#define ALPASS_CCSTRIP int2(0,24) -#define ALPASS_CCLIGHTS int2(0,25) -#define ALPASS_AUTOCORRELATOR int2(0,27) +#define ALPASS_CCINTERNAL int2(12,22) +#define ALPASS_CCSTRIP int2(0,24) +#define ALPASS_CCLIGHTS int2(0,25) +#define ALPASS_AUTOCORRELATOR int2(0,27) // Some basic constants to use (Note, these should be compatible with // future version of AudioLink, but may change. @@ -60,23 +60,31 @@ float4 AudioLinkLerp(float2 xy) { return lerp( AudioLinkData(xy), AudioLinkData( // Same as AudioLinkLerp but properly handles multiline reading. float4 AudioLinkLerpMultiline(float2 xy) { return lerp( AudioLinkDataMultiline(xy), AudioLinkDataMultiline(xy+float2(1,0)), frac( xy.x ) ); } +//Tests to see if Audio Link texture is available, I think this only works on VertFrag shaders. Will need another method for Surface Shaders? +bool AudioLinkIsAvailableNonSurface() +{ + int width, height; + _AudioTexture.GetDimensions(width, height); + return width > 16; +} + // Decompress a RGBA FP16 into a really big number, this is used in some sections of the info block. #define DecodeLongFloat( vALValue ) (vALValue.r + vALValue.g*1024 + vALValue.b * 1048576 + vALValue.a * 1073741824 ) // Extra utility functions for time. -uint ALDecodeDataAsUInt( uint2 sample ) +uint ALDecodeDataAsUInt( uint2 indexloc ) { - half4 rpx = AudioLinkData( sample ); + half4 rpx = AudioLinkData( indexloc ); return DecodeLongFloat( rpx ); } //Note: This will truncate time to every 134,217.728 seconds (~1.5 days of an instance being up) to prevent floating point aliasing. // if your code will alias sooner, you will need to use a different function. -float ALDecodeDataAsFloat( uint2 sample ) +float ALDecodeDataAsFloat( uint2 indexloc ) { - return (ALDecodeDataAsUInt( sample ) & 0x7ffffff) / 1000.; + return (ALDecodeDataAsUInt( indexloc ) & 0x7ffffff) / 1000.; } @@ -156,7 +164,7 @@ float3 CCtoRGB( float bin, float intensity, int RootNote ) // A basic versino of the debug screen without text was only 134 // instructions. -float PrintChar( uint selchar, float2 mxy ) +float PrintChar( uint selchar, float2 mxy, float2 softness ) { const static uint BitmapNumberFont[40] = { 15379168, // '0' 1110 1010 1010 1010 1110 0000 @@ -173,32 +181,32 @@ float PrintChar( uint selchar, float2 mxy ) 57344, // '-' 0000 0000 1110 0000 0000 0000 0, // ' ' 15395488, // 'A' 1110 1010 1110 1010 1010 0000 - 15395552, // 'B' 1110 1010 1110 1010 1110 0000 + 15387360, // 'B' 1110 1010 1100 1010 1110 0000 15239392, // 'C' 1110 1000 1000 1000 1110 0000 15379168, // 'D' 1110 1010 1010 1010 1110 0000 15255776, // 'E' 1110 1000 1100 1000 1110 0000 15255680, // 'F' 1110 1000 1100 1000 1000 0000 - 15264480, // 'G' 1110 1000 1110 1010 1110 0000 + 15248096, // 'G' 1110 1000 1010 1010 1110 0000 11201184, // 'H' 1010 1010 1110 1010 1010 0000 14959840, // 'I' 1110 0100 0100 0100 1110 0000 - 14823136, // 'J' 1110 0010 0010 1110 1110 0000 + 14822112, // 'J' 1110 0010 0010 1010 1110 0000 11201184, // 'K' 1010 1010 1110 1010 1010 0000 8947936 , // 'L' 1000 1000 1000 1000 1110 0000 11446944, // 'M' 1010 1110 1010 1010 1010 0000 - 9349792 , // 'N' 1000 1110 1010 1010 1010 0000 + 13281952, // 'N' 1110 1010 1010 1010 1010 0000 15379168, // 'O' 1110 1010 1010 1010 1110 0000 15394944, // 'P' 1110 1010 1110 1000 1000 0000 - 15380192, // 'Q' 1110 1010 1010 1110 1110 0000 + 15380064, // 'Q' 1110 1010 1010 1110 0110 0000 15395488, // 'R' 1110 1010 1110 1010 1010 0000 15262432, // 'S' 1110 1000 1110 0010 1110 0000 14959680, // 'T' 1110 0100 0100 0100 0100 0000 11184864, // 'U' 1010 1010 1010 1010 1110 0000 - 11184704, // 'V' 1010 1010 1010 1010 0100 0000 - 11464256, // 'W' 1010 1010 1110 1110 0100 0000 + 11185728, // 'V' 1010 1010 1010 1110 0100 0000 + 11185824, // 'W' 1010 1010 1010 1110 1010 0000 11160224, // 'X' 1010 1010 0100 1010 1010 0000 11199552, // 'Y' 1010 1010 1110 0100 0100 0000 14829792, // 'Z' 1110 0010 0100 1000 1110 0000 - 658144, // ':)'0000 1010 0000 1010 1110 0000 + 658144 // ':)'0000 1010 0000 1010 1110 0000 }; const static uint BitmapNumberFontPartial[40] = { 15379168, // '0' 1110 1010 1010 1010 1110 0000 @@ -223,24 +231,24 @@ float PrintChar( uint selchar, float2 mxy ) 15248096, // 'G' 1110 1000 1010 1010 1110 0000 11201184, // 'H' 1010 1010 1110 1010 1010 0000 14959840, // 'I' 1110 0100 0100 0100 0100 0000 - 14822080, // 'J' 1110 0010 0010 1010 1100 0000 + 14821952, // 'J' 1110 0010 0010 1010 0100 0000 11192992, // 'K' 1010 1010 1100 1010 1010 0000 8947936 , // 'L' 1000 1000 1000 1000 1110 0000 11446944, // 'M' 1010 1110 1010 1010 1010 0000 - 9218720 , // 'N' 1000 1100 1010 1010 1010 0000 + 15379104, // 'N' 1100 1010 1010 1010 1010 0000 15379168, // 'O' 1110 1010 1010 1010 1110 0000 15394944, // 'P' 1110 1010 1110 1000 1000 0000 - 15379040, // 'Q' 1110 1010 1010 1010 0110 0000 + 15380064, // 'Q' 1110 1010 1010 1110 0110 0000 15387296, // 'R' 1110 1010 1100 1010 1010 0000 - 15262432, // 'S' 1110 1000 1110 0010 1110 0000 + 6832832, // 'S' 0110 1000 0100 0010 1100 0000 14959680, // 'T' 1110 0100 0100 0100 0100 0000 11184864, // 'U' 1010 1010 1010 1010 1110 0000 11185728, // 'V' 1010 1010 1010 1110 0100 0000 - 11464256, // 'W' 1010 1010 1110 1110 0100 0000 + 11185824, // 'W' 1010 1010 1010 1110 1010 0000 11160224, // 'X' 1010 1010 0100 1010 1010 0000 11199552, // 'Y' 1010 1010 1110 0100 0100 0000 14829792, // 'Z' 1110 0010 0100 1000 1110 0000 - 657984, // ':)'0000 1010 0000 1010 0100 0000 + 657984 // ':)'0000 1010 0000 1010 0100 0000 }; uint bitmap = BitmapNumberFont[selchar]; @@ -272,13 +280,13 @@ float PrintChar( uint selchar, float2 mxy ) float ov = lerp( lerp( tolerp.x, tolerp.y, shift.x ), lerp( tolerp.z, tolerp.w, shift.x ), shift.y ) / 2.; - return saturate( ov * 20 - 10 ); + return saturate( ov * softness - softness/2 ); } } // Used for debugging -float PrintNumberOnLine( float number, uint fixeddiv, uint digit, float2 mxy, int offset, bool leadzero ) +float PrintNumberOnLine( float number, uint fixeddiv, uint digit, float2 mxy, int offset, bool leadzero, float2 softness ) { uint selnum; if( number < 0 && digit == 0 ) @@ -316,6 +324,6 @@ float PrintNumberOnLine( float number, uint fixeddiv, uint digit, float2 mxy, in } } - return PrintChar( selnum, mxy ); + return PrintChar( selnum, mxy, softness ); } diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index 2a49167..abcd5cd 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -387,10 +387,7 @@ half4 calcEmission(XSLighting i, DotProducts d, half lightAvg) } else { - int width, height; - _AudioTexture.GetDimensions(width, height); - bool hasAudioLink = width > 16; - if(hasAudioLink) + if(AudioLinkIsAvailableNonSurface()) { if(_EmissionAudioLinkChannel != 5) { From 26d898826ac07b8a505b73cd0fbae5c29badf886 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 26 May 2021 16:23:28 -0400 Subject: [PATCH 21/30] more cginc adjustments --- Main/CGIncludes/AudioLink.cginc | 5 ++--- Main/CGIncludes/XSLightingFunctions.cginc | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Main/CGIncludes/AudioLink.cginc b/Main/CGIncludes/AudioLink.cginc index 9d1fad1..3e5be4b 100644 --- a/Main/CGIncludes/AudioLink.cginc +++ b/Main/CGIncludes/AudioLink.cginc @@ -61,7 +61,7 @@ float4 AudioLinkLerp(float2 xy) { return lerp( AudioLinkData(xy), AudioLinkData( float4 AudioLinkLerpMultiline(float2 xy) { return lerp( AudioLinkDataMultiline(xy), AudioLinkDataMultiline(xy+float2(1,0)), frac( xy.x ) ); } //Tests to see if Audio Link texture is available, I think this only works on VertFrag shaders. Will need another method for Surface Shaders? -bool AudioLinkIsAvailableNonSurface() +bool AudioLinkIsAvailable() { int width, height; _AudioTexture.GetDimensions(width, height); @@ -325,5 +325,4 @@ float PrintNumberOnLine( float number, uint fixeddiv, uint digit, float2 mxy, in } return PrintChar( selnum, mxy, softness ); -} - +} \ No newline at end of file diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index abcd5cd..fcd6a7a 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -387,7 +387,7 @@ half4 calcEmission(XSLighting i, DotProducts d, half lightAvg) } else { - if(AudioLinkIsAvailableNonSurface()) + if(AudioLinkIsAvailable()) { if(_EmissionAudioLinkChannel != 5) { From 687dd6dda86e219faf2bcd5ab827399250eb9f80 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Wed, 26 May 2021 18:04:47 -0400 Subject: [PATCH 22/30] rename main struct to Fragment Data to be more accurate to what it is --- Main/CGIncludes/AudioLink.cginc | 12 +++++--- Main/CGIncludes/XSDefines.cginc | 4 +-- Main/CGIncludes/XSFrag.cginc | 4 +-- Main/CGIncludes/XSHelperFunctions.cginc | 14 +++++----- Main/CGIncludes/XSLighting.cginc | 2 +- Main/CGIncludes/XSLightingFunctions.cginc | 34 +++++++++++------------ 6 files changed, 36 insertions(+), 34 deletions(-) diff --git a/Main/CGIncludes/AudioLink.cginc b/Main/CGIncludes/AudioLink.cginc index 3e5be4b..59d9753 100644 --- a/Main/CGIncludes/AudioLink.cginc +++ b/Main/CGIncludes/AudioLink.cginc @@ -60,12 +60,16 @@ float4 AudioLinkLerp(float2 xy) { return lerp( AudioLinkData(xy), AudioLinkData( // Same as AudioLinkLerp but properly handles multiline reading. float4 AudioLinkLerpMultiline(float2 xy) { return lerp( AudioLinkDataMultiline(xy), AudioLinkDataMultiline(xy+float2(1,0)), frac( xy.x ) ); } -//Tests to see if Audio Link texture is available, I think this only works on VertFrag shaders. Will need another method for Surface Shaders? +//Tests to see if Audio Link texture is available bool AudioLinkIsAvailable() { - int width, height; - _AudioTexture.GetDimensions(width, height); - return width > 16; + #if !defined(AUDIOLINK_STANDARD_INDEXING) + int width, height; + _AudioTexture.GetDimensions(width, height); + return width > 16; + #else + return _AudioTexture_TexelSize.z > 16; + #endif } // Decompress a RGBA FP16 into a really big number, this is used in some sections of the info block. diff --git a/Main/CGIncludes/XSDefines.cginc b/Main/CGIncludes/XSDefines.cginc index 687b90b..202a0f1 100644 --- a/Main/CGIncludes/XSDefines.cginc +++ b/Main/CGIncludes/XSDefines.cginc @@ -88,7 +88,7 @@ struct VertexOutput }; #endif -struct XSLighting +struct FragmentData { half4 albedo; half4 normalMap; @@ -135,7 +135,6 @@ struct TextureUV half2 outlineMaskUV; half2 clipMapUV; half2 dissolveUV; - half2 audioLinkUV; }; struct DotProducts @@ -157,7 +156,6 @@ struct VertexLightInformation { float Attenuation[4]; }; - UNITY_DECLARE_TEX2D(_MainTex); half4 _MainTex_ST; UNITY_DECLARE_TEX2D_NOSAMPLER(_ClipMap); half4 _ClipMap_ST; UNITY_DECLARE_TEX2D_NOSAMPLER(_DissolveTexture); half4 _DissolveTexture_ST; diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index 9cebc2c..ea06e15 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -12,7 +12,7 @@ float4 frag ( if(_TilingMode != 1) { InitializeTextureUVs(i, t); } else { InitializeTextureUVsMerged(i, t); }; #ifdef UNITY_PASS_SHADOWCASTER - XSLighting o = (XSLighting)0; //Populate Lighting Struct, but only with important shadowcaster stuff! + FragmentData o = (FragmentData)0; //Populate Lighting Struct, but only with important shadowcaster stuff! o.albedo = UNITY_SAMPLE_TEX2D(_MainTex, t.albedoUV) * _Color; o.clipMap = tex2Dlod(_ClipMask, float4(t.clipMapUV, 0, 0)); o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV * _DissolveLayer1Scale + (_Time.y * _DissolveLayer1Speed)); @@ -51,7 +51,7 @@ float4 frag ( i.ntb[2] = -i.ntb[2]; } - XSLighting o = (XSLighting)0; //Populate Lighting Struct + FragmentData o = (FragmentData)0; //Populate Surface Fragment Struct o.albedo = UNITY_SAMPLE_TEX2D(_MainTex, t.albedoUV) * _Color * lerp(1, float4(i.color.rgb, 1), _VertexColorAlbedo); o.specularMap = UNITY_SAMPLE_TEX2D_SAMPLER(_SpecularMap, _MainTex, t.specularMapUV); o.metallicGlossMap = UNITY_SAMPLE_TEX2D_SAMPLER(_MetallicGlossMap, _MainTex, t.metallicGlossMapUV); diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 74dbd17..36f3996 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -1,4 +1,4 @@ -void calcNormal(inout XSLighting i) +void calcNormal(inout FragmentData i) { if(_NormalMapMode == 0) { @@ -219,7 +219,7 @@ half3 getReflectionUV(half3 direction, half3 position, half4 cubemapPosition, ha return direction; } -half3 getEnvMap(XSLighting i, DotProducts d, float blur, half3 reflDir, half3 indirectLight, half3 wnormal) +half3 getEnvMap(FragmentData i, DotProducts d, float blur, half3 reflDir, half3 indirectLight, half3 wnormal) {//This function handls Unity style reflections, Matcaps, and a baked in fallback cubemap. half3 envMap = half3(0,0,0); @@ -273,7 +273,7 @@ bool IsColorMatch(float3 color1, float3 color2) return step((delta.r + delta.g + delta.b), epsilon); } -float AdjustAlphaUsingTextureArray(XSLighting i, float alphaToAdj) +float AdjustAlphaUsingTextureArray(FragmentData i, float alphaToAdj) { half4 compValRGBW = 0; // Red Green Blue White half4 compValCYMB = 0; // Cyan Yellow Magenta Black @@ -304,7 +304,7 @@ float AdjustAlphaUsingTextureArray(XSLighting i, float alphaToAdj) return alphaToAdj; } -void calcDissolve(inout XSLighting i, inout float3 col) +void calcDissolve(inout FragmentData i, inout float3 col) { #ifdef _ALPHATEST_ON float4 mask = i.dissolveMask.x * i.dissolveMaskSecondLayer.x * _DissolveBlendPower; @@ -347,7 +347,7 @@ void calcDissolve(inout XSLighting i, inout float3 col) } //todo: What the fuck is going on here? -void calcAlpha(inout XSLighting i, inout float alpha) +void calcAlpha(inout FragmentData i, inout float alpha) { #if defined(_ALPHABLEND_ON) && !defined(_ALPHATEST_ON) // Traditional Alphablended / Fade blending alpha = i.albedo.a; @@ -406,7 +406,7 @@ half2 rotateUV(half2 uv, half rotation) ); } -half DotHalftone(XSLighting i, half scalar) //Scalar can be anything from attenuation to a dot product +half DotHalftone(FragmentData i, half scalar) //Scalar can be anything from attenuation to a dot product { bool inMirror = IsInMirror(); half2 uv = SphereUV(calcViewDir(i.worldPos)); @@ -419,7 +419,7 @@ half DotHalftone(XSLighting i, half scalar) //Scalar can be anything from attenu return lerp(1, 1-dotMask, smoothstep(0, 0.4, 1/distance(i.worldPos, _WorldSpaceCameraPos)));; } -half LineHalftone(XSLighting i, half scalar) +half LineHalftone(FragmentData i, half scalar) { // #if defined(DIRECTIONAL) // scalar = saturate(scalar + ((1-i.attenuation) * 0.2)); diff --git a/Main/CGIncludes/XSLighting.cginc b/Main/CGIncludes/XSLighting.cginc index d7c92d7..11e5d35 100644 --- a/Main/CGIncludes/XSLighting.cginc +++ b/Main/CGIncludes/XSLighting.cginc @@ -1,4 +1,4 @@ -half4 BRDF_XSLighting(XSLighting i, TextureUV t) +half4 BRDF_XSLighting(FragmentData i, TextureUV t) { float3 untouchedNormal = i.normal; i.tangent = normalize(i.tangent); diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index fcd6a7a..e0f36cf 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -81,7 +81,7 @@ float3 getVertexLightsDir(inout VertexLightInformation vLights, float3 worldPos, } // Get the most intense light Dir from probes OR from a light source. Method developed by Xiexe / Merlin -half3 calcLightDir(XSLighting i) +half3 calcLightDir(FragmentData i) { half3 lightDir = UnityWorldSpaceLightDir(i.worldPos); half3 probeLightDir = unity_SHAr.xyz + unity_SHAg.xyz + unity_SHAb.xyz; @@ -150,7 +150,7 @@ float3 get4VertexLightsColFalloff(inout VertexLightInformation vLight, float3 wo return lightColor; } -half4 calcRamp(XSLighting i, DotProducts d) +half4 calcRamp(FragmentData i, DotProducts d) { half remapRamp; remapRamp = (d.ndl * 0.5 + 0.5) * lerp(1, i.occlusion.r, _OcclusionMode) ; @@ -161,7 +161,7 @@ half4 calcRamp(XSLighting i, DotProducts d) return ramp; } -half4 calcRampShadowOverride(XSLighting i, float ndl) +half4 calcRampShadowOverride(FragmentData i, float ndl) { half remapRamp; remapRamp = (ndl * 0.5 + 0.5) * lerp(1, i.occlusion.r, _OcclusionMode); @@ -169,7 +169,7 @@ half4 calcRampShadowOverride(XSLighting i, float ndl) return ramp; } -float3 getVertexLightsDiffuse(XSLighting i, VertexLightInformation vLight) +float3 getVertexLightsDiffuse(FragmentData i, VertexLightInformation vLight) { float3 vertexLightsDiffuse = 0; #if defined(VERTEXLIGHT_ON) @@ -182,7 +182,7 @@ float3 getVertexLightsDiffuse(XSLighting i, VertexLightInformation vLight) return vertexLightsDiffuse; } -half4 calcMetallicSmoothness(XSLighting i) +half4 calcMetallicSmoothness(FragmentData i) { half roughness = 1-(_Glossiness * i.metallicGlossMap.a); roughness *= 1.7 - 0.7 * roughness; @@ -190,7 +190,7 @@ half4 calcMetallicSmoothness(XSLighting i) return half4(metallic, 0, 0, roughness); } -half4 calcRimLight(XSLighting i, DotProducts d, half4 lightCol, half3 indirectDiffuse, half3 envMap) +half4 calcRimLight(FragmentData i, DotProducts d, half4 lightCol, half3 indirectDiffuse, half3 envMap) { half rimIntensity = saturate((1-d.svdn)) * pow(d.ndl, _RimThreshold); rimIntensity = smoothstep(_RimRange - _RimSharpness, _RimRange + _RimSharpness, rimIntensity); @@ -199,7 +199,7 @@ half4 calcRimLight(XSLighting i, DotProducts d, half4 lightCol, half3 indirectDi return rim * _RimColor * lerp(1, i.diffuseColor.rgbb, _RimAlbedoTint) * lerp(1, envMap.rgbb, _RimCubemapTint); } -half4 calcShadowRim(XSLighting i, DotProducts d, half3 indirectDiffuse) +half4 calcShadowRim(FragmentData i, DotProducts d, half3 indirectDiffuse) { half rimIntensity = saturate((1-d.svdn)) * pow(1-d.ndl, _ShadowRimThreshold * 2); rimIntensity = smoothstep(_ShadowRimRange - _ShadowRimSharpness, _ShadowRimRange + _ShadowRimSharpness, rimIntensity); @@ -219,7 +219,7 @@ float3 getAnisotropicReflectionVector(float3 viewDir, float3 bitangent, float3 t return reflect(-viewDir, bentNormal); } -half3 calcDirectSpecular(XSLighting i, float ndl, float ndh, float vdn, float ldh, half4 lightCol, half3 halfVector, half anisotropy) +half3 calcDirectSpecular(FragmentData i, float ndl, float ndh, float vdn, float ldh, half4 lightCol, half3 halfVector, half anisotropy) { half specularIntensity = _SpecularIntensity * i.specularMap.r; half3 specular = half3(0,0,0); @@ -244,7 +244,7 @@ half3 calcDirectSpecular(XSLighting i, float ndl, float ndh, float vdn, float ld return specular; } -float3 getVertexLightSpecular(XSLighting i, DotProducts d, VertexLightInformation vLight, float3 normal, float3 viewDir, float anisotropy) +float3 getVertexLightSpecular(FragmentData i, DotProducts d, VertexLightInformation vLight, float3 normal, float3 viewDir, float anisotropy) { float3 vertexLightSpec = 0; #if defined(VERTEXLIGHT_ON) @@ -261,7 +261,7 @@ float3 getVertexLightSpecular(XSLighting i, DotProducts d, VertexLightInformatio return vertexLightSpec; } -half3 calcIndirectSpecular(XSLighting i, DotProducts d, half4 metallicSmoothness, half3 reflDir, half3 indirectLight, half3 viewDir, float3 fresnel, half4 ramp) +half3 calcIndirectSpecular(FragmentData i, DotProducts d, half4 metallicSmoothness, half3 reflDir, half3 indirectLight, half3 viewDir, float3 fresnel, half4 ramp) {//This function handls Unity style reflections, Matcaps, and a baked in fallback cubemap. half3 spec = half3(0,0,0); @@ -323,7 +323,7 @@ half3 calcIndirectSpecular(XSLighting i, DotProducts d, half4 metallicSmoothness return spec; } -half4 calcOutlineColor(XSLighting i, DotProducts d, half3 indirectDiffuse, half4 lightCol) +half4 calcOutlineColor(FragmentData i, DotProducts d, half3 indirectDiffuse, half4 lightCol) { half3 outlineColor = half3(0,0,0); #if defined(Geometry) @@ -335,13 +335,13 @@ half4 calcOutlineColor(XSLighting i, DotProducts d, half3 indirectDiffuse, half4 return half4(outlineColor,1); } -half3 calcIndirectDiffuse(XSLighting i) +half3 calcIndirectDiffuse(FragmentData i) {// We don't care about anything other than the color from probes for toon lighting. half3 indirectDiffuse = ShadeSH9(float4(0,0.5,0,1));//half3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); return indirectDiffuse; } -half4 calcDiffuse(XSLighting i, DotProducts d, half3 indirectDiffuse, half4 lightCol, half4 ramp) +half4 calcDiffuse(FragmentData i, DotProducts d, half3 indirectDiffuse, half4 lightCol, half4 ramp) { half4 diffuse; half4 indirect = indirectDiffuse.xyzz; @@ -356,7 +356,7 @@ half4 calcDiffuse(XSLighting i, DotProducts d, half3 indirectDiffuse, half4 ligh //Subsurface Scattering - Based on a 2011 GDC Conference from by Colin Barre-Bresebois & Marc Bouchard //Modified by Xiexe -half4 calcSubsurfaceScattering(XSLighting i, DotProducts d, half3 lightDir, half3 viewDir, half3 normal, half4 lightCol, half3 indirectDiffuse) +half4 calcSubsurfaceScattering(FragmentData i, DotProducts d, half3 lightDir, half3 viewDir, half3 normal, half4 lightCol, half3 indirectDiffuse) { UNITY_BRANCH if(any(_SSColor.rgb)) // Skip all the SSS stuff if the color is 0. @@ -377,7 +377,7 @@ half4 calcSubsurfaceScattering(XSLighting i, DotProducts d, half3 lightDir, half } } -half4 calcEmission(XSLighting i, DotProducts d, half lightAvg) +half4 calcEmission(FragmentData i, DotProducts d, half lightAvg) { #if defined(UNITY_PASS_FORWARDBASE) // Emission only in Base Pass, and vertex lights float4 emission = 0; @@ -425,7 +425,7 @@ half4 calcEmission(XSLighting i, DotProducts d, half lightAvg) #endif } -void calcReflectionBlending(XSLighting i, inout half4 col, half3 indirectSpecular) +void calcReflectionBlending(FragmentData i, inout half4 col, half3 indirectSpecular) { if(_ReflectionBlendMode == 0) // Additive col += indirectSpecular.xyzz * i.reflectivityMask.r; @@ -435,7 +435,7 @@ void calcReflectionBlending(XSLighting i, inout half4 col, half3 indirectSpecula col -= indirectSpecular.xyzz * i.reflectivityMask.r; } -void calcClearcoat(inout half4 col, XSLighting i, DotProducts d, half3 untouchedNormal, half3 indirectDiffuse, half3 lightCol, half3 viewDir, half3 lightDir, half4 ramp) +void calcClearcoat(inout half4 col, FragmentData i, DotProducts d, half3 untouchedNormal, half3 indirectDiffuse, half3 lightCol, half3 viewDir, half3 lightDir, half4 ramp) { UNITY_BRANCH if(_ClearCoat != 0) From 402f9882c524b4719b4a63c9530b4383526bec39 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Thu, 27 May 2021 01:36:35 -0400 Subject: [PATCH 23/30] Add support for fur shader --- Editor/XSToonInspector.cs | 76 ++++++++++++++++++++- Main/CGIncludes/XSDefines.cginc | 8 +++ Main/CGIncludes/XSFrag.cginc | 13 +++- Main/CGIncludes/XSHelperFunctions.cginc | 87 +++++++++++++++++-------- 4 files changed, 153 insertions(+), 31 deletions(-) diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 669a6d2..28f802c 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -24,6 +24,7 @@ public class FoldoutToggles public bool ShowEyeTracking = false; public bool ShowAudioLink = false; public bool ShowDissolve = false; + public bool ShowFur = false; } public class XSToonInspector : ShaderGUI @@ -187,11 +188,32 @@ public class XSToonInspector : ShaderGUI private MaterialProperty _EyeOffsetLimit = null; //-- + //Properties for Fur plugin + private MaterialProperty _FurTexture = null; + private MaterialProperty _FurLengthMask = null; + private MaterialProperty _NoiseTexture = null; + private MaterialProperty _LayerCount = null; + private MaterialProperty _FurLength = null; + private MaterialProperty _FurWidth = null; + private MaterialProperty _Gravity = null; + private MaterialProperty _CombX = null; + private MaterialProperty _CombY = null; + private MaterialProperty _FurOcclusion = null; + private MaterialProperty _OcclusionFalloffMin = null; + private MaterialProperty _OcclusionFalloffMax = null; + private MaterialProperty _ColorFalloffMin = null; + private MaterialProperty _ColorFalloffMax = null; + private MaterialProperty _BottomColor = null; + private MaterialProperty _TopColor = null; + private MaterialProperty _StrandAmount = null; + // + //!RDPSPropsInjection private static int BlendMode; private bool isPatreonShader = false; private bool isEyeTracking = false; + private bool isFurShader = false; private bool isOutlined = false; private bool isCutout = false; private bool isCutoutMasked = false; @@ -209,6 +231,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro isOutlined = shader.name.Contains("Outline"); isPatreonShader = shader.name.Contains("Patreon"); isEyeTracking = shader.name.Contains("EyeTracking"); + isFurShader = shader.name.Contains("Fur"); SetupFoldoutDictionary(material); @@ -229,7 +252,19 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro materialEditor.ShaderProperty(_TilingMode, new GUIContent("Tiling Mode", "Setting this to Merged will tile and offset all textures based on the Main texture's Tiling/Offset.")); materialEditor.ShaderProperty(_BlendMode, new GUIContent("Blend Mode", "Blend mode of the material. (Opaque, transparent, cutout, etc.)")); - DoBlendModeSettings(material); + if (!isFurShader) + { + DoBlendModeSettings(material); + } + else + { + SetBlend(material, (int) UnityEngine.Rendering.BlendMode.One, + (int) UnityEngine.Rendering.BlendMode.Zero, + (int) UnityEngine.Rendering.RenderQueue.AlphaTest, 1, 1); + material.EnableKeyword("_ALPHABLEND_ON"); + material.EnableKeyword("_ALPHATEST_ON"); + } + DrawMainSettings(materialEditor, material); DrawDissolveSettings(materialEditor, material); DrawShadowSettings(materialEditor, material); @@ -244,6 +279,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro DrawTransmissionSettings(materialEditor, material); DrawAdvancedSettings(materialEditor, material); DrawPatreonSettings(materialEditor, material); + DrawFurSettings(materialEditor, material); //!RDPSFunctionCallInject @@ -743,6 +779,44 @@ private void DrawPatreonSettings(MaterialEditor materialEditor, Material materia // } + private void DrawFurSettings(MaterialEditor materialEditor, Material material) + { + if (isFurShader) + { + Foldouts[material].ShowFur = XSStyles.ShurikenFoldout("Fur Settings", Foldouts[material].ShowFur); + if (Foldouts[material].ShowFur) + { + materialEditor.TexturePropertySingleLine(new GUIContent("Noise Texture", "Used to control the pattern of the fur strands."), _NoiseTexture); + XSStyles.SeparatorThin(); + + materialEditor.TexturePropertySingleLine(new GUIContent("Fur Albedo", "Albedo Texture for the fur coat"), _FurTexture); + materialEditor.TextureScaleOffsetProperty(_FurTexture); + XSStyles.SeparatorThin(); + + materialEditor.TexturePropertySingleLine(new GUIContent("Length Mask", "Used to control length of the fur."), _FurLengthMask); + materialEditor.TextureScaleOffsetProperty(_FurLengthMask); + XSStyles.SeparatorThin(); + + materialEditor.ShaderProperty(_TopColor, new GUIContent("Top Color", "")); + materialEditor.ShaderProperty(_BottomColor, new GUIContent("Bottom Color", "")); + materialEditor.ShaderProperty(_ColorFalloffMin, new GUIContent("Blend Min", "")); + materialEditor.ShaderProperty(_ColorFalloffMax, new GUIContent("Blend Max", "")); + XSStyles.SeparatorThin(); + + materialEditor.ShaderProperty(_LayerCount, new GUIContent("Layer Count", "")); + materialEditor.ShaderProperty(_StrandAmount, new GUIContent("Strand Count", "")); + materialEditor.ShaderProperty(_FurLength, new GUIContent("Length", "")); + materialEditor.ShaderProperty(_FurWidth, new GUIContent("Strand Width", "")); + XSStyles.SeparatorThin(); + + materialEditor.ShaderProperty(_Gravity, new GUIContent("Gravity Strength", "")); + materialEditor.ShaderProperty(_CombX, new GUIContent("Comb X", "")); + materialEditor.ShaderProperty(_CombY, new GUIContent("Comb Y", "")); + XSStyles.SeparatorThin(); + } + } + } + //!RDPSFunctionInject private void DrawVectorSliders(MaterialEditor materialEditor, Material material, MaterialProperty property, string nameR, string nameG, string nameB, string nameA) diff --git a/Main/CGIncludes/XSDefines.cginc b/Main/CGIncludes/XSDefines.cginc index 202a0f1..6e63e59 100644 --- a/Main/CGIncludes/XSDefines.cginc +++ b/Main/CGIncludes/XSDefines.cginc @@ -78,6 +78,10 @@ struct VertexOutput float4 screenPos : TEXCOORD8; float3 objPos : TEXCOORD10; + #if defined(Fur) + float layer : TEXCOORD11; + #endif + #if !defined(UNITY_PASS_SHADOWCASTER) SHADOW_COORDS(7) UNITY_FOG_COORDS(9) @@ -116,6 +120,10 @@ struct FragmentData float4 screenPos; float2 screenUV; float3 objPos; + + #if defined(Fur) + float layer; + #endif }; struct TextureUV diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index ea06e15..58621fe 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -23,8 +23,12 @@ float4 frag ( o.screenPos = i.screenPos; o.objPos = i.objPos; + #if defined(Fur) + o.layer = i.layer; + #endif + float alpha = o.albedo.a; - calcAlpha(o, alpha); + calcAlpha(o, t, alpha); calcDissolve(o, o.albedo.rgb); return alpha; #else @@ -80,9 +84,14 @@ float4 frag ( o.screenPos = i.screenPos; o.objPos = i.objPos; + #if defined(Fur) + o.layer = i.layer; + AdjustAlbedo(o, t); + #endif + float4 col = BRDF_XSLighting(o,t); float alpha = o.albedo.a; - calcAlpha(o, alpha); + calcAlpha(o, t, alpha); calcDissolve(o, col.rgb); UNITY_APPLY_FOG(i.fogCoord, col); return float4(col.rgb, alpha); diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 36f3996..8c4ccef 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -56,6 +56,9 @@ void InitializeTextureUVs( i.uv1 = eyeUvOffset; #endif + t.uv0 = i.uv; + t.uv1 = i.uv1; + half2 uvSetAlbedo = (_UVSetAlbedo == 0) ? i.uv : i.uv1; t.albedoUV = TRANSFORM_TEX(uvSetAlbedo, _MainTex); @@ -347,42 +350,70 @@ void calcDissolve(inout FragmentData i, inout float3 col) } //todo: What the fuck is going on here? -void calcAlpha(inout FragmentData i, inout float alpha) +void calcAlpha(inout FragmentData i, TextureUV t, inout float alpha) { - #if defined(_ALPHABLEND_ON) && !defined(_ALPHATEST_ON) // Traditional Alphablended / Fade blending - alpha = i.albedo.a; + #if defined(Fur) + float lengthMask = tex2D(_FurLengthMask, t.uv0 * _FurLengthMask_ST.xy + _FurLengthMask_ST.zw).x; - #ifdef UNITY_PASS_SHADOWCASTER - half dither = calcDither(i.screenUV.xy); - clip(alpha - dither); - #endif - #endif + float layer = i.layer; + float layerScalar = (layer / _LayerCount); + + float2 furUV = t.uv0 * _StrandAmount; + furUV.x += _CombX * layer * 0.01; + furUV.y += _CombY * layer * 0.01; - #if !defined(_ALPHABLEND_ON) && defined(_ALPHATEST_ON) // Dithered / Cutout transparency - float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); - if(_BlendMode == 2) + float4 noise = tex2D(_NoiseTexture, furUV); + + if(layer != 0) { - half dither = calcDither(i.screenUV.xy); - float fadeDist = abs(_FadeDitherDistance); - float d = distance(_WorldSpaceCameraPos, i.worldPos); - d = smoothstep(fadeDist, fadeDist + 0.05, d); - d = lerp(d, 1-d, saturate(step(0, _FadeDitherDistance))); - dither += lerp(0, d, saturate(_FadeDither)); - clip(modifiedAlpha - dither); + float clipMap = (layerScalar * (1-_FurWidth)) + (1-lengthMask); + clip(noise.r - clipMap); } - - if(_BlendMode == 1) + else { - clip(modifiedAlpha - _Cutoff); + float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); + half dither = calcDither(i.screenUV.xy); + alpha = modifiedAlpha - (dither * (1-i.albedo.a) * 0.15); + #if defined(UNITY_PASS_SHADOWCASTER) + clip(modifiedAlpha - dither); + #endif } - #endif + #else + #if defined(_ALPHABLEND_ON) && !defined(_ALPHATEST_ON) // Traditional Alphablended / Fade blending + alpha = i.albedo.a; + + #ifdef UNITY_PASS_SHADOWCASTER + half dither = calcDither(i.screenUV.xy); + clip(alpha - dither); + #endif + #endif + + #if !defined(_ALPHABLEND_ON) && defined(_ALPHATEST_ON) // Dithered / Cutout transparency + float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); + if(_BlendMode == 2) + { + half dither = calcDither(i.screenUV.xy); + float fadeDist = abs(_FadeDitherDistance); + float d = distance(_WorldSpaceCameraPos, i.worldPos); + d = smoothstep(fadeDist, fadeDist + 0.05, d); + d = lerp(d, 1-d, saturate(step(0, _FadeDitherDistance))); + dither += lerp(0, d, saturate(_FadeDither)); + clip(modifiedAlpha - dither); + } + + if(_BlendMode == 1) + { + clip(modifiedAlpha - _Cutoff); + } + #endif - #if defined(_ALPHABLEND_ON) && defined(_ALPHATEST_ON) // Alpha to Coverage - float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); - half dither = calcDither(i.screenUV.xy); - alpha = modifiedAlpha - (dither * (1-i.albedo.a) * 0.15); - #if defined(UNITY_PASS_SHADOWCASTER) - clip(modifiedAlpha - dither); + #if defined(_ALPHABLEND_ON) && defined(_ALPHATEST_ON) // Alpha to Coverage + float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); + half dither = calcDither(i.screenUV.xy); + alpha = modifiedAlpha - (dither * (1-i.albedo.a) * 0.15); + #if defined(UNITY_PASS_SHADOWCASTER) + clip(modifiedAlpha - dither); + #endif #endif #endif } From 2f56b73d155d9393f059a2cdcbf2dd5e384b1183 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Thu, 27 May 2021 14:51:33 -0400 Subject: [PATCH 24/30] Move fur alpha code into plugin CG --- Main/CGIncludes/XSFrag.cginc | 3 ++- Main/CGIncludes/XSHelperFunctions.cginc | 28 +------------------------ 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index 58621fe..841f348 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -84,13 +84,14 @@ float4 frag ( o.screenPos = i.screenPos; o.objPos = i.objPos; + float alpha = o.albedo.a; #if defined(Fur) o.layer = i.layer; AdjustAlbedo(o, t); + DoFurAlpha(o,t,alpha); #endif float4 col = BRDF_XSLighting(o,t); - float alpha = o.albedo.a; calcAlpha(o, t, alpha); calcDissolve(o, col.rgb); UNITY_APPLY_FOG(i.fogCoord, col); diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 8c4ccef..91f4b68 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -352,33 +352,7 @@ void calcDissolve(inout FragmentData i, inout float3 col) //todo: What the fuck is going on here? void calcAlpha(inout FragmentData i, TextureUV t, inout float alpha) { - #if defined(Fur) - float lengthMask = tex2D(_FurLengthMask, t.uv0 * _FurLengthMask_ST.xy + _FurLengthMask_ST.zw).x; - - float layer = i.layer; - float layerScalar = (layer / _LayerCount); - - float2 furUV = t.uv0 * _StrandAmount; - furUV.x += _CombX * layer * 0.01; - furUV.y += _CombY * layer * 0.01; - - float4 noise = tex2D(_NoiseTexture, furUV); - - if(layer != 0) - { - float clipMap = (layerScalar * (1-_FurWidth)) + (1-lengthMask); - clip(noise.r - clipMap); - } - else - { - float modifiedAlpha = lerp(AdjustAlphaUsingTextureArray(i, i.albedo.a), i.albedo.a, _UseClipsForDissolve); - half dither = calcDither(i.screenUV.xy); - alpha = modifiedAlpha - (dither * (1-i.albedo.a) * 0.15); - #if defined(UNITY_PASS_SHADOWCASTER) - clip(modifiedAlpha - dither); - #endif - } - #else + #if !defined(Fur) #if defined(_ALPHABLEND_ON) && !defined(_ALPHATEST_ON) // Traditional Alphablended / Fade blending alpha = i.albedo.a; From 2784f740056d41b000ee5657e9c35925ddb68a1c Mon Sep 17 00:00:00 2001 From: Xiexe Date: Thu, 27 May 2021 20:31:18 -0400 Subject: [PATCH 25/30] more fur stuff, done --- Main/CGIncludes/XSFrag.cginc | 3 ++- Main/CGIncludes/XSHelperFunctions.cginc | 5 +++++ Main/CGIncludes/XSLighting.cginc | 6 +++++- Main/CGIncludes/XSLightingFunctions.cginc | 15 ++++++++------- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Main/CGIncludes/XSFrag.cginc b/Main/CGIncludes/XSFrag.cginc index 841f348..53d4677 100644 --- a/Main/CGIncludes/XSFrag.cginc +++ b/Main/CGIncludes/XSFrag.cginc @@ -23,11 +23,12 @@ float4 frag ( o.screenPos = i.screenPos; o.objPos = i.objPos; + float alpha = o.albedo.a; #if defined(Fur) o.layer = i.layer; + DoFurAlpha(o,t,alpha); #endif - float alpha = o.albedo.a; calcAlpha(o, t, alpha); calcDissolve(o, o.albedo.rgb); return alpha; diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index 91f4b68..edcb3d4 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -392,6 +392,11 @@ void calcAlpha(inout FragmentData i, TextureUV t, inout float alpha) #endif } +float lerpstep(float a, float b, float t) +{ + return saturate( ( t - a ) / ( b - a ) ); +} + // //Halftone functions, finish implementing later.. Not correct right now. float2 SphereUV( float3 coords /*viewDir?*/) { diff --git a/Main/CGIncludes/XSLighting.cginc b/Main/CGIncludes/XSLighting.cginc index 11e5d35..e47abf7 100644 --- a/Main/CGIncludes/XSLighting.cginc +++ b/Main/CGIncludes/XSLighting.cginc @@ -91,13 +91,17 @@ half4 BRDF_XSLighting(FragmentData i, TextureUV t) indirectSpecular *= lerp(0.5, 1, stipplingIndirect); // Don't want these to go completely black, looks weird } + #if defined(Fur) + AdjustFurSpecular(i, directSpecular.rgb, indirectSpecular.rgb); + #endif + half4 col = diffuse * shadowRim; calcReflectionBlending(i, col, indirectSpecular.xyzz); col += max(directSpecular.xyzz, rimLight); col.rgb += max(vertexLightSpec.rgb, rimLight); col += subsurface; calcClearcoat(col, i, d, untouchedNormal, indirectDiffuse, lightCol, viewDir, lightDir, ramp); - col += calcEmission(i, d, lightAvg); + col += calcEmission(i, t, d, lightAvg); float4 finalColor = lerp(col, outlineColor, i.isOutline) * lerp(1, lineHalftone, _HalftoneLineIntensity * usingLineHalftone); return finalColor; diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index e0f36cf..be38f6f 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -377,7 +377,7 @@ half4 calcSubsurfaceScattering(FragmentData i, DotProducts d, half3 lightDir, ha } } -half4 calcEmission(FragmentData i, DotProducts d, half lightAvg) +half4 calcEmission(FragmentData i, TextureUV t, DotProducts d, half lightAvg) { #if defined(UNITY_PASS_FORWARDBASE) // Emission only in Base Pass, and vertex lights float4 emission = 0; @@ -397,14 +397,15 @@ half4 calcEmission(FragmentData i, DotProducts d, half lightAvg) } else { + float audioDataBass = AudioLinkData(ALPASS_AUDIOBASS).x; + float audioDataMids = AudioLinkData(ALPASS_AUDIOLOWMIDS).x; + float audioDataHighs = (AudioLinkData(ALPASS_AUDIOHIGHMIDS).x + AudioLinkData(ALPASS_AUDIOTREBLE).x) * 0.5; - float audioDataBass = AudioLinkData(int2(0,0)).x; - float audioDataMids = AudioLinkData(int2(0,1)).x; - float audioDataHighs = (AudioLinkData(int2(0,2)).x + AudioLinkData(int2(0,3)).x) * 0.5; - + float smoothsMids = smoothstep((1-audioDataMids), (1-audioDataMids) + (0.3 * fwidth(i.emissionMap.g)), i.emissionMap.g); + float smoothsHighs = smoothstep((1-audioDataHighs), (1-audioDataHighs) + (0.3 * fwidth(i.emissionMap.b)), i.emissionMap.b); float4 emissionChannelRed = i.emissionMap.r * _EmissionColor * audioDataBass; - float4 emissionChannelGreen = i.emissionMap.g * _EmissionColor0 * audioDataMids; - float4 emissionChannelBlue = i.emissionMap.b * _EmissionColor1 * audioDataHighs; + float4 emissionChannelGreen = smoothsMids * _EmissionColor0 * audioDataMids; + float4 emissionChannelBlue = smoothsHighs * _EmissionColor1 * audioDataHighs; emission = (emissionChannelRed + emissionChannelGreen + emissionChannelBlue) * lerp(1, i.diffuseColor.rgbb, _EmissionToDiffuse); } } From 9bb0358a5aa84d0206c45246326e9ed31ce78e29 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Thu, 27 May 2021 21:10:19 -0400 Subject: [PATCH 26/30] prepare for XSToon3 release, add more audio link emission options --- Editor/TextureList.cs | 2 +- Editor/XSClipMapEditor.cs | 6 +- Editor/XSGradientEditor.cs | 4 +- Editor/XSMultiGradient.cs | 2 +- Editor/XSReimportMyShadersPlease.cs | 10 +- Editor/XSStyles.cs | 4 +- Editor/XSTextureMerger.cs | 36 ++-- Editor/XSToonInspector.cs | 25 ++- Editor/XSUpdater.cs | 44 ++--- Main/CGIncludes/XSDefines.cginc | 1 + Main/CGIncludes/XSLightingFunctions.cginc | 11 +- .../{XSToon2.0.shader => XSToon3.0.shader} | 7 +- ...n2.0.shader.meta => XSToon3.0.shader.meta} | 0 ...lined.shader => XSToon3.0_Outlined.shader} | 7 +- ...er.meta => XSToon3.0_Outlined.shader.meta} | 0 Main/Test.mat.meta | 8 - XSToon 2.0 _ StippledHalftone.mat | 156 ------------------ ...Fiber.mat => XSToon 3.0 _ Carbon Fiber.mat | 88 +++++++++- ...meta => XSToon 3.0 _ Carbon Fiber.mat.meta | 0 ...0.mat => XSToon 3.0 _ StippledHalftone.mat | 40 ++++- ... => XSToon 3.0 _ StippledHalftone.mat.meta | 0 Main/Test.mat => XSToon 3.0.mat | 34 ++-- XSToon 2.0.mat.meta => XSToon 3.0.mat.meta | 0 23 files changed, 227 insertions(+), 258 deletions(-) rename Main/Shaders/{XSToon2.0.shader => XSToon3.0.shader} (98%) rename Main/Shaders/{XSToon2.0.shader.meta => XSToon3.0.shader.meta} (100%) rename Main/Shaders/{XSToon2.0_Outlined.shader => XSToon3.0_Outlined.shader} (97%) rename Main/Shaders/{XSToon2.0_Outlined.shader.meta => XSToon3.0_Outlined.shader.meta} (100%) delete mode 100644 Main/Test.mat.meta delete mode 100644 XSToon 2.0 _ StippledHalftone.mat rename XSToon 2.0 _ Carbon Fiber.mat => XSToon 3.0 _ Carbon Fiber.mat (63%) rename XSToon 2.0 _ Carbon Fiber.mat.meta => XSToon 3.0 _ Carbon Fiber.mat.meta (100%) rename XSToon 2.0.mat => XSToon 3.0 _ StippledHalftone.mat (80%) rename XSToon 2.0 _ StippledHalftone.mat.meta => XSToon 3.0 _ StippledHalftone.mat.meta (100%) rename Main/Test.mat => XSToon 3.0.mat (90%) rename XSToon 2.0.mat.meta => XSToon 3.0.mat.meta (100%) diff --git a/Editor/TextureList.cs b/Editor/TextureList.cs index da53b3d..3a4fb27 100644 --- a/Editor/TextureList.cs +++ b/Editor/TextureList.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -namespace XSToon +namespace XSToon3 { public class TextureList : ScriptableObject { diff --git a/Editor/XSClipMapEditor.cs b/Editor/XSClipMapEditor.cs index 527a428..161c4ac 100644 --- a/Editor/XSClipMapEditor.cs +++ b/Editor/XSClipMapEditor.cs @@ -6,7 +6,7 @@ using System; using UnityEditorInternal; -namespace XSToon +namespace XSToon3 { public class XSClipMapEditor : EditorWindow { @@ -24,8 +24,8 @@ static public void Init() public static Renderer Rend; - public XSToon.TextureList TexList; - private XSToon.TextureList oldTexList; + public XSToon3.TextureList TexList; + private XSToon3.TextureList oldTexList; public string[] filters = new string[] {"Point (No Filtering)", "Bilinear", "Trilinear"}; public FilterMode filterMode = FilterMode.Bilinear; diff --git a/Editor/XSGradientEditor.cs b/Editor/XSGradientEditor.cs index 995abfd..5aeaf26 100644 --- a/Editor/XSGradientEditor.cs +++ b/Editor/XSGradientEditor.cs @@ -6,7 +6,7 @@ using System; using UnityEditorInternal; -namespace XSToon +namespace XSToon3 { public class XSGradientEditor : EditorWindow { @@ -266,7 +266,7 @@ public void OnGUI() } } drawHelpText(); - } + } Gradient reflessGradient(Gradient old_grad) { diff --git a/Editor/XSMultiGradient.cs b/Editor/XSMultiGradient.cs index 452c9d2..b9ba201 100644 --- a/Editor/XSMultiGradient.cs +++ b/Editor/XSMultiGradient.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using UnityEngine; -namespace XSToon +namespace XSToon3 { public class XSMultiGradient : ScriptableObject { public string uniqueName = "New Gradient"; diff --git a/Editor/XSReimportMyShadersPlease.cs b/Editor/XSReimportMyShadersPlease.cs index 5171eab..4bb042c 100644 --- a/Editor/XSReimportMyShadersPlease.cs +++ b/Editor/XSReimportMyShadersPlease.cs @@ -3,20 +3,20 @@ using UnityEngine; using UnityEditor; using System.IO; -namespace XSToon +namespace XSToon3 { - public class XSReimportMyShadersPlease : AssetPostprocessor + public class XSReimportMyShadersPlease : AssetPostprocessor { private static string xsFilePath = null; static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { - if (xsFilePath == null) + if (xsFilePath == null) { xsFilePath = XSStyles.findAssetPath(""); } foreach (string str in importedAssets) { - if (str.StartsWith(xsFilePath + "/Main/CGIncludes")) + if (str.StartsWith(xsFilePath + "/Main/CGIncludes")) { Debug.Log("XS CGInclude updated: " + str.Replace(xsFilePath + "/Main/CGIncludes/","")); string[] files = Directory.GetFiles(xsFilePath + "/Main/Shaders", "*.shader"); @@ -26,7 +26,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse } } - if (str.StartsWith(xsFilePath + "/Main/Patreon/CGIncludes")) + if (str.StartsWith(xsFilePath + "/Main/Patreon/CGIncludes")) { Debug.Log("XS CGInclude updated: " + str.Replace(xsFilePath + "/Main/Patreon/CGIncludes/","")); string[] files = Directory.GetFiles(xsFilePath + "/Main/Patreon/Shaders", "*.shader"); diff --git a/Editor/XSStyles.cs b/Editor/XSStyles.cs index 6df35d7..9b161c7 100644 --- a/Editor/XSStyles.cs +++ b/Editor/XSStyles.cs @@ -2,12 +2,12 @@ using UnityEditor; using UnityEngine; using System.IO; -namespace XSToon +namespace XSToon3 { [InitializeOnLoad] public class XSStyles : MonoBehaviour { - public static string ver = "2.6"; + public static string ver = "3.0"; //Help URLs public static string mainURL = "https://docs.google.com/document/d/1xJ4PID_nwqVm_UCsO2c2gEdiEoWoCGeM_GDK_L8-aZE/edit#bookmark=id.xh0nk8x7ws1g"; diff --git a/Editor/XSTextureMerger.cs b/Editor/XSTextureMerger.cs index 3416d41..b8d17a7 100644 --- a/Editor/XSTextureMerger.cs +++ b/Editor/XSTextureMerger.cs @@ -3,7 +3,7 @@ using UnityEditor; using System.Collections; using System.IO; -namespace XSToon +namespace XSToon3 { public class XSTextureMerger : EditorWindow { @@ -62,7 +62,7 @@ static public void Init() public void OnGUI() { scrollPos = EditorGUILayout.BeginScrollView(scrollPos); - + GUILayout.BeginHorizontal(); GUILayout.Space(105); XSStyles.doLabel("1"); @@ -125,20 +125,20 @@ public void OnGUI() invertChannel[i] = EditorGUILayout.Toggle("", invertChannel[i]); } GUILayout.EndHorizontal(); - + GUILayout.Space(20); EditorGUILayout.EndScrollView(); //Button and Resolution GUILayout.BeginVertical(); XSStyles.doLabel("Resolution"); - + GUILayout.BeginHorizontal(); GUILayout.Space(175); res = (resolutions)EditorGUILayout.EnumPopup("", res); GUILayout.Space(175); GUILayout.EndHorizontal(); - + if(GUILayout.Button("Merge Channels")) { if (progress < 2) @@ -161,7 +161,7 @@ public void OnGUI() texture.SaveAndReimport(); } } - + switch(res) { case resolutions.Tiny_256x256: @@ -192,7 +192,7 @@ public void OnGUI() XSStyles.findAssetPath(finalFilePath); finalFilePath = EditorUtility.SaveFilePanel("Save Merged Texture", finalFilePath + "/Textures/", "mergedTex.png", "png"); - + Texture2D newTexture = new Texture2D(resolution, resolution, TextureFormat.RGBA32, false); //Get Colors textures and write them to the proper channel @@ -203,7 +203,7 @@ public void OnGUI() { float u = x / (float)resolution; float v = y / (float)resolution; - + // Grab out the texture values into an array for later lookup. Could probably just be done at the moment the texture color is needed. for(int i = 0; i < textures.Length; i++) { @@ -216,29 +216,29 @@ public void OnGUI() texColors[i] = new Color(0, 0, 0, 1); } } - + Color outputColor = new Color(0, 0, 0, 1); - + // Iterate the output RGBA channels for (int i = 0; i < 4; i++) - { + { // Convert the enums to indices we can use. 'None' will turn into -1 which will be discarded as invalid. int srcTexIdx = ((int)pickTexture[i]) - 1; int srcChannelIdx = ((int)texChannels[i]) - 1; - + // Go through each channel in the output color and assign it if (srcTexIdx >= 0 && srcChannelIdx >= 0) { outputColor[i] = texColors[srcTexIdx][srcChannelIdx]; - - //Allow you to invert specific channels. + + //Allow you to invert specific channels. if (invertChannel[i]) { outputColor[i] = 1f - outputColor[i]; } } - } - + } + newTexture.SetPixel(x, y, outputColor); } } @@ -246,11 +246,11 @@ public void OnGUI() newTexture.Apply(); ExportTexture(newTexture); } - + GUILayout.Space(10); GUILayout.EndVertical(); - + EditorGUIUtility.labelWidth = oldLabelWidth; } diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 28f802c..40b0732 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -6,7 +6,7 @@ using System; using System.Reflection; -namespace XSToon +namespace XSToon3 { public class FoldoutToggles { @@ -150,6 +150,9 @@ public class XSToonInspector : ShaderGUI private MaterialProperty _WireWidth = null; private MaterialProperty _EmissionAudioLinkChannel = null; + private MaterialProperty _ALGradientOnRed = null; + private MaterialProperty _ALGradientOnGreen = null; + private MaterialProperty _ALGradientOnBlue = null; //Experimenting private MaterialProperty _DissolveBlendPower = null; @@ -266,20 +269,19 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro } DrawMainSettings(materialEditor, material); + DrawFurSettings(materialEditor, material); DrawDissolveSettings(materialEditor, material); DrawShadowSettings(materialEditor, material); DrawOutlineSettings(materialEditor, material); DrawNormalSettings(materialEditor, material); DrawSpecularSettings(materialEditor, material); DrawReflectionsSettings(materialEditor, material); - // DrawAudioLinkSettings(materialEditor, material); DrawEmissionSettings(materialEditor, material); DrawRimlightSettings(materialEditor, material); DrawHalfToneSettings(materialEditor, material); DrawTransmissionSettings(materialEditor, material); DrawAdvancedSettings(materialEditor, material); DrawPatreonSettings(materialEditor, material); - DrawFurSettings(materialEditor, material); //!RDPSFunctionCallInject @@ -623,14 +625,21 @@ private void DrawEmissionSettings(MaterialEditor materialEditor, Material materi } else { - materialEditor.ColorProperty(_EmissionColor, "Red Ch. Color (Bass)"); - materialEditor.ColorProperty(_EmissionColor0, "Green Ch. Color (Mids)"); - materialEditor.ColorProperty(_EmissionColor1, "Blue Ch. Color (Highs)"); - - materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map", "Emissive map. White to black, unless you want multiple colors. Setting to Packed Map for Audio Link will change the color per channel."), _EmissionMap); + materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map (VRC Audio Link Packed)", "Emissive map. Each channel controls different audio link reactions. RGB = Lows, Mids, Highs"), _EmissionMap); materialEditor.TextureScaleOffsetProperty(_EmissionMap); materialEditor.ShaderProperty(_UVSetEmission, new GUIContent("UV Set", "The UV set to use for the Emission Map"), 2); materialEditor.ShaderProperty(_EmissionToDiffuse, new GUIContent("Tint To Diffuse", "Tints the emission to the Diffuse Color"), 2); + + XSStyles.SeparatorThin(); + + materialEditor.ColorProperty(_EmissionColor, "Red Ch. Color (Lows)"); + materialEditor.ShaderProperty(_ALGradientOnRed, new GUIContent("Gradient Bar", "Uses a gradient on this channel to create an animated bar from the audio link data."), 1); + + materialEditor.ColorProperty(_EmissionColor0, "Green Ch. Color (Mids)"); + materialEditor.ShaderProperty(_ALGradientOnGreen, new GUIContent("Gradient Bar", "Uses a gradient on this channel to create an animated bar from the audio link data."), 1); + + materialEditor.ColorProperty(_EmissionColor1, "Blue Ch. Color (Highs)"); + materialEditor.ShaderProperty(_ALGradientOnBlue, new GUIContent("Gradient Bar", "Uses a gradient on this channel to create an animated bar from the audio link data."), 1); } XSStyles.SeparatorThin(); diff --git a/Editor/XSUpdater.cs b/Editor/XSUpdater.cs index 347ccda..21992c4 100644 --- a/Editor/XSUpdater.cs +++ b/Editor/XSUpdater.cs @@ -3,7 +3,7 @@ using UnityEditor; using System.Collections.Generic; using System.IO; -namespace XSToon +namespace XSToon3 { public class XSUpdater : EditorWindow { @@ -18,12 +18,12 @@ static public void Init() private static string[] patrons = {}; private static string path; - + static int tab = 0; static string updateUrl = "https://api.github.com/repos/Xiexe/Xiexes-Unity-Shaders/releases/latest"; static string docsURL = "https://docs.google.com/document/d/1xJ4PID_nwqVm_UCsO2c2gEdiEoWoCGeM_GDK_L8-aZE"; static string patronsURL = "https://raw.githubusercontent.com/Xiexe/thefoxden/master/assets/patronlist/patronlist.txt"; - + static UnityWebRequest www; static string changelog; static string publishdate; @@ -43,12 +43,12 @@ public void OnGUI() XSStyles.doLabel("You can find Documentation here."); if(GUILayout.Button("Open Documentation")) Application.OpenURL(docsURL); - + break; - case 1: + case 1: EditorGUI.BeginChangeCheck(); - + XSStyles.HelpBox("The currently installed version is: v" + XSStyles.ver + "\n\nTo check for updates, use the update button. If you choose to download an update, you will need to manually overwrite the old install by extracting the .zip into the project using the windows explorer. \n\nDo not drag the update directly into Unity - it won't ask to overwrite - it'll just create a duplicate and break.", MessageType.Info); XSStyles.SeparatorThin(); if (GUILayout.Button("Check for Updates")) @@ -59,32 +59,32 @@ public void OnGUI() } if(showInfo){ - + scrollPos = EditorGUILayout.BeginScrollView(scrollPos); Repaint(); XSStyles.doLabelLeft("Newest version: "); XSStyles.doLabelSmall(curVer); XSStyles.SeparatorThin(); - + XSStyles.doLabelLeft("Release Date: "); XSStyles.doLabelSmall(publishdate); XSStyles.SeparatorThin(); - + XSStyles.doLabelLeft("Changelog: "); XSStyles.doLabelSmall(changelog); - + EditorGUILayout.EndScrollView(); XSStyles.SeparatorThin(); if (GUILayout.Button("Download")){ Application.OpenURL(downloadLink); } - + } else{ XSStyles.doLabel("Hit 'Check for Updates' to begin"); } EditorGUI.EndChangeCheck(); - + break; case 2: @@ -96,8 +96,8 @@ public void OnGUI() XSStyles.SeparatorThin(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); if(!hasCalledPatronlist) - { - hasCalledPatronlist = true; + { + hasCalledPatronlist = true; req(patronsURL); EditorApplication.update += EditorUpdate; } @@ -118,8 +118,8 @@ public void OnGUI() EditorGUILayout.EndHorizontal(); break; } - - + + } static void req(string url) @@ -139,7 +139,7 @@ static void EditorUpdate() { patrons = www.downloadHandler.text.Split('\n'); Debug.Log("Fetching Patron list of: " + patrons.Length); - } + } EditorApplication.update -= EditorUpdate; } @@ -172,20 +172,20 @@ static void changelogEditorUpdate() Debug.Log(www.error); else fetchChangelog(www.downloadHandler.text); - + EditorApplication.update -= changelogEditorUpdate; } static void fetchChangelog(string apiResult) { gitAPI git = JsonUtility.FromJson(apiResult); - + publishdate = git.published_at; curVer = git.tag_name; changelog = git.body; downloadLink = git.zipball_url; - //oldChangelog = - + //oldChangelog = + // Debug.Log(git.body); // Debug.Log(apiResult); // Debug.Log(git.tag_name); @@ -193,7 +193,7 @@ static void fetchChangelog(string apiResult) // Debug.Log(git.published_at); // Debug.Log(git.zipball_url); // Debug.Log(git.body); - + } public class gitAPI diff --git a/Main/CGIncludes/XSDefines.cginc b/Main/CGIncludes/XSDefines.cginc index 6e63e59..6b48bce 100644 --- a/Main/CGIncludes/XSDefines.cginc +++ b/Main/CGIncludes/XSDefines.cginc @@ -235,6 +235,7 @@ int _UVSetAlbedo, _UVSetNormal, _UVSetDetNormal, _UVSetEmission, _UVSetClipMap, _UVSetDissolve; int _NormalMapMode, _OutlineUVSelect; int _AlphaToMask; +int _ALGradientOnRed, _ALGradientOnGreen, _ALGradientOnBlue; //!RDPSDefines diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index be38f6f..8007279 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -401,11 +401,12 @@ half4 calcEmission(FragmentData i, TextureUV t, DotProducts d, half lightAvg) float audioDataMids = AudioLinkData(ALPASS_AUDIOLOWMIDS).x; float audioDataHighs = (AudioLinkData(ALPASS_AUDIOHIGHMIDS).x + AudioLinkData(ALPASS_AUDIOTREBLE).x) * 0.5; - float smoothsMids = smoothstep((1-audioDataMids), (1-audioDataMids) + (0.3 * fwidth(i.emissionMap.g)), i.emissionMap.g); - float smoothsHighs = smoothstep((1-audioDataHighs), (1-audioDataHighs) + (0.3 * fwidth(i.emissionMap.b)), i.emissionMap.b); - float4 emissionChannelRed = i.emissionMap.r * _EmissionColor * audioDataBass; - float4 emissionChannelGreen = smoothsMids * _EmissionColor0 * audioDataMids; - float4 emissionChannelBlue = smoothsHighs * _EmissionColor1 * audioDataHighs; + float smoothsLows = smoothstep((1-audioDataBass), (1-audioDataBass) + (0.5 * fwidth(i.emissionMap.r)), i.emissionMap.r); + float smoothsMids = smoothstep((1-audioDataMids), (1-audioDataMids) + (0.5 * fwidth(i.emissionMap.g)), i.emissionMap.g); + float smoothsHighs = smoothstep((1-audioDataHighs), (1-audioDataHighs) + (0.5 * fwidth(i.emissionMap.b)), i.emissionMap.b); + float4 emissionChannelRed = lerp(i.emissionMap.r, smoothsLows, _ALGradientOnRed) * _EmissionColor * audioDataBass; + float4 emissionChannelGreen = lerp(i.emissionMap.g, smoothsMids, _ALGradientOnGreen) * _EmissionColor0 * audioDataMids; + float4 emissionChannelBlue = lerp(i.emissionMap.b, smoothsHighs, _ALGradientOnBlue) * _EmissionColor1 * audioDataHighs; emission = (emissionChannelRed + emissionChannelGreen + emissionChannelBlue) * lerp(1, i.diffuseColor.rgbb, _EmissionToDiffuse); } } diff --git a/Main/Shaders/XSToon2.0.shader b/Main/Shaders/XSToon3.0.shader similarity index 98% rename from Main/Shaders/XSToon2.0.shader rename to Main/Shaders/XSToon3.0.shader index a8c8443..ae65492 100644 --- a/Main/Shaders/XSToon2.0.shader +++ b/Main/Shaders/XSToon3.0.shader @@ -1,4 +1,4 @@ -Shader "Xiexe/Toon2.0/XSToon2.0" +Shader "Xiexe/Toon3/XSToon3" { Properties { @@ -128,6 +128,9 @@ [Enum(UV1,0,UV2,1)] _UVSetDissolve("Dissolve Map UVs", Int) = 0 [Enum(None,0,Bass,1,Low Mids,2,High Mids,3,Treble,4,Packed Map,5)]_EmissionAudioLinkChannel("Emisssion Audio Link Channel", int) = 0 + [ToggleUI]_ALGradientOnRed("Gradient Red", Int) = 0 + [ToggleUI]_ALGradientOnGreen("Gradient Green", Int) = 0 + [ToggleUI]_ALGradientOnBlue("Gradient Blue", Int) = 0 [HDR]_EmissionColor("Emission Color", Color) = (0,0,0,0) [HDR]_EmissionColor0("Emission Packed Color 1", Color) = (0,0,0,0) [HDR]_EmissionColor1("Emission Packed Color 2", Color) = (0,0,0,0) @@ -276,5 +279,5 @@ } } Fallback "Diffuse" - CustomEditor "XSToon.XSToonInspector" + CustomEditor "XSToon3.XSToonInspector" } \ No newline at end of file diff --git a/Main/Shaders/XSToon2.0.shader.meta b/Main/Shaders/XSToon3.0.shader.meta similarity index 100% rename from Main/Shaders/XSToon2.0.shader.meta rename to Main/Shaders/XSToon3.0.shader.meta diff --git a/Main/Shaders/XSToon2.0_Outlined.shader b/Main/Shaders/XSToon3.0_Outlined.shader similarity index 97% rename from Main/Shaders/XSToon2.0_Outlined.shader rename to Main/Shaders/XSToon3.0_Outlined.shader index b843ff5..5622a34 100644 --- a/Main/Shaders/XSToon2.0_Outlined.shader +++ b/Main/Shaders/XSToon3.0_Outlined.shader @@ -1,4 +1,4 @@ -Shader "Xiexe/Toon2.0/XSToon2.0_Outlined" +Shader "Xiexe/Toon3/XSToon3_Outlined" { Properties { @@ -129,6 +129,9 @@ [Enum(UV1,0,UV2,1)] _UVSetDissolve("Dissolve Map UVs", Int) = 0 [Enum(None,0,Bass,1,Low Mids,2,High Mids,3,Treble,4,Packed Map,5)]_EmissionAudioLinkChannel("Emisssion Audio Link Channel", int) = 0 + [ToggleUI]_ALGradientOnRed("Gradient Red", Int) = 0 + [ToggleUI]_ALGradientOnGreen("Gradient Green", Int) = 0 + [ToggleUI]_ALGradientOnBlue("Gradient Blue", Int) = 0 [HDR]_EmissionColor("Emission Color", Color) = (0,0,0,0) [HDR]_EmissionColor0("Emission Packed Color 1", Color) = (0,0,0,0) [HDR]_EmissionColor1("Emission Packed Color 2", Color) = (0,0,0,0) @@ -286,5 +289,5 @@ } } Fallback "Diffuse" - CustomEditor "XSToon.XSToonInspector" + CustomEditor "XSToon3.XSToonInspector" } diff --git a/Main/Shaders/XSToon2.0_Outlined.shader.meta b/Main/Shaders/XSToon3.0_Outlined.shader.meta similarity index 100% rename from Main/Shaders/XSToon2.0_Outlined.shader.meta rename to Main/Shaders/XSToon3.0_Outlined.shader.meta diff --git a/Main/Test.mat.meta b/Main/Test.mat.meta deleted file mode 100644 index efbc651..0000000 --- a/Main/Test.mat.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 4dbcda476eefc6a4286ec65191ef2495 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 2100000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/XSToon 2.0 _ StippledHalftone.mat b/XSToon 2.0 _ StippledHalftone.mat deleted file mode 100644 index e122eb2..0000000 --- a/XSToon 2.0 _ StippledHalftone.mat +++ /dev/null @@ -1,156 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!21 &2100000 -Material: - serializedVersion: 6 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: XSToon 2.0 _ StippledHalftone - m_Shader: {fileID: 4800000, guid: 85c615217d617204cb497ae6838b8bae, type: 3} - m_ShaderKeywords: - m_LightmapFlags: 6 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _BakedCubemap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _BumpMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailMask: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailNormalMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _EmissionMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MainTex: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _Matcap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MetallicGlossMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _OcclusionMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _OutlineMask: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _Ramp: - m_Texture: {fileID: 2800000, guid: 529b95e318b684643b47bd73e037118a, type: 3} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _RampSelectionMask: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _ReflectivityMask: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _SpecularMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _ThicknessMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - m_Floats: - - _AdvMode: 0 - - _AnisotropicAX: 0.25 - - _AnisotropicAY: 0.75 - - _BumpScale: 1 - - _ClearCoat: 0 - - _ClearcoatSmoothness: 0.8 - - _ClearcoatStrength: 1 - - _Culling: 2 - - _Cutoff: 0.5 - - _DetailNormalMapScale: 1 - - _EmissionToDiffuse: 0 - - _Glossiness: 0 - - _HalftoneDotAmount: 50 - - _HalftoneDotSize: 1.7 - - _HalftoneLineAmount: 150 - - _HalftoneLineIntensity: 1 - - _HalftoneType: 3 - - _MatcapTintToDiffuse: 0 - - _Metallic: 0 - - _OutlineAlbedoTint: 0 - - _OutlineLighting: 0 - - _OutlineWidth: 1 - - _ReflectionBlendMode: 0 - - _ReflectionMode: 3 - - _Reflectivity: 1 - - _RimAlbedoTint: 0 - - _RimAttenEffect: 1 - - _RimCubemapTint: 0 - - _RimIntensity: 0 - - _RimRange: 0.7 - - _RimSharpness: 0.1 - - _RimThreshold: 0.1 - - _SSDistortion: 1 - - _SSPower: 1 - - _SSSRange: 1 - - _SSSSharpness: 0.2 - - _SSScale: 1 - - _Saturation: 1 - - _ScaleWithLight: 1 - - _ScaleWithLightSensitivity: 1 - - _ShadowRimAlbedoTint: 0 - - _ShadowRimRange: 0.7 - - _ShadowRimSharpness: 0.3 - - _ShadowRimThreshold: 0.1 - - _ShadowSharpness: 0.5 - - _SpecMode: 0 - - _SpecularAlbedoTint: 1 - - _SpecularArea: 0.5 - - _SpecularIntensity: 0 - - _SpecularStyle: 0 - - _Stencil: 0 - - _StencilComp: 0 - - _StencilOp: 0 - - _TilingMode: 0 - - _UVSetAlbedo: 0 - - _UVSetDetMask: 0 - - _UVSetDetNormal: 0 - - _UVSetEmission: 0 - - _UVSetMetallic: 0 - - _UVSetNormal: 0 - - _UVSetOcclusion: 0 - - _UVSetReflectivity: 0 - - _UVSetSpecular: 0 - - _UVSetThickness: 0 - - _VertexColorAlbedo: 0 - m_Colors: - - _Color: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} - - _MatcapTint: {r: 1, g: 1, b: 1, a: 1} - - _OcclusionColor: {r: 0, g: 0, b: 0, a: 0} - - _OutlineColor: {r: 0, g: 0, b: 0, a: 1} - - _RimColor: {r: 1, g: 1, b: 1, a: 1} - - _SSColor: {r: 0, g: 0, b: 0, a: 0} - - _ShadowRim: {r: 1, g: 1, b: 1, a: 1} diff --git a/XSToon 2.0 _ Carbon Fiber.mat b/XSToon 3.0 _ Carbon Fiber.mat similarity index 63% rename from XSToon 2.0 _ Carbon Fiber.mat rename to XSToon 3.0 _ Carbon Fiber.mat index 62d0573..4dfe751 100644 --- a/XSToon 2.0 _ Carbon Fiber.mat +++ b/XSToon 3.0 _ Carbon Fiber.mat @@ -4,9 +4,10 @@ Material: serializedVersion: 6 m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_Name: XSToon 2.0 _ Carbon Fiber + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: XSToon 3.0 _ Carbon Fiber m_Shader: {fileID: 4800000, guid: 85c615217d617204cb497ae6838b8bae, type: 3} m_ShaderKeywords: m_LightmapFlags: 4 @@ -26,6 +27,14 @@ Material: m_Texture: {fileID: 2800000, guid: 1632d2058ed6e554cae477f5a18dbcd6, type: 3} m_Scale: {x: 10, y: 10} m_Offset: {x: 0, y: 0} + - _ClipMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ClipMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _DetailAlbedoMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -38,10 +47,18 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _DissolveTexture: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _EmissionMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _HSVMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _MainTex: m_Texture: {fileID: 0} m_Scale: {x: 10, y: 10} @@ -88,18 +105,34 @@ Material: m_Offset: {x: 0, y: 0} m_Floats: - _AdvMode: 0 + - _AlphaToMask: 0 - _AnisotropicAX: 1 - _AnisotropicAY: 0.42 + - _AnisotropicReflection: 0 + - _AnisotropicSpecular: 0.39 + - _BlendMode: 0 - _BumpScale: 1 - _ClearCoat: 1 - _ClearcoatSmoothness: 0.907 - _ClearcoatStrength: 1 + - _ClipIndex: 0 - _ColorMask: 15 - _Culling: 0 - _Cutoff: 0.5 - _DetailNormalMapScale: 1 + - _DissolveBlendPower: 1 + - _DissolveCoordinates: 0 + - _DissolveLayer1Scale: 1 + - _DissolveLayer1Speed: 0 + - _DissolveLayer2Scale: 0.5 + - _DissolveLayer2Speed: 0 + - _DissolveProgress: 0 + - _DissolveStrength: 1 - _DstBlend: 0 + - _EmissionAudioLinkChannel: 0 - _EmissionToDiffuse: 0 + - _FadeDither: 0 + - _FadeDitherDistance: 0 - _GlossMapScale: 1 - _Glossiness: 0.6 - _GlossyReflections: 1 @@ -108,16 +141,31 @@ Material: - _HalftoneDotAmount: 50 - _HalftoneDotSize: 1.7 - _HalftoneLineAmount: 150 + - _HalftoneLineIntensity: 1 + - _HalftoneType: 3 + - _Hue: 0 + - _IOR: 0 - _Lambert: 0 + - _MatcapTintToDiffuse: 0 - _Metallic: 0 - _Mode: 0 + - _NormalMapMode: 0 + - _OcclusionIntensity: 1 + - _OcclusionMode: 0 - _OcclusionStrength: 1 + - _OutlineAlbedoTint: 0 + - _OutlineLighting: 0 + - _OutlineNormalMode: 0 + - _OutlineUVSelect: 2 - _OutlineWidth: 1 - _Parallax: 0.02 - _RampSampleMode: 0 - _ReflectionBlendMode: 0 - _ReflectionMode: 0 - _Reflectivity: 1 + - _RimAlbedoTint: 0 + - _RimAttenEffect: 1 + - _RimCubemapTint: 0 - _RimIntensity: 0 - _RimRange: 0.7 - _RimSharpness: 0.1 @@ -130,6 +178,7 @@ Material: - _Saturation: 1 - _ScaleWithLight: 1 - _ScaleWithLightSensitivity: 1 + - _ShadowRimAlbedoTint: 0 - _ShadowRimRange: 0.7 - _ShadowRimSharpness: 0 - _ShadowRimThreshold: 0.1 @@ -137,9 +186,10 @@ Material: - _SmoothnessTextureChannel: 0 - _SpecMode: 1 - _SpecularAlbedoTint: 0 - - _SpecularArea: 0.031 + - _SpecularArea: 0.312 - _SpecularHighlights: 1 - - _SpecularIntensity: 0.52 + - _SpecularIntensity: 0.05 + - _SpecularSharpness: 0 - _SpecularStyle: 0 - _SrcBlend: 1 - _Stencil: 0 @@ -150,8 +200,10 @@ Material: - _TilingMode: 1 - _UVSec: 0 - _UVSetAlbedo: 0 + - _UVSetClipMap: 0 - _UVSetDetMask: 0 - _UVSetDetNormal: 0 + - _UVSetDissolve: 0 - _UVSetEmission: 0 - _UVSetMetallic: 0 - _UVSetNormal: 0 @@ -159,10 +211,35 @@ Material: - _UVSetReflectivity: 0 - _UVSetSpecular: 0 - _UVSetThickness: 0 + - _UseClipsForDissolve: 0 + - _Value: 1 + - _VertexColorAlbedo: 0 + - _WireWidth: 0 - _ZWrite: 1 m_Colors: + - _ClipAgainstVertexColorGreaterZeroFive: {r: 1, g: 1, b: 1, a: 1} + - _ClipAgainstVertexColorLessZeroFive: {r: 1, g: 1, b: 1, a: 1} + - _ClipSlider00: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider01: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider02: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider03: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider04: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider05: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider06: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider07: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider08: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider09: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider10: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider11: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider12: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider13: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider14: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider15: {r: 0, g: 0, b: 0, a: 0} - _Color: {r: 0, g: 0, b: 0, a: 1} + - _DissolveColor: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} + - _EmissionColor0: {r: 0, g: 0, b: 0, a: 0} + - _EmissionColor1: {r: 0, g: 0, b: 0, a: 0} - _HSVAAdjust: {r: 3.29, g: 0, b: -0.22, a: 0} - _MatcapTint: {r: 1, g: 1, b: 1, a: 1} - _OcclusionColor: {r: 0, g: 0, b: 0, a: 0} @@ -170,3 +247,4 @@ Material: - _RimColor: {r: 1, g: 1, b: 1, a: 1} - _SSColor: {r: 0, g: 0, b: 0, a: 0} - _ShadowRim: {r: 1, g: 1, b: 1, a: 1} + - _WireColor: {r: 0, g: 0, b: 0, a: 0} diff --git a/XSToon 2.0 _ Carbon Fiber.mat.meta b/XSToon 3.0 _ Carbon Fiber.mat.meta similarity index 100% rename from XSToon 2.0 _ Carbon Fiber.mat.meta rename to XSToon 3.0 _ Carbon Fiber.mat.meta diff --git a/XSToon 2.0.mat b/XSToon 3.0 _ StippledHalftone.mat similarity index 80% rename from XSToon 2.0.mat rename to XSToon 3.0 _ StippledHalftone.mat index 119f34d..a8f4d60 100644 --- a/XSToon 2.0.mat +++ b/XSToon 3.0 _ StippledHalftone.mat @@ -7,16 +7,15 @@ Material: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: XSToon 2.0 + m_Name: XSToon 3.0 _ StippledHalftone m_Shader: {fileID: 4800000, guid: 85c615217d617204cb497ae6838b8bae, type: 3} m_ShaderKeywords: m_LightmapFlags: 6 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 2000 + m_CustomRenderQueue: -1 stringTagMap: {} - disabledShaderPasses: - - ALWAYS + disabledShaderPasses: [] m_SavedProperties: serializedVersion: 3 m_TexEnvs: @@ -32,6 +31,10 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _ClipMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _DetailMask: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -104,13 +107,20 @@ Material: - _ClearCoat: 0 - _ClearcoatSmoothness: 0.8 - _ClearcoatStrength: 1 + - _ClipIndex: 0 - _Culling: 2 - _Cutoff: 0.5 - _DetailNormalMapScale: 1 + - _DissolveBlendPower: 1 - _DissolveCoordinates: 0 + - _DissolveLayer1Scale: 1 + - _DissolveLayer1Speed: 0 + - _DissolveLayer2Scale: 0.5 + - _DissolveLayer2Speed: 0 - _DissolveProgress: 0 - _DissolveStrength: 1 - _DstBlend: 0 + - _EmissionAudioLinkChannel: 0 - _EmissionToDiffuse: 0 - _FadeDither: 0 - _FadeDitherDistance: 0 @@ -135,7 +145,6 @@ Material: - _ReflectionBlendMode: 0 - _ReflectionMode: 3 - _Reflectivity: 1 - - _RefractionModel: 0 - _RimAlbedoTint: 0 - _RimAttenEffect: 1 - _RimCubemapTint: 0 @@ -180,19 +189,38 @@ Material: - _UVSetSpecular: 0 - _UVSetThickness: 0 - _UseClipsForDissolve: 0 - - _UseRefraction: 0 - _Value: 1 - _VertexColorAlbedo: 0 + - _WireWidth: 0 - _ZWrite: 1 m_Colors: - _ClipAgainstVertexColorGreaterZeroFive: {r: 1, g: 1, b: 1, a: 1} - _ClipAgainstVertexColorLessZeroFive: {r: 1, g: 1, b: 1, a: 1} + - _ClipSlider00: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider01: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider02: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider03: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider04: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider05: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider06: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider07: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider08: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider09: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider10: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider11: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider12: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider13: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider14: {r: 0, g: 0, b: 0, a: 0} + - _ClipSlider15: {r: 0, g: 0, b: 0, a: 0} - _Color: {r: 1, g: 1, b: 1, a: 1} - _DissolveColor: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} + - _EmissionColor0: {r: 0, g: 0, b: 0, a: 0} + - _EmissionColor1: {r: 0, g: 0, b: 0, a: 0} - _MatcapTint: {r: 1, g: 1, b: 1, a: 1} - _OcclusionColor: {r: 0, g: 0, b: 0, a: 0} - _OutlineColor: {r: 0, g: 0, b: 0, a: 1} - _RimColor: {r: 1, g: 1, b: 1, a: 1} - _SSColor: {r: 0, g: 0, b: 0, a: 0} - _ShadowRim: {r: 1, g: 1, b: 1, a: 1} + - _WireColor: {r: 0, g: 0, b: 0, a: 0} diff --git a/XSToon 2.0 _ StippledHalftone.mat.meta b/XSToon 3.0 _ StippledHalftone.mat.meta similarity index 100% rename from XSToon 2.0 _ StippledHalftone.mat.meta rename to XSToon 3.0 _ StippledHalftone.mat.meta diff --git a/Main/Test.mat b/XSToon 3.0.mat similarity index 90% rename from Main/Test.mat rename to XSToon 3.0.mat index cf618ee..24a79ff 100644 --- a/Main/Test.mat +++ b/XSToon 3.0.mat @@ -7,13 +7,13 @@ Material: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Test + m_Name: XSToon 3.0 m_Shader: {fileID: 4800000, guid: 85c615217d617204cb497ae6838b8bae, type: 3} - m_ShaderKeywords: _ALPHABLEND_ON - m_LightmapFlags: 4 + m_ShaderKeywords: + m_LightmapFlags: 6 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 3000 + m_CustomRenderQueue: 2000 stringTagMap: {} disabledShaderPasses: - ALWAYS @@ -99,9 +99,11 @@ Material: m_Floats: - _AdvMode: 0 - _AlphaToMask: 0 + - _AnisotropicAX: 0.25 + - _AnisotropicAY: 0.75 - _AnisotropicReflection: 0 - _AnisotropicSpecular: 0 - - _BlendMode: 4 + - _BlendMode: 0 - _BumpScale: 1 - _ClearCoat: 0 - _ClearcoatSmoothness: 0.8 @@ -118,14 +120,15 @@ Material: - _DissolveLayer2Speed: 0 - _DissolveProgress: 0 - _DissolveStrength: 1 - - _DstBlend: 10 + - _DstBlend: 0 + - _EmissionAudioLinkChannel: 0 - _EmissionToDiffuse: 0 - _FadeDither: 0 - _FadeDitherDistance: 0 - _Glossiness: 0 - - _HalftoneDotAmount: 5 - - _HalftoneDotSize: 0.5 - - _HalftoneLineAmount: 2000 + - _HalftoneDotAmount: 50 + - _HalftoneDotSize: 1.7 + - _HalftoneLineAmount: 150 - _HalftoneLineIntensity: 1 - _HalftoneType: 3 - _Hue: 0 @@ -142,7 +145,7 @@ Material: - _OutlineWidth: 1 - _ReflectionBlendMode: 0 - _ReflectionMode: 3 - - _Reflectivity: 0.5 + - _Reflectivity: 1 - _RefractionModel: 0 - _RimAlbedoTint: 0 - _RimAttenEffect: 1 @@ -153,6 +156,8 @@ Material: - _RimThreshold: 0.1 - _SSDistortion: 1 - _SSPower: 1 + - _SSSRange: 1 + - _SSSSharpness: 0.2 - _SSScale: 1 - _Saturation: 1 - _ScaleWithLight: 1 @@ -162,10 +167,12 @@ Material: - _ShadowRimSharpness: 0.3 - _ShadowRimThreshold: 0.1 - _ShadowSharpness: 0.5 + - _SpecMode: 0 - _SpecularAlbedoTint: 1 - _SpecularArea: 0.5 - _SpecularIntensity: 0 - _SpecularSharpness: 0 + - _SpecularStyle: 0 - _SrcBlend: 1 - _Stencil: 0 - _StencilComp: 0 @@ -188,7 +195,7 @@ Material: - _Value: 1 - _VertexColorAlbedo: 0 - _WireWidth: 0 - - _ZWrite: 0 + - _ZWrite: 1 m_Colors: - _ClipAgainstVertexColorGreaterZeroFive: {r: 1, g: 1, b: 1, a: 1} - _ClipAgainstVertexColorLessZeroFive: {r: 1, g: 1, b: 1, a: 1} @@ -208,10 +215,13 @@ Material: - _ClipSlider13: {r: 0, g: 0, b: 0, a: 0} - _ClipSlider14: {r: 0, g: 0, b: 0, a: 0} - _ClipSlider15: {r: 0, g: 0, b: 0, a: 0} - - _Color: {r: 0, g: 0, b: 0, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 1} - _DissolveColor: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} + - _EmissionColor0: {r: 0, g: 0, b: 0, a: 0} + - _EmissionColor1: {r: 0, g: 0, b: 0, a: 0} - _MatcapTint: {r: 1, g: 1, b: 1, a: 1} + - _OcclusionColor: {r: 0, g: 0, b: 0, a: 0} - _OutlineColor: {r: 0, g: 0, b: 0, a: 1} - _RimColor: {r: 1, g: 1, b: 1, a: 1} - _SSColor: {r: 0, g: 0, b: 0, a: 0} diff --git a/XSToon 2.0.mat.meta b/XSToon 3.0.mat.meta similarity index 100% rename from XSToon 2.0.mat.meta rename to XSToon 3.0.mat.meta From b5ee5deb7e4d5930818b410e224d99d7f8c089b7 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Thu, 27 May 2021 21:19:14 -0400 Subject: [PATCH 27/30] remove fwidth cus honestly the aliasing looks better :L --- Main/CGIncludes/XSLightingFunctions.cginc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index 8007279..bd5c536 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -401,9 +401,9 @@ half4 calcEmission(FragmentData i, TextureUV t, DotProducts d, half lightAvg) float audioDataMids = AudioLinkData(ALPASS_AUDIOLOWMIDS).x; float audioDataHighs = (AudioLinkData(ALPASS_AUDIOHIGHMIDS).x + AudioLinkData(ALPASS_AUDIOTREBLE).x) * 0.5; - float smoothsLows = smoothstep((1-audioDataBass), (1-audioDataBass) + (0.5 * fwidth(i.emissionMap.r)), i.emissionMap.r); - float smoothsMids = smoothstep((1-audioDataMids), (1-audioDataMids) + (0.5 * fwidth(i.emissionMap.g)), i.emissionMap.g); - float smoothsHighs = smoothstep((1-audioDataHighs), (1-audioDataHighs) + (0.5 * fwidth(i.emissionMap.b)), i.emissionMap.b); + float smoothsLows = smoothstep((1-audioDataBass), (1-audioDataBass) + 0.01, i.emissionMap.r); + float smoothsMids = smoothstep((1-audioDataMids), (1-audioDataMids) + 0.01, i.emissionMap.g); + float smoothsHighs = smoothstep((1-audioDataHighs), (1-audioDataHighs) + 0.01, i.emissionMap.b); float4 emissionChannelRed = lerp(i.emissionMap.r, smoothsLows, _ALGradientOnRed) * _EmissionColor * audioDataBass; float4 emissionChannelGreen = lerp(i.emissionMap.g, smoothsMids, _ALGradientOnGreen) * _EmissionColor0 * audioDataMids; float4 emissionChannelBlue = lerp(i.emissionMap.b, smoothsHighs, _ALGradientOnBlue) * _EmissionColor1 * audioDataHighs; From 7c8455c7e268bc9dd96952be429a2bf0f5d0bbd5 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Fri, 28 May 2021 00:40:27 -0400 Subject: [PATCH 28/30] add support for masking emission with alpha to fix aliasing issues --- Main/CGIncludes/XSHelperFunctions.cginc | 2 ++ Main/CGIncludes/XSLightingFunctions.cginc | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index edcb3d4..2ae706c 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -444,4 +444,6 @@ half LineHalftone(FragmentData i, half scalar) return saturate(lineMask); } + +float flength(float i) { return length(float2(ddx(i), ddy(i))); } // \ No newline at end of file diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index bd5c536..902795f 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -401,12 +401,13 @@ half4 calcEmission(FragmentData i, TextureUV t, DotProducts d, half lightAvg) float audioDataMids = AudioLinkData(ALPASS_AUDIOLOWMIDS).x; float audioDataHighs = (AudioLinkData(ALPASS_AUDIOHIGHMIDS).x + AudioLinkData(ALPASS_AUDIOTREBLE).x) * 0.5; - float smoothsLows = smoothstep((1-audioDataBass), (1-audioDataBass) + 0.01, i.emissionMap.r); - float smoothsMids = smoothstep((1-audioDataMids), (1-audioDataMids) + 0.01, i.emissionMap.g); - float smoothsHighs = smoothstep((1-audioDataHighs), (1-audioDataHighs) + 0.01, i.emissionMap.b); - float4 emissionChannelRed = lerp(i.emissionMap.r, smoothsLows, _ALGradientOnRed) * _EmissionColor * audioDataBass; - float4 emissionChannelGreen = lerp(i.emissionMap.g, smoothsMids, _ALGradientOnGreen) * _EmissionColor0 * audioDataMids; - float4 emissionChannelBlue = lerp(i.emissionMap.b, smoothsHighs, _ALGradientOnBlue) * _EmissionColor1 * audioDataHighs; + float tLow = smoothstep((1-audioDataBass), (1-audioDataBass) + 0.05, i.emissionMap.r) * i.emissionMap.a; + float tMid = smoothstep((1-audioDataMids), (1-audioDataMids) + 0.05, i.emissionMap.g) * i.emissionMap.a; + float tHigh = smoothstep((1-audioDataHighs), (1-audioDataHighs) + 0.05, i.emissionMap.b) * i.emissionMap.a; + + float4 emissionChannelRed = lerp(i.emissionMap.r, tLow, _ALGradientOnRed) * _EmissionColor * audioDataBass; + float4 emissionChannelGreen = lerp(i.emissionMap.g, tMid, _ALGradientOnGreen) * _EmissionColor0 * audioDataMids; + float4 emissionChannelBlue = lerp(i.emissionMap.b, tHigh, _ALGradientOnBlue) * _EmissionColor1 * audioDataHighs; emission = (emissionChannelRed + emissionChannelGreen + emissionChannelBlue) * lerp(1, i.diffuseColor.rgbb, _EmissionToDiffuse); } } From 6cf1f6f0013c91aba688fd68750f962aabf71698 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Fri, 28 May 2021 01:05:03 -0400 Subject: [PATCH 29/30] change falloff on smoothstep to be sharper because lol --- Main/CGIncludes/XSLightingFunctions.cginc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Main/CGIncludes/XSLightingFunctions.cginc b/Main/CGIncludes/XSLightingFunctions.cginc index 902795f..645aed4 100644 --- a/Main/CGIncludes/XSLightingFunctions.cginc +++ b/Main/CGIncludes/XSLightingFunctions.cginc @@ -401,9 +401,9 @@ half4 calcEmission(FragmentData i, TextureUV t, DotProducts d, half lightAvg) float audioDataMids = AudioLinkData(ALPASS_AUDIOLOWMIDS).x; float audioDataHighs = (AudioLinkData(ALPASS_AUDIOHIGHMIDS).x + AudioLinkData(ALPASS_AUDIOTREBLE).x) * 0.5; - float tLow = smoothstep((1-audioDataBass), (1-audioDataBass) + 0.05, i.emissionMap.r) * i.emissionMap.a; - float tMid = smoothstep((1-audioDataMids), (1-audioDataMids) + 0.05, i.emissionMap.g) * i.emissionMap.a; - float tHigh = smoothstep((1-audioDataHighs), (1-audioDataHighs) + 0.05, i.emissionMap.b) * i.emissionMap.a; + float tLow = smoothstep((1-audioDataBass), (1-audioDataBass) + 0.01, i.emissionMap.r) * i.emissionMap.a; + float tMid = smoothstep((1-audioDataMids), (1-audioDataMids) + 0.01, i.emissionMap.g) * i.emissionMap.a; + float tHigh = smoothstep((1-audioDataHighs), (1-audioDataHighs) + 0.01, i.emissionMap.b) * i.emissionMap.a; float4 emissionChannelRed = lerp(i.emissionMap.r, tLow, _ALGradientOnRed) * _EmissionColor * audioDataBass; float4 emissionChannelGreen = lerp(i.emissionMap.g, tMid, _ALGradientOnGreen) * _EmissionColor0 * audioDataMids; From 11cebe9b6812aeedffecb2df7c0c4ceaf27e41a5 Mon Sep 17 00:00:00 2001 From: Xiexe Date: Fri, 28 May 2021 16:11:52 -0400 Subject: [PATCH 30/30] fix a tooltip --- Editor/XSToonInspector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 40b0732..79b8865 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -625,7 +625,7 @@ private void DrawEmissionSettings(MaterialEditor materialEditor, Material materi } else { - materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map (VRC Audio Link Packed)", "Emissive map. Each channel controls different audio link reactions. RGB = Lows, Mids, Highs"), _EmissionMap); + materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map (VRC Audio Link Packed)", "Emissive map. Each channel controls different audio link reactions. RGB = Lows, Mids, Highs, Alpha Channel can be used to have extra masking as a way to combat aliasing"), _EmissionMap); materialEditor.TextureScaleOffsetProperty(_EmissionMap); materialEditor.ShaderProperty(_UVSetEmission, new GUIContent("UV Set", "The UV set to use for the Emission Map"), 2); materialEditor.ShaderProperty(_EmissionToDiffuse, new GUIContent("Tint To Diffuse", "Tints the emission to the Diffuse Color"), 2);