Skip to content

Commit

Permalink
Merge branch 'head_unity2019'
Browse files Browse the repository at this point in the history
  • Loading branch information
whiteflare committed Feb 11, 2024
2 parents 40c42e7 + d88774a commit cf51846
Show file tree
Hide file tree
Showing 133 changed files with 1,197 additions and 497 deletions.
93 changes: 90 additions & 3 deletions Editor/WFEditorSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,53 @@ public class WFEditorSetting : ScriptableObject
[Header("Quest Build Support")]
public bool autoSwitchQuestShader = true;

public NearClipCancelMode enableNccInVRC3Avatar = NearClipCancelMode.ForceON;
/// <summary>
/// カメラのニアクリップを無視(for VRC3Avatar)
/// </summary>
public MatForceSettingMode enableNccInVRC3Avatar = MatForceSettingMode.ForceON;
/// <summary>
/// カメラのニアクリップを無視(for VRC3World)
/// </summary>
public MatForceSettingMode enableNccInVRC3World = MatForceSettingMode.ForceOFF;

public NearClipCancelMode enableNccInVRC3World = NearClipCancelMode.ForceOFF;
/// <summary>
/// 逆光補正しない(for VRC3Avatar)
/// </summary>
public MatForceSettingMode disableBackLitInVRC3Avatar = MatForceSettingMode.PerMaterial;
/// <summary>
/// 逆光補正しない(for VRC3World)
/// </summary>
public MatForceSettingMode disableBackLitInVRC3World = MatForceSettingMode.ForceON;

private static WFEditorSetting currentSettings = null;
private static int currentPriority = 0;

public MatForceSettingMode GetEnableNccInCurrentEnvironment()
{
switch (WFCommonUtility.GetCurrentEntironment())
{
case CurrentEntironment.VRCSDK3_Avatar:
return enableNccInVRC3Avatar;
case CurrentEntironment.VRCSDK3_World:
return enableNccInVRC3World;
default:
return MatForceSettingMode.PerMaterial;
}
}

public MatForceSettingMode GetDisableBackLitInCurrentEnvironment()
{
switch (WFCommonUtility.GetCurrentEntironment())
{
case CurrentEntironment.VRCSDK3_Avatar:
return disableBackLitInVRC3Avatar;
case CurrentEntironment.VRCSDK3_World:
return disableBackLitInVRC3World;
default:
return MatForceSettingMode.PerMaterial;
}
}

public static WFEditorSetting GetOneOfSettings(bool forceReload = false)
{
if (forceReload)
Expand Down Expand Up @@ -128,7 +168,7 @@ private static WFEditorSetting[] LoadAllSettingsFromAssetDatabase()
}
}

public enum NearClipCancelMode
public enum MatForceSettingMode
{
PerMaterial = -1,
ForceOFF = 0,
Expand Down Expand Up @@ -166,6 +206,8 @@ class WFEditorSettingEditor : Editor
SerializedProperty p_autoSwitchQuestShader;
SerializedProperty p_enableNccInVRC3Avatar;
SerializedProperty p_enableNccInVRC3World;
SerializedProperty p_disableBackLitInVRC3Avatar;
SerializedProperty p_disableBackLitInVRC3World;

private void OnEnable()
{
Expand All @@ -191,6 +233,10 @@ private void OnEnable()
// EnableNCC
this.p_enableNccInVRC3Avatar = serializedObject.FindProperty(nameof(WFEditorSetting.enableNccInVRC3Avatar));
this.p_enableNccInVRC3World = serializedObject.FindProperty(nameof(WFEditorSetting.enableNccInVRC3World));

// DisableBackLit
this.p_disableBackLitInVRC3Avatar = serializedObject.FindProperty(nameof(WFEditorSetting.disableBackLitInVRC3Avatar));
this.p_disableBackLitInVRC3World = serializedObject.FindProperty(nameof(WFEditorSetting.disableBackLitInVRC3World));
}

public override void OnInspectorGUI()
Expand Down Expand Up @@ -248,9 +294,50 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(p_enableNccInVRC3World, new GUIContent("For VRCSDK3 World"));
}

EditorGUILayout.LabelField(WFI18N.Translate("WFEditorSetting", "Disable BackLit"));
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(p_disableBackLitInVRC3Avatar, new GUIContent("For VRCSDK3 Avatar"));
EditorGUILayout.PropertyField(p_disableBackLitInVRC3World, new GUIContent("For VRCSDK3 World"));
}

serializedObject.ApplyModifiedProperties();

WFEditorPrefs.LangMode = (EditorLanguage)EditorGUILayout.EnumPopup("Editor language", WFEditorPrefs.LangMode);

EditorGUILayout.Space();
GUI.Label(EditorGUILayout.GetControlRect(), "Other", EditorStyles.boldLabel);

if (GUI.Button(EditorGUILayout.GetControlRect(), WFI18N.Translate("WFEditorSetting", "Create New Settings asset")))
{
CreateNewSettingsAsset();
}
}

private void CreateNewSettingsAsset()
{
if (target == null)
{
return;
}
var path = EditorUtility.SaveFilePanelInProject("Create New Settings asset", "", "asset", "");
if (string.IsNullOrWhiteSpace(path))
{
return;
}

// 現在の設定をコピーして新しいアセットとする
var newSettings = Instantiate((WFEditorSetting)target);
// 優先度は現在有効になっている設定より小さくする
newSettings.settingPriority = WFEditorSetting.GetOneOfSettings().settingPriority - 1;

// 新規作成
AssetDatabase.CreateAsset(newSettings, path);
// 選択する
Selection.activeObject = newSettings;

// リロード
WFEditorSetting.GetOneOfSettings(true);
}

private GUIContent toDisplay(SerializedProperty p)
Expand Down
30 changes: 18 additions & 12 deletions Editor/WFMaterialValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@ static class WFMaterialValidators
}
else
{
if (WFAccessor.GetBool(target, "_TS_Enable", false) && !WFAccessor.GetBool(target, "_TS_DisableBackLit", true))
if (WFEditorSetting.GetOneOfSettings().GetDisableBackLitInCurrentEnvironment() == MatForceSettingMode.PerMaterial)
{
return true;
}
if (WFAccessor.GetBool(target, "_TR_Enable", false) && !WFAccessor.GetBool(target, "_TR_DisableBackLit", true))
{
return true;
if (WFAccessor.GetBool(target, "_TS_Enable", false) && !WFAccessor.GetBool(target, "_TS_DisableBackLit", true))
{
return true;
}
if (WFAccessor.GetBool(target, "_TR_Enable", false) && !WFAccessor.GetBool(target, "_TR_DisableBackLit", true))
{
return true;
}
}
}
// それ以外は設定不要
Expand All @@ -137,13 +140,16 @@ static class WFMaterialValidators
{
WFAccessor.SetBool(mat, "_GL_DisableBackLit", true);
WFAccessor.SetBool(mat, "_GL_DisableBasePos", true);
if (WFAccessor.GetBool(mat, "_TS_Enable", false))
{
WFAccessor.SetBool(mat, "_TS_DisableBackLit", true);
}
if (WFAccessor.GetBool(mat, "_TR_Enable", false))
if (WFEditorSetting.GetOneOfSettings().GetDisableBackLitInCurrentEnvironment() == MatForceSettingMode.PerMaterial)
{
WFAccessor.SetBool(mat, "_TR_DisableBackLit", true);
if (WFAccessor.GetBool(mat, "_TS_Enable", false))
{
WFAccessor.SetBool(mat, "_TS_DisableBackLit", true);
}
if (WFAccessor.GetBool(mat, "_TR_Enable", false))
{
WFAccessor.SetBool(mat, "_TR_DisableBackLit", true);
}
}
}
}
Expand Down
35 changes: 30 additions & 5 deletions Editor/WF_Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public static bool SetupMaterial(Material mat)
changed |= SetupMaterial_GIFrags(mat);
changed |= SetupMaterial_ClearBgPass(mat);
changed |= SetupMaterial_NearClipCancel(mat);
changed |= SetupMaterial_DisableBackLit(mat);
changed |= SetupMaterial_SetupKeyword(mat);
changed |= SetupMaterial_DeleteKeyword(mat);
}
Expand Down Expand Up @@ -304,11 +305,7 @@ private static bool SetupMaterial_NearClipCancel(Material mat)
if (mat.HasProperty("_GL_NCC_Enable"))
{
var oldVal = mat.GetInt("_GL_NCC_Enable");
#if ENV_VRCSDK3_AVATAR
var newVal = (int)WFEditorSetting.GetOneOfSettings().enableNccInVRC3Avatar;
#elif ENV_VRCSDK3_WORLD
var newVal = (int)WFEditorSetting.GetOneOfSettings().enableNccInVRC3World;
#endif
var newVal = (int)WFEditorSetting.GetOneOfSettings().GetEnableNccInCurrentEnvironment();
if (0 <= newVal && oldVal != newVal)
{
mat.SetInt("_GL_NCC_Enable", newVal);
Expand All @@ -319,6 +316,34 @@ private static bool SetupMaterial_NearClipCancel(Material mat)
return changed;
}

private static bool SetupMaterial_DisableBackLit(Material mat)
{
bool changed = false;
#if ENV_VRCSDK3_AVATAR || ENV_VRCSDK3_WORLD
if (mat.HasProperty("_TS_DisableBackLit"))
{
var oldVal = mat.GetInt("_TS_DisableBackLit");
var newVal = (int)WFEditorSetting.GetOneOfSettings().GetDisableBackLitInCurrentEnvironment();
if (0 <= newVal && oldVal != newVal)
{
mat.SetInt("_TS_DisableBackLit", newVal);
changed = true;
}
}
if (mat.HasProperty("_TR_DisableBackLit"))
{
var oldVal = mat.GetInt("_TR_DisableBackLit");
var newVal = (int)WFEditorSetting.GetOneOfSettings().GetDisableBackLitInCurrentEnvironment();
if (0 <= newVal && oldVal != newVal)
{
mat.SetInt("_TR_DisableBackLit", newVal);
changed = true;
}
}
#endif
return changed;
}

#endregion

#region シェーダ切り替え
Expand Down
12 changes: 7 additions & 5 deletions Editor/WF_Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,12 @@ private static Dictionary<string, WFCustomKeywordSetting> ToWFCustomKeywordSetti
new WFI18NTranslation("TS", "Dont Ajust Contrast", "影コントラストを調整しない"),
// RimLight
new WFI18NTranslation("TR", "Rim Color", "リムライト色"),
new WFI18NTranslation("TR", "Power", "強度(マスター)"),
new WFI18NTranslation("TR", "Feather", "境界のぼかし強度"),
new WFI18NTranslation("TR", "Power Top", "強度(上)"),
new WFI18NTranslation("TR", "Power Side", "強度(横)"),
new WFI18NTranslation("TR", "Power Bottom", "強度(下)"),
new WFI18NTranslation("TR", "Width", ""),
new WFI18NTranslation("TR", "Width Top", "幅(上)"),
new WFI18NTranslation("TR", "Width Side", "幅(横)"),
new WFI18NTranslation("TR", "Width Bottom", "幅(下)"),
new WFI18NTranslation("TR", "Feather", "ぼかし幅"),
new WFI18NTranslation("TR", "Exponent", "ぼかし指数"),
new WFI18NTranslation("TR", "Assign MainTex to MaskTexture", "MainTexをマスクに設定する"),
// Overlay Texture
new WFI18NTranslation("OVL", "Overlay Color", "オーバーレイ テクスチャ"),
Expand Down Expand Up @@ -734,6 +735,7 @@ private static Dictionary<string, WFCustomKeywordSetting> ToWFCustomKeywordSetti
new WFI18NTranslation("WFEditorSetting", "Enable Scan Projects", "Shaderインポート時にプロジェクトをスキャン"),
new WFI18NTranslation("WFEditorSetting", "Enable Migration When Import", "マテリアルインポート時にマテリアルを最新化"),
new WFI18NTranslation("WFEditorSetting", "Auto Switch Quest Shader", "Quest向けシェーダに自動で切り替える"),
new WFI18NTranslation("WFEditorSetting", "Create New Settings asset", "設定アセットファイルを新規作成"),

// その他のテキスト
new WFI18NTranslation(WFMessageText.NewerVersion, "新しいバージョンがリリースされています。\n最新版: "),
Expand Down
18 changes: 17 additions & 1 deletion Editor/WF_MaterialConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ protected static List<Action<SelectShaderContext>> CreateConverterList()

static class ScanAndMigrationExecutor
{
public const int VERSION = 8;
public const int VERSION = 9;
private static readonly string KEY_MIG_VERSION = "UnlitWF.ShaderEditor/autoMigrationVersion";

/// <summary>
Expand Down Expand Up @@ -1139,6 +1139,12 @@ protected override bool Validate(Material mat)

PropertyNameReplacement.Group("2023/08/27"),
PropertyNameReplacement.Match("_GL_DisableBackLit", "_TS_DisableBackLit"), // 後でTRにもコピーする

PropertyNameReplacement.Group("2024/01/28"), // TODO 後で変更
PropertyNameReplacement.Match("_TR_Power", "_TR_Width"),
PropertyNameReplacement.Match("_TR_PowerTop", "_TR_WidthTop"),
PropertyNameReplacement.Match("_TR_PowerSide", "_TR_WidthSide"),
PropertyNameReplacement.Match("_TR_PowerBottom", "_TR_WidthBottom"),
};

public static bool ExistsNeedsMigration(Material mat)
Expand Down Expand Up @@ -1227,6 +1233,16 @@ protected static List<Action<ConvertContext>> CreateConverterList()
WFAccessor.CopyIntValue(ctx.target, "_TS_DisableBackLit", "_TR_DisableBackLit");
}
},
ctx => {
// _TR_Powerありの状態から_TR_Widthに変更されたならば、
if (HasOldProperty(ctx, "_TR_Power") && HasNewProperty(ctx, "_TR_Width"))
{
WFAccessor.SetFloat(ctx.target, "_TR_Width", Mathf.Clamp(WFAccessor.GetFloat(ctx.target, "_TR_Width", 1) * 0.1f, 0, 1));
WFAccessor.SetFloat(ctx.target, "_TR_WidthTop", Mathf.Clamp(WFAccessor.GetFloat(ctx.target, "_TR_WidthTop", 1) * 10, 0, 1));
WFAccessor.SetFloat(ctx.target, "_TR_WidthSide", Mathf.Clamp(WFAccessor.GetFloat(ctx.target, "_TR_WidthSide", 1) * 10, 0, 1));
WFAccessor.SetFloat(ctx.target, "_TR_WidthBottom", Mathf.Clamp(WFAccessor.GetFloat(ctx.target, "_TR_WidthBottom", 1) * 10, 0, 1));
}
},
};
}
}
Expand Down
5 changes: 4 additions & 1 deletion Editor/WF_MaterialEditUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,10 @@ private static bool IsUnlitWFMaterial(Material mm)
{
if (mm != null && mm.shader != null)
{
return mm.shader.name.Contains("UnlitWF") && !mm.shader.name.Contains("Debug");
if (mm.shader.name.Contains("UnlitWF") && !mm.shader.name.Contains("Debug"))
{
return mm.shader.name.Contains("URP") == WFCommonUtility.IsURP();
}
}
return false;
}
Expand Down
13 changes: 2 additions & 11 deletions Editor/WF_ShaderCustomEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,8 @@ class ShaderCustomEditor : ShaderGUI
new ConditionVisiblePropertyHook("_GL_ShadowCutoff", ctx => IsAnyIntValue(ctx, "_GL_CastShadow", p => 1 <= p), isRegex:false),
new ConditionVisiblePropertyHook("_GL_CustomAzimuth|_GL_CustomAltitude", ctx => IsAnyIntValue(ctx, "_GL_LightMode", p => p != 5)),
new ConditionVisiblePropertyHook("_GL_CustomLitPos", ctx => IsAnyIntValue(ctx, "_GL_LightMode", p => p == 5), isRegex:false),
new ConditionVisiblePropertyHook("_GL_NCC_Enable", ctx => {
switch(WFCommonUtility.GetCurrentEntironment())
{
case CurrentEntironment.VRCSDK3_Avatar:
return WFEditorSetting.GetOneOfSettings().enableNccInVRC3Avatar == NearClipCancelMode.PerMaterial;
case CurrentEntironment.VRCSDK3_World:
return WFEditorSetting.GetOneOfSettings().enableNccInVRC3World == NearClipCancelMode.PerMaterial;
default:
return true;
}
}, isRegex:false),
new ConditionVisiblePropertyHook("_GL_NCC_Enable", ctx => WFEditorSetting.GetOneOfSettings().GetEnableNccInCurrentEnvironment() == MatForceSettingMode.PerMaterial, isRegex:false),
new ConditionVisiblePropertyHook("_T[SR]_DisableBackLit", ctx => WFEditorSetting.GetOneOfSettings().GetDisableBackLitInCurrentEnvironment() == MatForceSettingMode.PerMaterial),
// 条件付きHide(Grass系列)
new ConditionVisiblePropertyHook("_GRS_WorldYBase|_GRS_WorldYScale", ctx => IsAnyIntValue(ctx, "_GRS_HeightType", p => p == 0)),
new ConditionVisiblePropertyHook("_GRS_HeightUVType", ctx => IsAnyIntValue(ctx, "_GRS_HeightType", p => p == 1 || p == 2), isRegex:false),
Expand Down
5 changes: 4 additions & 1 deletion Editor/WF_ShaderToolWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ public static bool IsUnlitWFMaterial(Material mm)
{
if (mm != null && mm.shader != null)
{
return mm.shader.name.Contains("UnlitWF") && !mm.shader.name.Contains("Debug");
if (mm.shader.name.Contains("UnlitWF") && !mm.shader.name.Contains("Debug"))
{
return mm.shader.name.Contains("URP") == WFCommonUtility.IsURP();
}
}
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions Examples/Gem/GemMaterials/BlackGem.mat
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Material:
- _ES_AU_Slope: 0.2
- _ES_AuLinkEnable: 0
- _ES_BlendType: 0
- _ES_ChangeAlpha: 0
- _ES_Enable: 0
- _ES_SC_AlphaScroll: 0
- _ES_SC_DirType: 0
Expand Down Expand Up @@ -105,8 +106,10 @@ Material:
- _GMR_Monochrome: 1
- _GMR_Power: 1
- _NM_Enable: 0
- _NM_InvConvex: 0
- _QuestSupported: 0
- _UseVertexColor: 0
- _VRCFallback: 0
m_Colors:
- _Color: {r: 0.045542486, g: 0.04282353, b: 0.050980393, a: 1}
- _DSV_SparkColor: {r: 1, g: 1, b: 1, a: 1}
Expand Down
3 changes: 3 additions & 0 deletions Examples/Gem/GemMaterials/GrayGem.mat
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Material:
- _ES_AU_Slope: 0.2
- _ES_AuLinkEnable: 0
- _ES_BlendType: 0
- _ES_ChangeAlpha: 0
- _ES_Enable: 0
- _ES_SC_AlphaScroll: 0
- _ES_SC_DirType: 0
Expand Down Expand Up @@ -105,8 +106,10 @@ Material:
- _GMR_Monochrome: 1
- _GMR_Power: 1
- _NM_Enable: 0
- _NM_InvConvex: 0
- _QuestSupported: 0
- _UseVertexColor: 0
- _VRCFallback: 0
m_Colors:
- _Color: {r: 0.385, g: 0.385, b: 0.385, a: 1}
- _DSV_SparkColor: {r: 1, g: 1, b: 1, a: 1}
Expand Down
Loading

0 comments on commit cf51846

Please sign in to comment.