From 65457e263644c36cd772ad1f42fb9fb3f84ab753 Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Thu, 27 Feb 2025 17:35:08 +0900 Subject: [PATCH] feat: support `SoftMaskForUGUI ` package with `UIEffect` This feature allow `UIEffect` component to automatically select shaders like 'UIEffect-SoftMaskable' without any manual configuration. close #270 --- .../TextMeshPro_ExtraShaders.unity | 752 +++++++++++++++++- .../RemoveSoftMaskableVariantsIfNeeded.cs | 35 + ...RemoveSoftMaskableVariantsIfNeeded.cs.meta | 12 + .../Editor/UIEffectProjectSettingsEditor.cs | 7 +- Packages/src/README.md | 22 + .../Utilities/ShaderSampleImporter.cs | 172 ++++ .../Utilities/ShaderSampleImporter.cs.meta | 11 + .../Utilities/ShaderVariantRegistry.cs | 136 ++-- Packages/src/Runtime/UIEffectBase.cs | 19 +- .../src/Runtime/UIEffectProjectSettings.cs | 112 ++- Packages/src/Runtime/Utilities/TmpProxy.cs | 5 +- ...n-TMP_Bitmap-Mobile-UIEffect-Unity6.shader | 28 +- ..._Bitmap-Mobile-UIEffect-Unity6.shader.meta | 4 +- .../Hidden-TMP_Bitmap-UIEffect-Unity6.shader | 28 +- ...den-TMP_Bitmap-UIEffect-Unity6.shader.meta | 4 +- ...dden-TMP_SDF-Mobile-UIEffect-Unity6.shader | 37 +- ...TMP_SDF-Mobile-UIEffect-Unity6.shader.meta | 4 +- .../Hidden-TMP_SDF-UIEffect-Unity6.shader | 36 +- ...Hidden-TMP_SDF-UIEffect-Unity6.shader.meta | 4 +- .../Hidden-TMP_Bitmap-Mobile-UIEffect.shader | 37 +- ...den-TMP_Bitmap-Mobile-UIEffect.shader.meta | 2 +- .../Hidden-TMP_Bitmap-UIEffect.shader | 40 +- .../Hidden-TMP_Bitmap-UIEffect.shader.meta | 2 +- .../Hidden-TMP_SDF-Mobile-UIEffect.shader | 38 +- ...Hidden-TMP_SDF-Mobile-UIEffect.shader.meta | 2 +- .../Hidden-TMP_SDF-UIEffect.shader | 28 +- .../Hidden-TMP_SDF-UIEffect.shader.meta | 2 +- Packages/src/Shaders/UIEffect.cginc | 2 + Packages/src/Shaders/UIEffect.shader | 36 +- 29 files changed, 1424 insertions(+), 193 deletions(-) create mode 100644 Packages/src/Editor/RemoveSoftMaskableVariantsIfNeeded.cs create mode 100644 Packages/src/Editor/RemoveSoftMaskableVariantsIfNeeded.cs.meta create mode 100644 Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs create mode 100644 Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs.meta diff --git a/Assets/Demos/TextMeshPro Support/TextMeshPro_ExtraShaders.unity b/Assets/Demos/TextMeshPro Support/TextMeshPro_ExtraShaders.unity index efb27e2..5a6cd09 100644 --- a/Assets/Demos/TextMeshPro Support/TextMeshPro_ExtraShaders.unity +++ b/Assets/Demos/TextMeshPro Support/TextMeshPro_ExtraShaders.unity @@ -123,6 +123,43 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &10648190 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 10648191} + m_Layer: 5 + m_Name: Overlay Mobile + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &10648191 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 10648190} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1104939386} + m_Father: {fileID: 795204878} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &35634202 GameObject: m_ObjectHideFlags: 0 @@ -485,7 +522,7 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 114739998} m_CullTransparentMesh: 1 ---- !u!1 &368143712 +--- !u!1 &162579139 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -493,34 +530,302 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 368143713} + - component: {fileID: 162579140} + - component: {fileID: 162579143} + - component: {fileID: 162579142} + - component: {fileID: 162579141} m_Layer: 5 - m_Name: Space + m_Name: TITLE m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!224 &368143713 +--- !u!224 &162579140 RectTransform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 368143712} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_GameObject: {fileID: 162579139} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 795204878} - m_RootOrder: 4 + m_Father: {fileID: 779059310} + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0.000015258789, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &162579141 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 162579139} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bcd162ab5f95d4f82a841acc1e950418, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Target: {fileID: 1887047861} + m_UseTargetTransform: 0 + m_SamplingScale: 1 + m_AllowToModifyMeshShape: 1 +--- !u!114 &162579142 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 162579139} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: SSD + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: bc6ef582a0efa420683ff976adff235a, type: 2} + m_sharedMaterial: {fileID: 2100000, guid: 06cd8c04a12a94e6084bc44a7e8454f6, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 71.4 + m_fontSizeBase: 36 + m_fontWeight: 400 + m_enableAutoSizing: 1 + m_fontSizeMin: 18 + m_fontSizeMax: 100 + m_fontStyle: 0 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 0 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &162579143 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 162579139} + m_CullTransparentMesh: 1 +--- !u!1 &252380787 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 252380788} + - component: {fileID: 252380791} + - component: {fileID: 252380790} + - component: {fileID: 252380789} + m_Layer: 5 + m_Name: TITLE + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &252380788 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 252380787} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1563788056} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0.000015258789, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &252380789 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 252380787} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bcd162ab5f95d4f82a841acc1e950418, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Target: {fileID: 1887047861} + m_UseTargetTransform: 0 + m_SamplingScale: 1 + m_AllowToModifyMeshShape: 1 +--- !u!114 &252380790 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 252380787} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: Overlay + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: bc6ef582a0efa420683ff976adff235a, type: 2} + m_sharedMaterial: {fileID: 2100000, guid: cb2000f2042fb4545b8af94316e74dbc, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 71.4 + m_fontSizeBase: 36 + m_fontWeight: 400 + m_enableAutoSizing: 1 + m_fontSizeMin: 18 + m_fontSizeMax: 100 + m_fontStyle: 0 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 0 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &252380791 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 252380787} + m_CullTransparentMesh: 1 --- !u!21 &509591527 Material: serializedVersion: 8 @@ -715,6 +1020,43 @@ MonoBehaviour: m_UseTargetTransform: 0 m_SamplingScale: 1 m_AllowToModifyMeshShape: 1 +--- !u!1 &622625912 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 622625913} + m_Layer: 5 + m_Name: SSD Mobile + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &622625913 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 622625912} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 790108298} + m_Father: {fileID: 795204878} + m_RootOrder: 7 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &632405357 GameObject: m_ObjectHideFlags: 0 @@ -842,6 +1184,195 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 632405357} m_CullTransparentMesh: 1 +--- !u!1 &779059309 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 779059310} + m_Layer: 5 + m_Name: SSD + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &779059310 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 779059309} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 162579140} + m_Father: {fileID: 795204878} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &790108297 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 790108298} + - component: {fileID: 790108301} + - component: {fileID: 790108300} + - component: {fileID: 790108299} + m_Layer: 5 + m_Name: TITLE + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &790108298 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 790108297} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 622625913} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &790108299 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 790108297} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bcd162ab5f95d4f82a841acc1e950418, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Target: {fileID: 1887047861} + m_UseTargetTransform: 0 + m_SamplingScale: 1 + m_AllowToModifyMeshShape: 1 +--- !u!114 &790108300 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 790108297} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: SSD Mobile + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: bc6ef582a0efa420683ff976adff235a, type: 2} + m_sharedMaterial: {fileID: 2100000, guid: 9426c45abd5c54484b10707936c04ade, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 71.25 + m_fontSizeBase: 36 + m_fontWeight: 400 + m_enableAutoSizing: 1 + m_fontSizeMin: 18 + m_fontSizeMax: 100 + m_fontStyle: 0 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 0 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &790108301 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 790108297} + m_CullTransparentMesh: 1 --- !u!1 &795204877 GameObject: m_ObjectHideFlags: 0 @@ -878,7 +1409,10 @@ RectTransform: - {fileID: 1489226064} - {fileID: 1044616015} - {fileID: 1530152937} - - {fileID: 368143713} + - {fileID: 1563788056} + - {fileID: 10648191} + - {fileID: 779059310} + - {fileID: 622625913} m_Father: {fileID: 1887047860} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1261,6 +1795,158 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &1104939385 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1104939386} + - component: {fileID: 1104939389} + - component: {fileID: 1104939388} + - component: {fileID: 1104939387} + m_Layer: 5 + m_Name: TITLE + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1104939386 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1104939385} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 10648191} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1104939387 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1104939385} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bcd162ab5f95d4f82a841acc1e950418, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Target: {fileID: 1887047861} + m_UseTargetTransform: 0 + m_SamplingScale: 1 + m_AllowToModifyMeshShape: 1 +--- !u!114 &1104939388 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1104939385} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: Overlay Mobile + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: bc6ef582a0efa420683ff976adff235a, type: 2} + m_sharedMaterial: {fileID: 2100000, guid: 5a5cc54c1f12241ff8d794ef8ca1c16e, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 52 + m_fontSizeBase: 36 + m_fontWeight: 400 + m_enableAutoSizing: 1 + m_fontSizeMin: 18 + m_fontSizeMax: 100 + m_fontStyle: 0 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 0 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &1104939389 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1104939385} + m_CullTransparentMesh: 1 --- !u!1 &1339549413 GameObject: m_ObjectHideFlags: 0 @@ -1447,6 +2133,43 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &1563788055 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1563788056} + m_Layer: 5 + m_Name: Overlay + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1563788056 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1563788055} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 252380788} + m_Father: {fileID: 795204878} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &1612340793 GameObject: m_ObjectHideFlags: 0 @@ -1649,6 +2372,8 @@ MonoBehaviour: m_GradationMode: 0 m_GradationColor1: {r: 1, g: 1, b: 1, a: 1} m_GradationColor2: {r: 1, g: 1, b: 1, a: 1} + m_GradationColor3: {r: 1, g: 1, b: 1, a: 1} + m_GradationColor4: {r: 1, g: 1, b: 1, a: 1} m_GradationGradient: serializedVersion: 2 key0: {r: 1, g: 1, b: 1, a: 1} @@ -1686,6 +2411,7 @@ MonoBehaviour: m_EdgeWidth: 0.5 m_EdgeColorFilter: 4 m_EdgeColor: {r: 1, g: 1, b: 1, a: 1} + m_EdgeShinyRate: 0.5 m_EdgeShinyWidth: 0.5 m_EdgeShinyAutoPlaySpeed: 1 m_PatternArea: 1 @@ -1723,13 +2449,13 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1887047859} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 3312d7739989d2b4e91e6319e9a96d76, type: 3} m_Name: m_EditorClassIdentifier: m_Padding: {x: 0, y: 0, z: 0, w: 0} - m_Softness: {x: 0, y: 0} + m_Softness: {x: 500, y: 0} --- !u!1 &1932217252 GameObject: m_ObjectHideFlags: 0 diff --git a/Packages/src/Editor/RemoveSoftMaskableVariantsIfNeeded.cs b/Packages/src/Editor/RemoveSoftMaskableVariantsIfNeeded.cs new file mode 100644 index 0000000..df502a8 --- /dev/null +++ b/Packages/src/Editor/RemoveSoftMaskableVariantsIfNeeded.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using UnityEditor.Build; +using UnityEditor.Rendering; +using UnityEngine; +using UnityEngine.Rendering; +using PackageInfo = UnityEditor.PackageManager.PackageInfo; + +namespace Coffee.UIEffects.Editors +{ + internal class RemoveSoftMaskableVariantsIfNeeded : IPreprocessShaders + { + public int callbackOrder => 1; + + // Remove the 'SOFTMASKABLE' variants if 'SoftMaskForUGUI' package is not installed. + public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList data) + { + // If the shader is not for UIEffect: skip. + if (!shader.name.EndsWith(" (UIEffect)")) return; + + // If the 'SoftMaskForUGUI' package is installed: skip. + if (PackageInfo.FindForAssetPath("Packages/com.coffee.softmask-for-ugui/package.json") != null) return; + + // Remove the 'SOFTMASKABLE' variants. + var softMaskable = new ShaderKeyword(shader, "SOFTMASKABLE"); + for (var i = data.Count - 1; i >= 0; i--) + { + var d = data[i]; + if (d.shaderKeywordSet.IsEnabled(softMaskable)) + { + data.RemoveAt(i); + } + } + } + } +} diff --git a/Packages/src/Editor/RemoveSoftMaskableVariantsIfNeeded.cs.meta b/Packages/src/Editor/RemoveSoftMaskableVariantsIfNeeded.cs.meta new file mode 100644 index 0000000..ee7b49e --- /dev/null +++ b/Packages/src/Editor/RemoveSoftMaskableVariantsIfNeeded.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e42595bbbad4941a686a82e328aa266b +timeCreated: 1487152293 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/src/Editor/UIEffectProjectSettingsEditor.cs b/Packages/src/Editor/UIEffectProjectSettingsEditor.cs index 1af583f..184b101 100644 --- a/Packages/src/Editor/UIEffectProjectSettingsEditor.cs +++ b/Packages/src/Editor/UIEffectProjectSettingsEditor.cs @@ -82,7 +82,12 @@ namespace Coffee.UIEffects.Editors if (_shaderVariantRegistryEditor == null) { var property = serializedObject.FindProperty("m_ShaderVariantRegistry"); - _shaderVariantRegistryEditor = new ShaderVariantRegistryEditor(property, "(UIEffect)"); + _shaderVariantRegistryEditor = new ShaderVariantRegistryEditor(property, "(UIEffect)", + () => + { + UIEffectProjectSettings.shaderRegistry + .RegisterOptionalShaders(UIEffectProjectSettings.instance); + }); } _shaderVariantRegistryEditor.Draw(); diff --git a/Packages/src/README.md b/Packages/src/README.md index bd9678d..d0f359c 100644 --- a/Packages/src/README.md +++ b/Packages/src/README.md @@ -40,6 +40,7 @@ Combine various filters, such as grayscale, blur, and dissolve, to decorate your - [Component: UIEffectTweener](#component-uieffecttweener) - [Component: UIEffectReplica](#component-uieffectreplica) - [Usage with TextMeshPro](#usage-with-textmeshpro) + - [Usage with SoftMaskForUGUI](#usage-with-softmaskforugui) - [Runtime/Editor Preset for UIEffect](#runtimeeditor-preset-for-uieffect) - [Usage with Code](#usage-with-code) - [Project Settings](#project-settings) @@ -343,6 +344,23 @@ Alternatively, you can manually import the resources by following these steps: > `TextMeshPro Support` may change with updates to the UIEffect package. > If issues occur, try importing it again. +> [!TIP] +> If you have moved `TMPro_Properties.cginc` and `TMPro.cginc` from their default install path +> (`Assets/TextMesh Pro/Shaders/...`), you will need to manually update the paths in the shaders under +> `TextMeshPro Support` or `TextMeshPro Support (Unity 6)`. + +

+ +### Usage with SoftMaskForUGUI + +![](https://github.com/user-attachments/assets/7701e765-896a-49a8-b1ed-22adb0ecce12) + +[SoftMaskForUGUI](https://github.com/mob-sakai/SoftMaskForUGUI) is a package that allows you to create soft masks for UI elements. + +`SoftMaskForUGUI (v3.3.0+)` supports `UIEffect (v5.6.0+)`. +When a shader included in the samples is requested, an import dialog will automatically appear. +Click the `Import` button. +

### Runtime/Editor Preset for UIEffect @@ -418,6 +436,10 @@ You can adjust the project-wide settings for UIEffect. (`Edit > Project Settings - **Error On Unregistered Variant**: If enabled, an error will be displayed when an unregistered shader variant is used. - The shader variant will be automatically added to the `Unregistered Variants` list. +> [!IMPORTANT] +> - The setting file is usually saved in `Assets/ProjectSettings/UIEffectProjectSettings.asset`. Include this file in your version control system. +> - The setting file is automatically added as a preloaded asset in `ProjectSettings/ProjectSettings.asset`. +

### :warning: Limitations diff --git a/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs b/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs new file mode 100644 index 0000000..290740c --- /dev/null +++ b/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs @@ -0,0 +1,172 @@ +#if UNITY_EDITOR +using System; +using System.Collections.Generic; +using System.IO; +using UnityEngine; +using System.Linq; +using UnityEditor; +using UnityEditor.PackageManager.UI; +using PackageInfo = UnityEditor.PackageManager.PackageInfo; + +namespace Coffee.UIEffectInternal +{ + internal static class ShaderSampleImporter + { + private static (string shaderName, string sampleName, string version)[] s_Samples; + private static (string guid, string fileName)[] s_DeprecatedShaders; + private static readonly Dictionary s_SampleNames = new Dictionary(); + private static readonly Dictionary s_ShaderAliases = new Dictionary(); + + public static void RegisterShaderSamples((string shaderName, string sampleName, string version)[] samples) + { + if (IsBatchOrBuilding()) return; + + // Collect sample names. + s_Samples = samples; + foreach (var (shaderName, sampleName, _) in samples) + { + s_SampleNames[shaderName] = sampleName; + } + } + + public static void RegisterShaderAliases((string, string)[] aliases) + { + foreach (var (from, to) in aliases) + { + s_ShaderAliases[from] = to; + } + } + + public static void RegisterDeprecatedShaders((string, string)[] deprecatedShaders) + { + if (IsBatchOrBuilding()) return; + + s_DeprecatedShaders = deprecatedShaders; + } + + /// + /// Import the sample containing the requested shader. + /// If choice 'Import' is selected, the sample is imported. + /// If choice 'Skip in this session' is selected, the sample is skipped in this session. + /// + public static bool ImportShaderIfSelected(string shaderName) + { + if (IsBatchOrBuilding()) return false; + + if (s_ShaderAliases.TryGetValue(shaderName, out var alias)) + { + shaderName = alias; + } + + // Find sample name. + if (s_SampleNames.TryGetValue(shaderName, out var sampleName)) + { + var message = $"Import the sample '{sampleName}' to use the shader '{shaderName}'."; + return ImportSampleIfSelected(sampleName, message); + } + + return false; + } + + private static bool ImportSampleIfSelected(string sampleName, string message) + { + if (IsBatchOrBuilding()) return false; + if (!s_SampleNames.ContainsValue(sampleName)) return false; + + // Find package info. + var pInfo = PackageInfo.FindForAssembly(typeof(ShaderSampleImporter).Assembly); + if (pInfo == null) return false; + + // Find sample. If not found (resolvedPath == null), skip. + var sample = Sample.FindByPackage(pInfo.name, pInfo.version) + .FirstOrDefault(x => x.displayName == sampleName); + if (sample.resolvedPath == null) return false; + + // Import the sample if selected. + if (!string.IsNullOrEmpty(message)) + { + var selected = EditorUtility.DisplayDialog($"Import {sampleName}", message, "Import", "Cancel"); + if (!selected) return false; + } + + // Remove the imported sample name from the list. + foreach (var shaderName in s_SampleNames.Keys.ToArray()) + { + if (s_SampleNames[shaderName] != sampleName) continue; + s_SampleNames.Remove(shaderName); + DeleteShader(shaderName); + } + + // Import the sample in the next frame. + EditorApplication.delayCall += () => sample.Import(Sample.ImportOptions.OverridePreviousImports); + return true; + } + + private static string GetVersion(string shaderName) + { + if (string.IsNullOrEmpty(shaderName)) return null; + + var shader = Shader.Find(shaderName); + if (!shader) return null; + + var path = AssetDatabase.GetAssetPath(shader); + if (string.IsNullOrEmpty(path)) return null; + + return AssetImporter.GetAtPath(path).userData; + } + + private static void DeleteShader(string shaderName) + { + var shader = Shader.Find(shaderName); + if (shader) + { + AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(shader)); + } + } + + private static bool IsBatchOrBuilding() + { + return Application.isBatchMode || BuildPipeline.isBuildingPlayer; + } + + public static void Update() + { + if (s_Samples == null || IsBatchOrBuilding()) return; + + // Find package info. + var pInfo = PackageInfo.FindForAssembly(typeof(ShaderSampleImporter).Assembly); + if (pInfo == null) return; + + // Find sample. If not found (resolvedPath == null), skip. + var sample = Sample.FindByPackage(pInfo.name, pInfo.version).FirstOrDefault(); + if (sample.resolvedPath == null) return; + + // Update the sample. + foreach (var (shaderName, sampleName, version) in s_Samples) + { + if (string.IsNullOrEmpty(version)) continue; + if (!s_SampleNames.ContainsValue(sampleName)) continue; + + // If the shader exist and the version is different, add the sample to the update list. + var currentVersion = GetVersion(shaderName); + if (currentVersion != null && currentVersion != version && ImportSampleIfSelected(sampleName, null)) + { + Debug.Log($"Updating '{sampleName}' to use the package '{pInfo.displayName} v{pInfo.version}'."); + } + } + + // Remove deprecated shaders. + foreach (var (guid, fileName) in s_DeprecatedShaders) + { + var path = AssetDatabase.GUIDToAssetPath(guid); + if (!string.IsNullOrEmpty(path) && Path.GetFileName(path) == fileName) + { + AssetDatabase.DeleteAsset(path); + } + } + + s_Samples = null; + } + } +} +#endif diff --git a/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs.meta b/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs.meta new file mode 100644 index 0000000..ff188b9 --- /dev/null +++ b/Packages/src/Runtime/Internal/Utilities/ShaderSampleImporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 763d620015bc94d7ab423f3b42aabf1e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs b/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs index 35a445e..7cd90de 100644 --- a/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs +++ b/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using UnityEditor; -using UnityEditor.PackageManager.UI; using UnityEditorInternal; using PackageInfo = UnityEditor.PackageManager.PackageInfo; using Object = UnityEngine.Object; @@ -63,6 +62,7 @@ namespace Coffee.UIEffectInternal #endif public ShaderVariantCollection shaderVariantCollection => m_Asset; + public Func onShaderRequested; public Shader FindOptionalShader(Shader shader, string requiredName, @@ -78,16 +78,16 @@ namespace Coffee.UIEffectInternal return Shader.Find(optionalShaderName); } - // The shader has - if (shader.name.Contains(requiredName)) + // The shader has required name. + var shaderName = shader.name; + if (shaderName.Contains(requiredName)) { - _cachedOptionalShaders[id] = shader.name; + _cachedOptionalShaders[id] = shaderName; return shader; } // Find optional shader. Shader optionalShader; - var shaderName = shader.name; foreach (var pair in m_OptionalShaders) { if (pair.key != shaderName) continue; @@ -100,7 +100,7 @@ namespace Coffee.UIEffectInternal } // Find optional shader by format. - optionalShaderName = string.Format(format, shader.name); + optionalShaderName = string.Format(format, shaderName); optionalShader = Shader.Find(optionalShaderName); if (optionalShader) { @@ -109,7 +109,10 @@ namespace Coffee.UIEffectInternal } #if UNITY_EDITOR - ImportFromSample(optionalShaderName); + if (onShaderRequested?.Invoke(optionalShaderName) ?? false) + { + return Shader.Find(defaultOptionalShaderName); + } #endif // Find default optional shader. @@ -119,83 +122,67 @@ namespace Coffee.UIEffectInternal #if UNITY_EDITOR private readonly HashSet _logVariants = new HashSet(); - private readonly Dictionary _sampleNames = new Dictionary(); - - /// - /// Import the sample containing the requested shader. - /// If choice 'Import' is selected, the sample is imported. - /// If choice 'Skip in this session' is selected, the sample is skipped in this session. - /// - public void ImportFromSample(string shaderName) - { - if (Misc.isBatchOrBuilding) return; - - // Find sample name. - if (_sampleNames.TryGetValue(shaderName, out var sampleName)) - { - // Find package info. - var pInfo = PackageInfo.FindForAssembly(typeof(ShaderVariantRegistry).Assembly); - if (pInfo == null) return; - - // Find sample. If not found (resolvedPath == null), skip. - var sample = Sample.FindByPackage(pInfo.name, pInfo.version) - .FirstOrDefault(x => x.displayName == sampleName); - if (sample.resolvedPath == null) return; - - // Import the sample if selected. - var importSelected = EditorUtility.DisplayDialog($"Import {sampleName}", - $"Import '{sampleName}' to use the shader '{shaderName}'", "Import", "Cancel"); - if (importSelected) - { - EditorApplication.delayCall += () => - { - sample.Import(); - }; - } - } - } public void ClearCache() { _cachedOptionalShaders.Clear(); } - public void RegisterSamples((string shaderName, string sampleName)[] samples) + /// + /// Register all optional shaders associated with the package. + /// If the shader file has a comment "// [OptionalShader] {packageName}: {shaderName}", it will be registered. + /// + public void RegisterOptionalShaders(Object owner) { - foreach (var (shaderName, sampleName) in samples) + var shaderPaths = ShaderUtil.GetAllShaderInfo() + .Select(s => AssetDatabase.GetAssetPath(Shader.Find(s.name))) + .Where(path => !string.IsNullOrEmpty(path) && path.EndsWith(".shader")) + .ToArray(); + foreach (var path in shaderPaths) { - _sampleNames[shaderName] = sampleName; + RegisterOptionalShaders(owner, path); } } - public void InitializeIfNeeded(Object owner, string optionalName) + /// + /// Register optional shaders associated with the package. + /// If the shader file has a comment "// [OptionalShader] {packageName}: {shaderName}", it will be registered. + /// + private void RegisterOptionalShaders(Object owner, string path) { - Profiler.BeginSample("(EDITOR/COF)[ShaderVariantRegistry] InitializeIfNeeded"); + if (!File.Exists(path) || !path.EndsWith(".shader")) return; + + var packageName = PackageInfo.FindForAssembly(typeof(ShaderVariantRegistry).Assembly)?.name; + if (string.IsNullOrEmpty(packageName)) return; // Register optional shader names by shader comment. - if (!string.IsNullOrEmpty(optionalName)) + var pattern = $"// \\[OptionalShader\\] {packageName}: (.*)$"; + var registeredKeys = new HashSet(m_OptionalShaders.Select(x => x.key)); + var keys = File.ReadLines(path) + .Take(10) + .Select(line => Regex.Match(line, pattern)) + .Where(match => match.Success && registeredKeys.Add(match.Groups[1].Value)) + .Select(match => match.Groups[1].Value) + .ToArray(); + if (0 < keys.Length) { - var optionalShaders = ShaderUtil.GetAllShaderInfo() - .Where(s => s.name.Contains(optionalName)) - .Select(s => (s.name, path: AssetDatabase.GetAssetPath(Shader.Find(s.name)))) - .Where(x => !string.IsNullOrEmpty(x.path)) - .SelectMany(x => - { - return File.ReadLines(x.path) - .Take(10) - .Where(line => line.Contains($"OptionalShader@{optionalName}")) - .Select(line => Regex.Match(line, @":\s*(.*)$")) - .Where(match => match.Success) - .Select(match => new StringPair() { key = match.Groups[1].Value, value = x.name }); - }) - .Where(pair => m_OptionalShaders.All(x => x.key != pair.key)) - .ToArray(); - if (0 < optionalShaders.Length) + // Find shader. + var shader = AssetDatabase.LoadAssetAtPath(path); + if (!shader) return; + + var shaderName = shader.name; + foreach (var key in keys) { - m_OptionalShaders.AddRange(optionalShaders); - EditorUtility.SetDirty(owner); + m_OptionalShaders.Add(new StringPair() { key = key, value = shaderName }); } + + EditorUtility.SetDirty(owner); } + } + + public void InitializeIfNeeded(Object owner) + { + Profiler.BeginSample("(EDITOR/COF)[ShaderVariantRegistry] InitializeIfNeeded"); if (!m_Asset && AssetDatabase.IsMainAsset(owner)) { @@ -286,7 +273,7 @@ namespace Coffee.UIEffectInternal private Editor _editor; private bool _expand; - public ShaderVariantRegistryEditor(SerializedProperty property, string optionName) + public ShaderVariantRegistryEditor(SerializedProperty property, string optionName, Action onFindOptions) { var so = property.serializedObject; var optionalShaders = property.FindPropertyRelative("m_OptionalShaders"); @@ -302,8 +289,14 @@ namespace Coffee.UIEffectInternal EditorGUIUtility.TrTextContent($"Optional Shaders {optionName}", "Specify optional shaders explicitly.")); - var rButton = new Rect(rect.x + rect.width - 80, rect.y, 80, rect.height - 4); - if (GUI.Button(rButton, "Clear All", EditorStyles.miniButton)) + var rButton1 = new Rect(rect.x + rect.width - 150, rect.y, 90, rect.height - 4); + if (GUI.Button(rButton1, "Find Options", EditorStyles.miniButton)) + { + onFindOptions?.Invoke(); + } + + var rButton2 = new Rect(rect.x + rect.width - 60, rect.y, 60, rect.height - 4); + if (GUI.Button(rButton2, "Clear All", EditorStyles.miniButton)) { optionalShaders.ClearArray(); } @@ -346,7 +339,7 @@ namespace Coffee.UIEffectInternal var rLabel = new Rect(rect.x + 20, rect.y, 200, rect.height); EditorGUI.LabelField(rLabel, "Unregistered Shader Variants"); - var rButton = new Rect(rect.x + rect.width - 80, rect.y, 80, rect.height - 4); + var rButton = new Rect(rect.x + rect.width - 60, rect.y, 60, rect.height - 4); if (GUI.Button(rButton, "Clear All", EditorStyles.miniButton)) { unregisteredVariants.ClearArray(); @@ -438,9 +431,10 @@ namespace Coffee.UIEffectInternal Editor.CreateCachedEditor(collection, null, ref editor); editor.serializedObject.Update(); var shaders = editor.serializedObject.FindProperty("m_Shaders"); + var drawShaderEntry = s_MiDrawShaderEntry?.CreateDelegate(typeof(Action), editor) as Action; for (var i = 0; i < shaders.arraySize; i++) { - s_MiDrawShaderEntry.Invoke(editor, new object[] { i }); + drawShaderEntry?.Invoke(i); } EditorGUILayout.EndVertical(); diff --git a/Packages/src/Runtime/UIEffectBase.cs b/Packages/src/Runtime/UIEffectBase.cs index 79d0171..51725e7 100644 --- a/Packages/src/Runtime/UIEffectBase.cs +++ b/Packages/src/Runtime/UIEffectBase.cs @@ -127,6 +127,7 @@ namespace Coffee.UIEffects Profiler.EndSample(); } + _material.CopyPropertiesFromMaterial(baseMaterial); ApplyContextToMaterial(_material); Profiler.EndSample(); return _material; @@ -165,9 +166,7 @@ namespace Coffee.UIEffects { graphic.SetVerticesDirty(); GraphicProxy.Find(graphic).SetVerticesDirty(graphic, enabled); -#if UNITY_EDITOR - EditorApplication.QueuePlayerLoopUpdate(); -#endif + Misc.QueuePlayerLoopUpdate(); } } @@ -185,12 +184,15 @@ namespace Coffee.UIEffects if (graphic) { graphic.SetMaterialDirty(); -#if UNITY_EDITOR - EditorApplication.QueuePlayerLoopUpdate(); -#endif + Misc.QueuePlayerLoopUpdate(); } } + internal void ReleaseMaterial() + { + MaterialRepository.Release(ref _material); + } + protected abstract void UpdateContext(UIEffectContext c); public virtual void ApplyContextToMaterial(Material material) @@ -198,13 +200,10 @@ namespace Coffee.UIEffects if (!isActiveAndEnabled || context == null || !material) return; context.ApplyToMaterial(material, actualSamplingScale); + Misc.QueuePlayerLoopUpdate(); #if UNITY_EDITOR UIEffectProjectSettings.shaderRegistry.RegisterVariant(material, "UI > UIEffect"); - if (!EditorApplication.isPlaying) - { - EditorApplication.QueuePlayerLoopUpdate(); - } #endif } diff --git a/Packages/src/Runtime/UIEffectProjectSettings.cs b/Packages/src/Runtime/UIEffectProjectSettings.cs index f39b0ad..f358922 100644 --- a/Packages/src/Runtime/UIEffectProjectSettings.cs +++ b/Packages/src/Runtime/UIEffectProjectSettings.cs @@ -73,62 +73,69 @@ namespace Coffee.UIEffects return null; } - protected override void OnEnable() - { - base.OnEnable(); -#if UNITY_EDITOR - SetupSamplesForShaderVariantRegistry(); - m_ShaderVariantRegistry.ClearCache(); -#endif - } - #if UNITY_EDITOR private const string k_PresetDir = "UIEffectPresets"; private const string k_PresetSaveDir = "Assets/ProjectSettings/" + k_PresetDir; private const string k_PresetPathPattern = "/" + k_PresetDir + "/(.*).prefab$"; + [InitializeOnLoadMethod] + private static void InitializeOnLoadMethod() + { +#if UNITY_2023_2_OR_NEWER + const string tmpSupport = "TextMeshPro Support (Unity 6)"; + const string version = "v5.6.0 (Unity 6)"; +#else + const string tmpSupport = "TextMeshPro Support"; + const string version = "v5.6.0"; +#endif + ShaderSampleImporter.RegisterShaderSamples(new[] + { + // TextMeshPro Support/TextMeshPro Support (Unity 6) + ("Hidden/TextMeshPro/Bitmap (UIEffect)", tmpSupport, version), + ("Hidden/TextMeshPro/Mobile/Bitmap (UIEffect)", tmpSupport, version), + ("Hidden/TextMeshPro/Distance Field (UIEffect)", tmpSupport, version), + ("Hidden/TextMeshPro/Mobile/Distance Field (UIEffect)", tmpSupport, version) + }); + ShaderSampleImporter.RegisterShaderAliases(new[] + { + ("Hidden/Hidden/TextMeshPro/Bitmap (SoftMaskable) (UIEffect)", "Hidden/TextMeshPro/Bitmap (UIEffect)"), + ("Hidden/Hidden/TextMeshPro/Mobile/Bitmap (SoftMaskable) (UIEffect)", "Hidden/TextMeshPro/Mobile/Bitmap (UIEffect)"), + ("Hidden/Hidden/TextMeshPro/Distance Field (SoftMaskable) (UIEffect)", "Hidden/TextMeshPro/Distance Field (UIEffect)"), + ("Hidden/Hidden/TextMeshPro/Mobile/Distance Field (SoftMaskable) (UIEffect)", "Hidden/TextMeshPro/Mobile/Distance Field (UIEffect)") + }); + ShaderSampleImporter.RegisterDeprecatedShaders(new[] + { + // Old shaders. + ("367310b4ca95c4b00a2215568f1af735", "Hidden-TMP_Bitmap-Mobile-UIEffect-Unity6.shader"), + ("490fe6c46146140cca8766a31c9dfc0c", "Hidden-TMP_Bitmap-UIEffect-Unity6.shader"), + ("b875fa74fa43a4c48a44634d5f3e6d3d", "Hidden-TMP_SDF-Mobile-UIEffect-Unity6.shader"), + ("c67f821adbb6348a3a21573a25b55de0", "Hidden-TMP_SDF-UIEffect-Unity6.shader") + }); + EditorApplication.update += ShaderSampleImporter.Update; + } + + protected override void OnEnable() + { + base.OnEnable(); + m_ShaderVariantRegistry.onShaderRequested = ShaderSampleImporter.ImportShaderIfSelected; + m_ShaderVariantRegistry.ClearCache(); + } + protected override void OnCreateAsset() { - m_ShaderVariantRegistry.InitializeIfNeeded(this, "(UIEffect)"); + m_ShaderVariantRegistry.InitializeIfNeeded(this); + m_ShaderVariantRegistry.RegisterOptionalShaders(this); } protected override void OnInitialize() { - m_ShaderVariantRegistry.InitializeIfNeeded(this, "(UIEffect)"); + m_ShaderVariantRegistry.InitializeIfNeeded(this); } private void Reset() { - m_ShaderVariantRegistry.InitializeIfNeeded(this, "(UIEffect)"); - } - - private void SetupSamplesForShaderVariantRegistry() - { -#if UNITY_2023_2_OR_NEWER - const string tmpSupport = "TextMeshPro Support (Unity 6)"; -#else - const string tmpSupport = "TextMeshPro Support"; -#endif - m_ShaderVariantRegistry.RegisterSamples(new[] - { - ("Hidden/TextMeshPro/Bitmap (UIEffect)", tmpSupport), - ("Hidden/TextMeshPro/Mobile/Bitmap (UIEffect)", tmpSupport), - ("Hidden/TextMeshPro/Distance Field (UIEffect)", tmpSupport), - ("Hidden/TextMeshPro/Mobile/Distance Field (UIEffect)", tmpSupport) - }); - } - - private void Refresh() - { - m_ShaderVariantRegistry.ClearCache(); - MaterialRepository.Clear(); - foreach (var c in Misc.FindObjectsOfType() - .Concat(Misc.GetAllComponentsInPrefabStage())) - { - c.SetMaterialDirty(); - } - - EditorApplication.QueuePlayerLoopUpdate(); + m_ShaderVariantRegistry.InitializeIfNeeded(this); + m_ShaderVariantRegistry.RegisterOptionalShaders(this); } internal static UIEffect[] LoadEditorPresets() @@ -180,11 +187,30 @@ namespace Coffee.UIEffects private class Postprocessor : AssetPostprocessor { - private static void OnPostprocessAllAssets(string[] _, string[] __, string[] ___, string[] ____) + private static void OnPostprocessAllAssets(string[] imported, string[] deleted, string[] ___, string[] ____) { if (Misc.isBatchOrBuilding) return; - instance.Refresh(); + // Register optional shaders when shaders are imported. + if (imported.Concat(deleted).Any(path => path.EndsWith(".shader"))) + { + MaterialRepository.Clear(); + + // Refresh + if (hasInstance) + { + shaderRegistry.ClearCache(); + shaderRegistry.RegisterOptionalShaders(instance); + } + + // Refresh all UIEffect instances. + foreach (var c in Misc.FindObjectsOfType() + .Concat(Misc.GetAllComponentsInPrefabStage())) + { + c.ReleaseMaterial(); + c.SetMaterialDirty(); + } + } } } #endif diff --git a/Packages/src/Runtime/Utilities/TmpProxy.cs b/Packages/src/Runtime/Utilities/TmpProxy.cs index a7555ee..f0b52cf 100644 --- a/Packages/src/Runtime/Utilities/TmpProxy.cs +++ b/Packages/src/Runtime/Utilities/TmpProxy.cs @@ -189,11 +189,14 @@ namespace Coffee.UIEffects foreach (var textMeshProUGUI in s_RegisteredInstances) { if (!textMeshProUGUI || !textMeshProUGUI.isActiveAndEnabled) continue; - if (textMeshProUGUI.TryGetComponent(out var effect) && effect.isActiveAndEnabled) + if (textMeshProUGUI.TryGetComponent(out var effect) && effect.isActiveAndEnabled) { + effect.ReleaseMaterial(); effect.SetMaterialDirty(); } } + + Misc.QueuePlayerLoopUpdate(); }; #endif } diff --git a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-Mobile-UIEffect-Unity6.shader b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-Mobile-UIEffect-Unity6.shader index fd346be..2f9071a 100755 --- a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-Mobile-UIEffect-Unity6.shader +++ b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-Mobile-UIEffect-Unity6.shader @@ -1,3 +1,5 @@ +// [OptionalShader] com.coffee.softmask-for-ugui: Hidden/TextMeshPro/Mobile/Bitmap (UIEffect) +// [OptionalShader] com.coffee.ui-effect: Hidden/TextMeshPro/Mobile/Bitmap (SoftMaskable) Shader "Hidden/TextMeshPro/Mobile/Bitmap (UIEffect)" { Properties { @@ -67,6 +69,14 @@ SubShader { #pragma shader_feature_local_fragment _ TARGET_HUE TARGET_LUMINANCE // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #pragma shader_feature _ SOFTMASK_EDITOR + #pragma shader_feature_local_fragment _ SOFTMASKABLE + #if SOFTMASKABLE + #include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" + #endif + // ==== SOFTMASKABLE END ==== + #include "UnityCG.cginc" #include "UnityUI.cginc" @@ -91,6 +101,11 @@ SubShader { float4 uvMask : TEXCOORD3; float2 uvLocal : TEXCOORD4; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + float4 worldPosition : TEXCOORD5; + #endif + // ==== SOFTMASKABLE END ==== }; sampler2D _MainTex; @@ -136,11 +151,16 @@ SubShader { OUT.uvLocal = v.texcoord1.zw; OUT.uvMask = v.texcoord2; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + OUT.worldPosition = v.vertex; + #endif + // ==== SOFTMASKABLE END ==== return OUT; } - // ==== UIEFFECT ==== + // ==== UIEFFECT START ==== v2f _fragInput; fixed4 uieffect_frag(float2 uv) { @@ -165,6 +185,12 @@ SubShader { color *= m.x * m.y; #endif + // ==== SOFTMASKABLE START ==== + #if SOFTMASKABLE + color *= SoftMask(IN.vertex, IN.worldPosition, color.a); + #endif + // ==== SOFTMASKABLE END ==== + #if UNITY_UI_ALPHACLIP clip(color.a - 0.001); #endif diff --git a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-Mobile-UIEffect-Unity6.shader.meta b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-Mobile-UIEffect-Unity6.shader.meta index 8615f28..e7e8d9c 100755 --- a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-Mobile-UIEffect-Unity6.shader.meta +++ b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-Mobile-UIEffect-Unity6.shader.meta @@ -1,9 +1,9 @@ fileFormatVersion: 2 -guid: 367310b4ca95c4b00a2215568f1af735 +guid: 63a1dba10bff94661a909d63808a9a3b ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] - userData: + userData: v5.6.0 (Unity 6) assetBundleName: assetBundleVariant: diff --git a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-UIEffect-Unity6.shader b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-UIEffect-Unity6.shader index f0a5c54..f71d05f 100755 --- a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-UIEffect-Unity6.shader +++ b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-UIEffect-Unity6.shader @@ -1,3 +1,5 @@ +// [OptionalShader] com.coffee.softmask-for-ugui: Hidden/TextMeshPro/Bitmap (UIEffect) +// [OptionalShader] com.coffee.ui-effect: Hidden/TextMeshPro/Bitmap (SoftMaskable) Shader "Hidden/TextMeshPro/Bitmap (UIEffect)" { Properties { @@ -66,6 +68,14 @@ SubShader{ #pragma shader_feature_local_fragment _ TARGET_HUE TARGET_LUMINANCE // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #pragma shader_feature _ SOFTMASK_EDITOR + #pragma shader_feature_local_fragment _ SOFTMASKABLE + #if SOFTMASKABLE + #include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" + #endif + // ==== SOFTMASKABLE END ==== + #include "UnityCG.cginc" #include "UnityUI.cginc" @@ -91,6 +101,11 @@ SubShader{ float4 uvMask : TEXCOORD3; float2 uvLocal : TEXCOORD4; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + float4 worldPosition : TEXCOORD5; + #endif + // ==== SOFTMASKABLE END ==== }; uniform sampler2D _MainTex; @@ -141,11 +156,16 @@ SubShader{ OUT.uvLocal = v.texcoord1.zw; OUT.uvMask = v.texcoord2; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + OUT.worldPosition = v.vertex; + #endif + // ==== SOFTMASKABLE END ==== return OUT; } - // ==== UIEFFECT ==== + // ==== UIEFFECT START ==== v2f _fragInput; fixed4 uieffect_frag(float2 uv) { @@ -171,6 +191,12 @@ SubShader{ color *= m.x * m.y; #endif + // ==== SOFTMASKABLE START ==== + #if SOFTMASKABLE + color *= SoftMask(IN.vertex, IN.worldPosition, color.a); + #endif + // ==== SOFTMASKABLE END ==== + #if UNITY_UI_ALPHACLIP clip(color.a - 0.001); #endif diff --git a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-UIEffect-Unity6.shader.meta b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-UIEffect-Unity6.shader.meta index c65560a..3bc104a 100755 --- a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-UIEffect-Unity6.shader.meta +++ b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_Bitmap-UIEffect-Unity6.shader.meta @@ -1,9 +1,9 @@ fileFormatVersion: 2 -guid: 490fe6c46146140cca8766a31c9dfc0c +guid: d1cb940e3804b4adcaf9b22083fadfad ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] - userData: + userData: v5.6.0 (Unity 6) assetBundleName: assetBundleVariant: diff --git a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-Mobile-UIEffect-Unity6.shader b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-Mobile-UIEffect-Unity6.shader index 354e3ea..242ac43 100755 --- a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-Mobile-UIEffect-Unity6.shader +++ b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-Mobile-UIEffect-Unity6.shader @@ -1,8 +1,5 @@ -// Simplified SDF shader: -// - No Shading Option (bevel / bump / env map) -// - No Glow Option -// - Softness is applied on both side of the outline - +// [OptionalShader] com.coffee.softmask-for-ugui: Hidden/TextMeshPro/Mobile/Distance Field (UIEffect) +// [OptionalShader] com.coffee.ui-effect: Hidden/TextMeshPro/Mobile/Distance Field (SoftMaskable) Shader "Hidden/TextMeshPro/Mobile/Distance Field (UIEffect)" { Properties { @@ -104,10 +101,17 @@ SubShader { #pragma shader_feature_local_fragment _ TARGET_HUE TARGET_LUMINANCE // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #pragma shader_feature _ SOFTMASK_EDITOR + #pragma shader_feature_local_fragment _ SOFTMASKABLE + #if SOFTMASKABLE + #include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" + #endif + // ==== SOFTMASKABLE END ==== + #include "UnityCG.cginc" #include "UnityUI.cginc" #include "Assets/TextMesh Pro/Shaders/TMPro_Properties.cginc" - #include "Assets/TextMesh Pro/Shaders/TMPro.cginc" struct vertex_t { UNITY_VERTEX_INPUT_INSTANCE_ID @@ -138,6 +142,11 @@ SubShader { float4 uvMask : TEXCOORD5; float2 uvLocal : TEXCOORD6; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + float4 worldPosition : TEXCOORD7; + #endif + // ==== SOFTMASKABLE END ==== }; float _UIMaskSoftnessX; @@ -186,11 +195,11 @@ SubShader { #endif fixed4 faceColor = fixed4(input.color.rgb, opacity) * _FaceColor; - faceColor.rgb *= faceColor.a; + //faceColor.rgb *= faceColor.a; fixed4 outlineColor = _OutlineColor; outlineColor.a *= opacity; - outlineColor.rgb *= outlineColor.a; + //outlineColor.rgb *= outlineColor.a; outlineColor = lerp(faceColor, outlineColor, sqrt(min(1.0, (outline * 2)))); #if (UNDERLAY_ON | UNDERLAY_INNER) @@ -224,6 +233,11 @@ SubShader { output.uvLocal = input.texcoord1.zw; output.uvMask = input.texcoord2; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + output.worldPosition = input.vertex; + #endif + // ==== SOFTMASKABLE END ==== return output; } @@ -234,6 +248,7 @@ SubShader { { pixel_t input = _fragInput; float2 uvMove = uv - input.texcoord0.xy; + half d = tex2D(_MainTex, input.texcoord0.xy + uvMove).a * input.param.x; half4 c = input.faceColor * saturate(d - input.param.w); @@ -277,6 +292,12 @@ SubShader { c *= m.x * m.y; #endif + // ==== SOFTMASKABLE START ==== + #if SOFTMASKABLE + c *= SoftMask(input.vertex, input.worldPosition, c.a); + #endif + // ==== SOFTMASKABLE END ==== + #if UNITY_UI_ALPHACLIP clip(c.a - 0.001); #endif diff --git a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-Mobile-UIEffect-Unity6.shader.meta b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-Mobile-UIEffect-Unity6.shader.meta index 0e5d0a1..f81ec80 100755 --- a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-Mobile-UIEffect-Unity6.shader.meta +++ b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-Mobile-UIEffect-Unity6.shader.meta @@ -1,9 +1,9 @@ fileFormatVersion: 2 -guid: b875fa74fa43a4c48a44634d5f3e6d3d +guid: e65241fa80a374114b3f55ed746c04d9 ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] - userData: + userData: v5.6.0 (Unity 6) assetBundleName: assetBundleVariant: diff --git a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-UIEffect-Unity6.shader b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-UIEffect-Unity6.shader index 58f8765..d5dff2f 100755 --- a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-UIEffect-Unity6.shader +++ b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-UIEffect-Unity6.shader @@ -1,3 +1,5 @@ +// [OptionalShader] com.coffee.softmask-for-ugui: Hidden/TextMeshPro/Distance Field (UIEffect) +// [OptionalShader] com.coffee.ui-effect: Hidden/TextMeshPro/Distance Field (SoftMaskable) Shader "Hidden/TextMeshPro/Distance Field (UIEffect)" { Properties { @@ -136,6 +138,14 @@ SubShader { #pragma shader_feature_local_fragment _ TARGET_HUE TARGET_LUMINANCE // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #pragma shader_feature _ SOFTMASK_EDITOR + #pragma shader_feature_local_fragment _ SOFTMASKABLE + #if SOFTMASKABLE + #include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" + #endif + // ==== SOFTMASKABLE END ==== + #include "UnityCG.cginc" #include "UnityUI.cginc" #include "Assets/TextMesh Pro/Shaders/TMPro_Properties.cginc" @@ -175,6 +185,11 @@ SubShader { float4 uvMask : TEXCOORD6; float2 uvLocal : TEXCOORD7; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + float4 worldPosition : TEXCOORD8; + #endif + // ==== SOFTMASKABLE END ==== }; // Used by Unity internally to handle Texture Tiling and Offset. @@ -264,12 +279,17 @@ SubShader { output.uvLocal = input.texcoord1.zw; output.uvMask = input.texcoord2; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + output.worldPosition = input.position; + #endif + // ==== SOFTMASKABLE END ==== return output; } - // ==== UIEFFECT ==== + // ==== UIEFFECT START ==== pixel_t _fragInput; fixed4 uieffect_frag(float2 uv) { @@ -345,14 +365,20 @@ SubShader { _fragInput = input; half4 faceColor = uieffect(_fragInput.atlas, _fragInput.uvMask, _fragInput.uvLocal); - #if UNITY_UI_CLIP_RECT + #if UNITY_UI_CLIP_RECT half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * input.mask.zw); faceColor *= m.x * m.y; - #endif + #endif - #if UNITY_UI_ALPHACLIP + // ==== SOFTMASKABLE START ==== + #if SOFTMASKABLE + faceColor *= SoftMask(input.position, input.worldPosition, faceColor.a); + #endif + // ==== SOFTMASKABLE END ==== + + #if UNITY_UI_ALPHACLIP clip(faceColor.a - 0.001); - #endif + #endif return faceColor; } diff --git a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-UIEffect-Unity6.shader.meta b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-UIEffect-Unity6.shader.meta index 20a1a96..a4fe528 100755 --- a/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-UIEffect-Unity6.shader.meta +++ b/Packages/src/Samples~/TextMeshPro Support (Unity 6)~/Hidden-TMP_SDF-UIEffect-Unity6.shader.meta @@ -1,9 +1,9 @@ fileFormatVersion: 2 -guid: c67f821adbb6348a3a21573a25b55de0 +guid: 935b7be1c88464d2eb87204fdfab5a38 ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] - userData: + userData: v5.6.0 (Unity 6) assetBundleName: assetBundleVariant: diff --git a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-Mobile-UIEffect.shader b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-Mobile-UIEffect.shader index b212ddd..cb100b5 100755 --- a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-Mobile-UIEffect.shader +++ b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-Mobile-UIEffect.shader @@ -1,3 +1,5 @@ +// [OptionalShader] com.coffee.softmask-for-ugui: Hidden/TextMeshPro/Mobile/Bitmap (UIEffect) +// [OptionalShader] com.coffee.ui-effect: Hidden/TextMeshPro/Mobile/Bitmap (SoftMaskable) Shader "Hidden/TextMeshPro/Mobile/Bitmap (UIEffect)" { Properties { @@ -67,6 +69,14 @@ SubShader { #pragma shader_feature_local_fragment _ TARGET_HUE TARGET_LUMINANCE // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #pragma shader_feature _ SOFTMASK_EDITOR + #pragma shader_feature_local_fragment _ SOFTMASKABLE + #if SOFTMASKABLE + #include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" + #endif + // ==== SOFTMASKABLE END ==== + #include "UnityCG.cginc" struct appdata_t { @@ -88,6 +98,11 @@ SubShader { float4 uvMask : TEXCOORD3; float2 uvLocal : TEXCOORD4; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + float4 worldPosition : TEXCOORD5; + #endif + // ==== SOFTMASKABLE END ==== }; sampler2D _MainTex; @@ -99,6 +114,8 @@ SubShader { uniform float4 _ClipRect; uniform float _MaskSoftnessX; uniform float _MaskSoftnessY; + uniform float _UIMaskSoftnessX; + uniform float _UIMaskSoftnessY; v2f vert (appdata_t v) { @@ -120,25 +137,31 @@ SubShader { // Clamp _ClipRect to 16bit. float4 clampedRect = clamp(_ClipRect, -2e10, 2e10); - OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy)); + const half2 maskSoftness = half2(max(_UIMaskSoftnessX, _MaskSoftnessX), max(_UIMaskSoftnessY, _MaskSoftnessY)); + OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * maskSoftness + pixelSize.xy)); // ==== UIEFFECT START ==== OUT.uvLocal = v.texcoord1.zw; OUT.uvMask = v.texcoord2; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + OUT.worldPosition = v.vertex; + #endif + // ==== SOFTMASKABLE END ==== return OUT; } - - // ==== UIEFFECT ==== + // ==== UIEFFECT START ==== v2f _fragInput; fixed4 uieffect_frag(float2 uv) { v2f IN = _fragInput; float2 uvMove = uv - IN.texcoord0; fixed4 color = fixed4(IN.color.rgb, IN.color.a * tex2D(_MainTex, IN.texcoord0 + uvMove).a); - return color * color.a; + color.rgb *= color.a; + return color; } #define UIEFFECT_TEXTMESHPRO 1 @@ -156,6 +179,12 @@ SubShader { color *= m.x * m.y; #endif + // ==== SOFTMASKABLE START ==== + #if SOFTMASKABLE + color *= SoftMask(IN.vertex, IN.worldPosition, color.a); + #endif + // ==== SOFTMASKABLE END ==== + #if UNITY_UI_ALPHACLIP clip(color.a - 0.001); #endif diff --git a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-Mobile-UIEffect.shader.meta b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-Mobile-UIEffect.shader.meta index b8bbc52..aa18ffb 100755 --- a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-Mobile-UIEffect.shader.meta +++ b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-Mobile-UIEffect.shader.meta @@ -4,6 +4,6 @@ ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] - userData: + userData: v5.6.0 assetBundleName: assetBundleVariant: diff --git a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-UIEffect.shader b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-UIEffect.shader index d591641..a3ad4e1 100755 --- a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-UIEffect.shader +++ b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-UIEffect.shader @@ -1,3 +1,5 @@ +// [OptionalShader] com.coffee.softmask-for-ugui: Hidden/TextMeshPro/Bitmap (UIEffect) +// [OptionalShader] com.coffee.ui-effect: Hidden/TextMeshPro/Bitmap (SoftMaskable) Shader "Hidden/TextMeshPro/Bitmap (UIEffect)" { Properties { @@ -66,6 +68,14 @@ SubShader{ #pragma shader_feature_local_fragment _ TARGET_HUE TARGET_LUMINANCE // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #pragma shader_feature _ SOFTMASK_EDITOR + #pragma shader_feature_local_fragment _ SOFTMASKABLE + #if SOFTMASKABLE + #include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" + #endif + // ==== SOFTMASKABLE END ==== + #include "UnityCG.cginc" struct appdata_t { @@ -88,6 +98,11 @@ SubShader{ float4 uvMask : TEXCOORD3; float2 uvLocal : TEXCOORD4; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + float4 worldPosition : TEXCOORD5; + #endif + // ==== SOFTMASKABLE END ==== }; uniform sampler2D _MainTex; @@ -100,6 +115,8 @@ SubShader{ uniform float4 _ClipRect; uniform float _MaskSoftnessX; uniform float _MaskSoftnessY; + uniform float _UIMaskSoftnessX; + uniform float _UIMaskSoftnessY; float2 UnpackUV(float uv) { @@ -127,23 +144,29 @@ SubShader{ OUT.vertex = vPosition; OUT.color = faceColor; OUT.texcoord0 = v.texcoord0; - OUT.texcoord1 = TRANSFORM_TEX(UnpackUV(v.texcoord1.xy), _FaceTex); + OUT.texcoord1 = TRANSFORM_TEX(UnpackUV(v.texcoord1), _FaceTex); float2 pixelSize = vPosition.w; pixelSize /= abs(float2(_ScreenParams.x * UNITY_MATRIX_P[0][0], _ScreenParams.y * UNITY_MATRIX_P[1][1])); // Clamp _ClipRect to 16bit. float4 clampedRect = clamp(_ClipRect, -2e10, 2e10); - OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy)); + const half2 maskSoftness = half2(max(_UIMaskSoftnessX, _MaskSoftnessX), max(_UIMaskSoftnessY, _MaskSoftnessY)); + OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * maskSoftness + pixelSize.xy)); // ==== UIEFFECT START ==== OUT.uvLocal = v.texcoord1.zw; OUT.uvMask = v.texcoord2; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + OUT.worldPosition = v.vertex; + #endif + // ==== SOFTMASKABLE END ==== return OUT; } - - // ==== UIEFFECT ==== + + // ==== UIEFFECT START ==== v2f _fragInput; fixed4 uieffect_frag(float2 uv) { @@ -151,7 +174,8 @@ SubShader{ float2 uvMove = uv - IN.texcoord0; fixed4 color = tex2D(_MainTex, IN.texcoord0 + uvMove); color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, IN.color.a * color.a); - return color * color.a; + color.rgb *= color.a; + return color; } #define UIEFFECT_TEXTMESHPRO 1 @@ -169,6 +193,12 @@ SubShader{ color *= m.x * m.y; #endif + // ==== SOFTMASKABLE START ==== + #if SOFTMASKABLE + color *= SoftMask(IN.vertex, IN.worldPosition, color.a); + #endif + // ==== SOFTMASKABLE END ==== + #if UNITY_UI_ALPHACLIP clip(color.a - 0.001); #endif diff --git a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-UIEffect.shader.meta b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-UIEffect.shader.meta index 132b636..474b9d7 100755 --- a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-UIEffect.shader.meta +++ b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_Bitmap-UIEffect.shader.meta @@ -4,6 +4,6 @@ ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] - userData: + userData: v5.6.0 assetBundleName: assetBundleVariant: diff --git a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-Mobile-UIEffect.shader b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-Mobile-UIEffect.shader index 169bbe4..b3e37cc 100644 --- a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-Mobile-UIEffect.shader +++ b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-Mobile-UIEffect.shader @@ -1,8 +1,5 @@ -// Simplified SDF shader: -// - No Shading Option (bevel / bump / env map) -// - No Glow Option -// - Softness is applied on both side of the outline - +// [OptionalShader] com.coffee.softmask-for-ugui: Hidden/TextMeshPro/Mobile/Distance Field (UIEffect) +// [OptionalShader] com.coffee.ui-effect: Hidden/TextMeshPro/Mobile/Distance Field (SoftMaskable) Shader "Hidden/TextMeshPro/Mobile/Distance Field (UIEffect)" { Properties { @@ -103,6 +100,14 @@ SubShader { #pragma shader_feature_local_fragment _ TARGET_HUE TARGET_LUMINANCE // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #pragma shader_feature _ SOFTMASK_EDITOR + #pragma shader_feature_local_fragment _ SOFTMASKABLE + #if SOFTMASKABLE + #include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" + #endif + // ==== SOFTMASKABLE END ==== + #include "UnityCG.cginc" #include "UnityUI.cginc" #include "Assets/TextMesh Pro/Shaders/TMPro_Properties.cginc" @@ -137,8 +142,15 @@ SubShader { float4 uvMask : TEXCOORD5; float2 uvLocal : TEXCOORD6; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + float4 worldPosition : TEXCOORD7; + #endif + // ==== SOFTMASKABLE END ==== }; + float _UIMaskSoftnessX; + float _UIMaskSoftnessY; pixel_t VertShader(vertex_t input) { @@ -204,7 +216,8 @@ SubShader { output.outlineColor = outlineColor; output.texcoord0 = float4(input.texcoord0.x, input.texcoord0.y, maskUV.x, maskUV.y); output.param = half4(scale, bias - outline, bias + outline, bias); - output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy)); + const half2 maskSoftness = half2(max(_UIMaskSoftnessX, _MaskSoftnessX), max(_UIMaskSoftnessY, _MaskSoftnessY)); + output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * maskSoftness + pixelSize.xy)); #if (UNDERLAY_ON || UNDERLAY_INNER) output.texcoord1 = float4(input.texcoord0 + layerOffset, input.color.a, 0); output.underlayParam = half2(layerScale, layerBias); @@ -214,6 +227,11 @@ SubShader { output.uvLocal = input.texcoord1.zw; output.uvMask = input.texcoord2; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + output.worldPosition = input.vertex; + #endif + // ==== SOFTMASKABLE END ==== return output; } @@ -265,7 +283,13 @@ SubShader { half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * input.mask.zw); c *= m.x * m.y; #endif - + + // ==== SOFTMASKABLE START ==== + #if SOFTMASKABLE + c *= SoftMask(input.vertex, input.worldPosition, c.a); + #endif + // ==== SOFTMASKABLE END ==== + #if UNITY_UI_ALPHACLIP clip(c.a - 0.001); #endif diff --git a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-Mobile-UIEffect.shader.meta b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-Mobile-UIEffect.shader.meta index 4eca24f..6dc9d72 100644 --- a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-Mobile-UIEffect.shader.meta +++ b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-Mobile-UIEffect.shader.meta @@ -4,6 +4,6 @@ ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] - userData: + userData: v5.6.0 assetBundleName: assetBundleVariant: diff --git a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-UIEffect.shader b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-UIEffect.shader index 3a1e76d..00a6024 100644 --- a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-UIEffect.shader +++ b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-UIEffect.shader @@ -1,3 +1,5 @@ +// [OptionalShader] com.coffee.softmask-for-ugui: Hidden/TextMeshPro/Distance Field (UIEffect) +// [OptionalShader] com.coffee.ui-effect: Hidden/TextMeshPro/Distance Field (SoftMaskable) Shader "Hidden/TextMeshPro/Distance Field (UIEffect)" { Properties { @@ -136,6 +138,14 @@ SubShader { #pragma shader_feature_local_fragment _ TARGET_HUE TARGET_LUMINANCE // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #pragma shader_feature _ SOFTMASK_EDITOR + #pragma shader_feature_local_fragment _ SOFTMASKABLE + #if SOFTMASKABLE + #include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" + #endif + // ==== SOFTMASKABLE END ==== + #include "UnityCG.cginc" #include "UnityUI.cginc" #include "Assets/TextMesh Pro/Shaders/TMPro_Properties.cginc" @@ -173,6 +183,11 @@ SubShader { float4 uvMask : TEXCOORD6; float2 uvLocal : TEXCOORD7; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + float4 worldPosition : TEXCOORD8; + #endif + // ==== SOFTMASKABLE END ==== }; // Used by Unity internally to handle Texture Tiling and Offset. @@ -257,11 +272,16 @@ SubShader { output.uvLocal = input.texcoord1.zw; output.uvMask = input.texcoord2; // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #if SOFTMASK_EDITOR + output.worldPosition = input.position; + #endif + // ==== SOFTMASKABLE END ==== return output; } - // ==== UIEFFECT ==== + // ==== UIEFFECT START ==== pixel_t _fragInput; fixed4 uieffect_frag(float2 uv) { @@ -343,6 +363,12 @@ SubShader { faceColor *= m.x * m.y; #endif + // ==== SOFTMASKABLE START ==== + #if SOFTMASKABLE + faceColor *= SoftMask(input.position, input.worldPosition, faceColor.a); + #endif + // ==== SOFTMASKABLE END ==== + #if UNITY_UI_ALPHACLIP clip(faceColor.a - 0.001); #endif diff --git a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-UIEffect.shader.meta b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-UIEffect.shader.meta index a1a301f..1c93f53 100644 --- a/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-UIEffect.shader.meta +++ b/Packages/src/Samples~/TextMeshPro Support~/Hidden-TMP_SDF-UIEffect.shader.meta @@ -4,6 +4,6 @@ ShaderImporter: externalObjects: {} defaultTextures: [] nonModifiableTextures: [] - userData: + userData: v5.6.0 assetBundleName: assetBundleVariant: diff --git a/Packages/src/Shaders/UIEffect.cginc b/Packages/src/Shaders/UIEffect.cginc index 9a468ba..52727ee 100644 --- a/Packages/src/Shaders/UIEffect.cginc +++ b/Packages/src/Shaders/UIEffect.cginc @@ -1,6 +1,8 @@ #ifndef UI_EFFECT_INCLUDED #define UI_EFFECT_INCLUDED +uniform const int _SrcBlend; +uniform const int _DstBlend; uniform const float4 _MainTex_TexelSize; uniform const float _ToneIntensity; uniform const half4 _ColorValue; diff --git a/Packages/src/Shaders/UIEffect.shader b/Packages/src/Shaders/UIEffect.shader index bfc0f5c..4843af8 100644 --- a/Packages/src/Shaders/UIEffect.shader +++ b/Packages/src/Shaders/UIEffect.shader @@ -1,4 +1,6 @@ -Shader "Hidden/UI/Default (UIEffect)" +// [OptionalShader] com.coffee.softmask-for-ugui: Hidden/UI/Default (UIEffect) +// [OptionalShader] com.coffee.ui-effect: Hidden/UI/Default (SoftMaskable) +Shader "Hidden/UI/Default (UIEffect)" { Properties { @@ -53,8 +55,8 @@ #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile_local_fragment _ UNITY_UI_CLIP_RECT - #pragma multi_compile_local_fragment _ UNITY_UI_ALPHACLIP + #pragma multi_compile _ UNITY_UI_CLIP_RECT + #pragma multi_compile _ UNITY_UI_ALPHACLIP // ==== UIEFFECT START ==== #pragma shader_feature_local_fragment _ TONE_GRAYSCALE TONE_SEPIA TONE_NEGATIVE TONE_RETRO TONE_POSTERIZE @@ -68,6 +70,14 @@ #pragma shader_feature_local_fragment _ TARGET_HUE TARGET_LUMINANCE // ==== UIEFFECT END ==== + // ==== SOFTMASKABLE START ==== + #pragma shader_feature _ SOFTMASK_EDITOR + #pragma shader_feature_local_fragment _ SOFTMASKABLE + #if SOFTMASKABLE + #include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc" + #endif + // ==== SOFTMASKABLE END ==== + struct appdata_t { float4 vertex : POSITION; @@ -143,13 +153,6 @@ fixed4 uieffect_frag(float2 uv) { v2f IN = _fragInput; - //Round up the alpha color coming from the interpolator (to 1.0/256.0 steps) - //The incoming alpha could have numerical instability, which makes it very sensible to - //HDR color transparency blend, when it blends with the world's texture. - const half alphaPrecision = half(0xff); - const half invAlphaPrecision = half(1.0 / alphaPrecision); - IN.color.a = round(IN.color.a * alphaPrecision) * invAlphaPrecision; - half4 color = IN.color * (tex2D(_MainTex, uv) + _TextureSampleAdd); color.rgb *= color.a; return color; @@ -160,6 +163,13 @@ half4 frag(v2f IN) : SV_Target { + //Round up the alpha color coming from the interpolator (to 1.0/256.0 steps) + //The incoming alpha could have numerical instability, which makes it very sensible to + //HDR color transparency blend, when it blends with the world's texture. + const half alphaPrecision = half(0xff); + const half invAlphaPrecision = half(1.0 / alphaPrecision); + IN.color.a = round(IN.color.a * alphaPrecision) * invAlphaPrecision; + _fragInput = IN; half4 c = uieffect(_fragInput.texcoord, _fragInput.uvMask, _fragInput.uvLocal); @@ -168,6 +178,12 @@ c *= m.x * m.y; #endif + // ==== SOFTMASKABLE START ==== + #if SOFTMASKABLE + c *= SoftMask(IN.vertex, IN.worldPosition, c.a); + #endif + // ==== SOFTMASKABLE END ==== + #ifdef UNITY_UI_ALPHACLIP clip (c.a - 0.001); #endif