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 Dec 9, 2023
2 parents eb55437 + 336cf0b commit b431670
Show file tree
Hide file tree
Showing 280 changed files with 10,475 additions and 1,458 deletions.
25 changes: 15 additions & 10 deletions Editor/WF_Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -998,9 +998,14 @@ public static bool IsPropertyLockedByAncestor(UnityEngine.Object[] mats, string

#region マテリアル値の取得

private static bool CanRead(Material mat, string name)
{
return mat != null && mat.HasProperty(name);
}

public static bool GetBool(Material mat, string name, bool _default)
{
if (mat.HasProperty(name))
if (CanRead(mat, name))
{
return mat.GetInt(name) != 0;
}
Expand All @@ -1009,7 +1014,7 @@ public static bool GetBool(Material mat, string name, bool _default)

public static int GetInt(Material mat, string name, int _default)
{
if (mat.HasProperty(name))
if (CanRead(mat, name))
{
return mat.GetInt(name);
}
Expand All @@ -1018,7 +1023,7 @@ public static int GetInt(Material mat, string name, int _default)

public static float GetFloat(Material mat, string name, float _default)
{
if (mat.HasProperty(name))
if (CanRead(mat, name))
{
return mat.GetFloat(name);
}
Expand All @@ -1027,7 +1032,7 @@ public static float GetFloat(Material mat, string name, float _default)

public static Color GetColor(Material mat, string name, Color _default)
{
if (mat.HasProperty(name))
if (CanRead(mat, name))
{
return mat.GetColor(name);
}
Expand All @@ -1036,7 +1041,7 @@ public static Color GetColor(Material mat, string name, Color _default)

public static Vector4 GetVector(Material mat, string name, Vector4 _default)
{
if (mat.HasProperty(name))
if (CanRead(mat, name))
{
return mat.GetVector(name);
}
Expand All @@ -1045,7 +1050,7 @@ public static Vector4 GetVector(Material mat, string name, Vector4 _default)

public static Texture GetTexture(Material mat, string name)
{
if (mat.HasProperty(name))
if (CanRead(mat, name))
{
return mat.GetTexture(name);
}
Expand All @@ -1058,7 +1063,7 @@ public static Texture GetTexture(Material mat, string name)

private static bool CanWrite(Material mat, string name)
{
return mat.HasProperty(name) && !IsPropertyLockedByAncestor(mat, name);
return mat != null && mat.HasProperty(name) && !IsPropertyLockedByAncestor(mat, name);
}

public static bool SetBool(Material mat, string name, bool value)
Expand Down Expand Up @@ -1123,7 +1128,7 @@ public static bool SetTexture(Material mat, string name, Texture value)

public static bool CopyFloatValue(Material mat, string from, string to)
{
if (mat.HasProperty(from) && CanWrite(mat, to))
if (CanRead(mat, from) && CanWrite(mat, to))
{
mat.SetFloat(to, mat.GetFloat(from));
return true;
Expand All @@ -1133,7 +1138,7 @@ public static bool CopyFloatValue(Material mat, string from, string to)

public static bool CopyIntValue(Material mat, string from, string to)
{
if (mat.HasProperty(from) && CanWrite(mat, to))
if (CanRead(mat, from) && CanWrite(mat, to))
{
mat.SetInt(to, mat.GetInt(from));
return true;
Expand All @@ -1143,7 +1148,7 @@ public static bool CopyIntValue(Material mat, string from, string to)

public static bool CopyTextureValue(Material mat, string from, string to)
{
if (mat.HasProperty(from) && CanWrite(mat, to))
if (CanRead(mat, from) && CanWrite(mat, to))
{
mat.SetTexture(to, mat.GetTexture(from));
return true;
Expand Down
9 changes: 9 additions & 0 deletions Editor/WF_Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ private static bool HasPropertyPrefix(Material mat, string prefix)
// その他の機能
new WFShaderFunction("BKT", "BKT", "BackFace Texture"),
new WFShaderFunction("CHM", "CHM", "3ch Color Mask"),
new WFShaderFunction("CGR", "CGR", "Gradient Map"),
new WFShaderFunction("CLC", "CLC", "Color Change"),
new WFShaderFunction("LME", "LME", "Lame"),
new WFShaderFunction("OVL", "OVL", "Overlay Texture"),
new WFShaderFunction("DFD", "DFD", "Distance Fade"),
new WFShaderFunction("DSV", "DSV", "Dissolve"),
new WFShaderFunction("LBE", "LBE", "Light Bake Effects"),

// カスタムシェーダ系
Expand Down Expand Up @@ -338,6 +340,7 @@ private static Dictionary<string, WFCustomKeywordSetting> ToWFCustomKeywordSetti
new WFI18NTranslation("BackFace Texture", "裏面テクスチャ"),
new WFI18NTranslation("Base", "基本設定"),
new WFI18NTranslation("ClearCoat", "クリアコート"),
new WFI18NTranslation("Gradient Map", "グラデーションマップ"),
new WFI18NTranslation("Color Change", "色変更"),
new WFI18NTranslation("Detail NormalMap", "ディテールノーマルマップ"),
new WFI18NTranslation("Distance Fade", "距離フェード"),
Expand Down Expand Up @@ -419,6 +422,10 @@ private static Dictionary<string, WFCustomKeywordSetting> ToWFCustomKeywordSetti
new WFI18NTranslation("FadeOut Distance (Near)", "フェードアウト距離 (Near)"),
new WFI18NTranslation("FadeOut Distance (Far)", "フェードアウト距離 (Far)"),
new WFI18NTranslation("Shadow Power", "影の濃さ"),
new WFI18NTranslation("Preview", "プレビュー"),
new WFI18NTranslation("Save", "保存"),
new WFI18NTranslation("Gamma", "ガンマ"),
new WFI18NTranslation("Create GradationMap Texture", "グラデーションマップ用テクスチャを作成"),
// Lit
new WFI18NTranslation("Unlit Intensity", "Unlit Intensity (最小明度)"),
new WFI18NTranslation("Saturate Intensity", "Saturate Intensity (飽和明度)"),
Expand Down Expand Up @@ -721,6 +728,7 @@ private static Dictionary<string, WFCustomKeywordSetting> ToWFCustomKeywordSetti
new WFI18NTranslation(WFMessageText.PsCapTypeMedian, "MEDIAN_CAPは灰色を基準とした加算&減算合成を行うmatcapです"),
new WFI18NTranslation(WFMessageText.PsCapTypeLight, "LIGHT_CAPは黒色を基準とした加算合成を行うmatcapです"),
new WFI18NTranslation(WFMessageText.PsCapTypeShade, "SHADE_CAPは白色を基準とした乗算合成を行うmatcapです"),
new WFI18NTranslation(WFMessageText.PsPreviewTexture, "プレビューテクスチャが設定されています。\nプレビューテクスチャは保存されません。"),

new WFI18NTranslation(WFMessageText.DgChangeMobile, "シェーダをMobile向けに切り替えますか?\n\nこの操作はUndoできますが、バックアップを取ることをお勧めします。"),
new WFI18NTranslation(WFMessageText.DgMigrationAuto, "UnlitWFシェーダがインポートされました。\nプロジェクト内に古いマテリアルが残っていないかスキャンしますか?"),
Expand Down Expand Up @@ -975,6 +983,7 @@ static class WFMessageText
public static readonly string PsCapTypeMedian = "MEDIAN_CAP is a matcap that performs gray-based additive and subtractive blending.";
public static readonly string PsCapTypeLight = "LIGHT_CAP is a matcap that performs black-based additive blending.";
public static readonly string PsCapTypeShade = "SHADE_CAP is a matcap that performs white-based multiply blending.";
public static readonly string PsPreviewTexture = "A preview texture is set that cannot be saved.";
public static readonly string DgChangeMobile = "Do you want to change those shader for Mobile?\n\nYou can undo this operation, but we recommend that you make a backup.";
public static readonly string DgMigrationAuto = "UnlitWF shaders have been imported.\nDo you want to scan for old materials still in the project?";
public static readonly string DgMigrationManual = "Do you want to scan the materials in your project and update them to the latest material values?";
Expand Down
37 changes: 37 additions & 0 deletions Editor/WF_MaterialConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,43 @@ protected static List<Action<SelectShaderContext>> CreateConverterList()
}
}
},
ctx => {
// 色変換
var p = ctx.oldProps.GetValueOrNull("_MainTexHSVG");
if (p != null && (p.Type == ShaderUtil.ShaderPropertyType.Vector || p.Type == ShaderUtil.ShaderPropertyType.Color)) {
var hsv = p.ColorValue;
if (hsv.r != 0 || hsv.g != 1 || hsv.b != 1 || hsv.a != 1)
{
WFAccessor.SetBool(ctx.target, "_CLC_Enable", true);
WFAccessor.SetFloat(ctx.target, "_CLC_DeltaH", 0 <= hsv.r ? hsv.r : (hsv.r + 1));
WFAccessor.SetFloat(ctx.target, "_CLC_DeltaS", hsv.g - 1);
WFAccessor.SetFloat(ctx.target, "_CLC_DeltaV", hsv.b - 1);
WFAccessor.SetFloat(ctx.target, "_CLC_Gamma", hsv.a);
}
var t = ctx.oldProps.GetValueOrNull("_MainColorAdjustMask");
if (t != null && t.Type == ShaderUtil.ShaderPropertyType.TexEnv)
{
var tex = t.TextureValue;
WFAccessor.SetTexture(ctx.target, "_CLC_MaskTex", tex);
}
}
},
ctx => {
// グラデーションマップ
if (HasOldPropertyValue(ctx, "_MainGradationTex"))
{
WFAccessor.SetBool(ctx.target, "_CGR_Enable", true);
WFMaterialEditUtility.ReplacePropertyNamesWithoutUndo(ctx.target,
PropertyNameReplacement.MatchIgnoreCase("_MainGradationTex", "_CGR_GradMapTex")
);
var t = ctx.oldProps.GetValueOrNull("_MainColorAdjustMask");
if (t != null && t.Type == ShaderUtil.ShaderPropertyType.TexEnv)
{
var tex = t.TextureValue;
WFAccessor.SetTexture(ctx.target, "_CGR_MaskTex", tex);
}
}
},
ctx => {
// プロパティ名変更終了
WFMaterialEditUtility.EndReplacePropertyNames(ctx.target);
Expand Down
Loading

0 comments on commit b431670

Please sign in to comment.