Skip to content

Commit

Permalink
feat: strip shaders using ShaderVariantCollection instead of 'Always …
Browse files Browse the repository at this point in the history
…Include Shaders'

close #211
  • Loading branch information
mob-sakai committed Nov 14, 2024
1 parent c6b8906 commit d9010bf
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 261 deletions.
21 changes: 0 additions & 21 deletions Assets/ProjectSettings/UISoftMask.asset

This file was deleted.

60 changes: 60 additions & 0 deletions Assets/ProjectSettings/UISoftMaskProjectSettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: eb5b5e33068c14a2bacdd6575e94f505, type: 3}
m_Name: UISoftMaskProjectSettings
m_EditorClassIdentifier:
m_SoftMaskEnabled: 1
m_StereoEnabled: 1
m_TransformSensitivity: 1
m_UseStencilOutsideScreen: 1
m_HideGeneratedComponents: 1
m_ShaderVariantRegistry:
m_ErrorWhenFallback: 0
m_ShaderAliases:
- key: UI/Default
value: Hidden/UI/Default (SoftMaskable)
m_UnregisteredVariants: []
m_Asset: {fileID: 6562417279084414694}
--- !u!200 &6562417279084414694
ShaderVariantCollection:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: ShaderVariants
m_Shaders:
- first: {fileID: 4800000, guid: 935b7be1c88464d2eb87204fdfab5a38, type: 3}
second:
variants:
- keywords: GLOW_ON
passType: 0
- first: {fileID: 4800000, guid: 9839189d918374a318d397a86e90aa73, type: 3}
second:
variants:
- keywords:
passType: 0
- keywords: SOFTMASK_EDITOR UNITY_UI_CLIP_RECT
passType: 0
- keywords: UNITY_UI_ALPHACLIP
passType: 0
- keywords: UNITY_UI_CLIP_RECT
passType: 0
- first: {fileID: 4800000, guid: 2933b413a51fc4ff3a83c7ef4177ae84, type: 3}
second:
variants:
- keywords:
passType: 0
- first: {fileID: 4800000, guid: 33e06cd3c50064f30a691b600fc62f3f, type: 3}
second:
variants:
- keywords:
passType: 0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 0 additions & 48 deletions Packages/src/Editor/ShaderPreProcessor.cs

This file was deleted.

40 changes: 12 additions & 28 deletions Packages/src/Editor/UISoftMaskProjectSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,28 @@ namespace Coffee.UISoftMask
[CustomEditor(typeof(UISoftMaskProjectSettings))]
internal class UISoftMaskProjectSettingsEditor : Editor
{
private static readonly GUIContent s_ContentRemove = new GUIContent("-");
private static readonly GUIContent s_ContentReset = new GUIContent("Reset");
private static readonly GUIContent s_ContentIncluded = new GUIContent("Included Shaders");
private static readonly GUIContent s_ContentUpgrade = new GUIContent("Upgrade");
private static readonly GUIContent s_ContentUpgradeButton = new GUIContent("Upgrade All Assets V1 to V2");
private ShaderRegistryEditor _shaderRegistryEditor;

public override void OnInspectorGUI()
{
base.OnInspectorGUI();

// Draw SoftMask/SoftMaskable/TerminalShape Shaders;
EditorGUILayout.BeginHorizontal();
// Shader registry.
EditorGUILayout.Space();
EditorGUILayout.LabelField("Shader", EditorStyles.boldLabel);
if (_shaderRegistryEditor == null)
{
EditorGUILayout.PrefixLabel(s_ContentIncluded);
if (GUILayout.Button(s_ContentReset, EditorStyles.miniButton, GUILayout.Width(80)))
{
UISoftMaskProjectSettings.instance.ReloadShaders(true);
}
var property = serializedObject.FindProperty("m_ShaderVariantRegistry");
_shaderRegistryEditor = new ShaderRegistryEditor(property, "(SoftMaskable)");
}
EditorGUILayout.EndHorizontal();

foreach (var shader in AlwaysIncludedShadersProxy.GetShaders())
{
if (!UISoftMaskProjectSettings.CanIncludeShader(shader)) continue;

EditorGUILayout.BeginHorizontal();
EditorGUILayout.ObjectField(shader, typeof(Shader), false);
if (GUILayout.Button(s_ContentRemove, EditorStyles.miniButton, GUILayout.Width(20)))
{
AlwaysIncludedShadersProxy.Remove(shader);
}

EditorGUILayout.EndHorizontal();
}
_shaderRegistryEditor.Draw();
serializedObject.ApplyModifiedProperties();

// Upgrade v1 to v2.
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_ContentUpgrade, EditorStyles.boldLabel);
if (GUILayout.Button(s_ContentUpgradeButton))
EditorGUILayout.LabelField("Upgrade", EditorStyles.boldLabel);
if (GUILayout.Button("Upgrade All Assets V1 to V2"))
{
EditorApplication.delayCall += () => new UISoftMaskModifierRunner().RunIfUserWantsTo();
}
Expand Down
Loading

0 comments on commit d9010bf

Please sign in to comment.