Skip to content

Commit

Permalink
feat: 그림자 조정 기능 추가
Browse files Browse the repository at this point in the history
- 환경광에 의한 그림자 색을 조정할 수 있음
  • Loading branch information
noridev committed Sep 25, 2024
1 parent 2fcc6aa commit 81fa918
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG_NRDV.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.x.x] - 2024-x-x
기반 LightLimitChanger 버전: <b>1.x.x</b>

### Added
- 그림자 조정 기능 추가
- 환경광에 의한 그림자 색을 조정할 수 있음

### Changed
- Poiyomi Toon 셰이더 업데이트 (<small>9.0.56</small> -> 9.0.61)

Expand Down
4 changes: 3 additions & 1 deletion Editor/ControlAnimationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public readonly struct ControlAnimationParameters
public readonly float DefaultMaxLightValue;
public readonly float DefaultMonochromeLightingValue;
public readonly float DefaultMonochromeAdditiveLightingValue;
public readonly float DefaultShadowEnvStrengthValue;

public ControlAnimationParameters(string targetPath, Type targetType, float minLightValue, float maxLightValue, float defaultMinLightValue, float defaultMaxLightValue, float defaultMonochromeLightingValue, float defaultMonochromeAdditiveLightingValue)
public ControlAnimationParameters(string targetPath, Type targetType, float minLightValue, float maxLightValue, float defaultMinLightValue, float defaultMaxLightValue, float defaultMonochromeLightingValue, float defaultMonochromeAdditiveLightingValue, float defaultShadowEnvStrengthValue)
{
TargetPath = targetPath;
TargetType = targetType;
Expand All @@ -24,6 +25,7 @@ public ControlAnimationParameters(string targetPath, Type targetType, float minL
DefaultMaxLightValue = defaultMaxLightValue;
DefaultMonochromeLightingValue = defaultMonochromeLightingValue;
DefaultMonochromeAdditiveLightingValue = defaultMonochromeAdditiveLightingValue;
DefaultShadowEnvStrengthValue = defaultShadowEnvStrengthValue;
}
}
}
16 changes: 14 additions & 2 deletions Editor/LightLimitChangerSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal sealed class LightLimitChangerSettingsEditor : Editor
private SerializedProperty AllowMonochromeControl;
private SerializedProperty AllowUnlitControl;
private SerializedProperty AllowEmissionControl;
private SerializedProperty AllowShadowControl;
private SerializedProperty InitialTempControlValue;
private SerializedProperty InitialSaturationControlValue;
private SerializedProperty InitialMonochromeControlValue;
Expand All @@ -33,6 +34,7 @@ internal sealed class LightLimitChangerSettingsEditor : Editor
private SerializedProperty Excludes;
private SerializedProperty WriteDefaults;
private SerializedProperty MonochromeAdditiveLightingValue;
private SerializedProperty ShadowEnvStrengthValue;

private static bool _isOptionFoldoutOpen = true;
private static bool _isCepareteInitValFoldoutOpen = false;
Expand All @@ -59,6 +61,7 @@ private void OnEnable()
AllowMonochromeControl = parameters.FindPropertyRelative(nameof(LightLimitChangerParameters.AllowMonochromeControl));
AllowUnlitControl = parameters.FindPropertyRelative(nameof(LightLimitChangerParameters.AllowUnlitControl));
AllowEmissionControl = parameters.FindPropertyRelative(nameof(LightLimitChangerParameters.AllowEmissionControl));
AllowShadowControl = parameters.FindPropertyRelative(nameof(LightLimitChangerParameters.AllowShadowControl));
InitialTempControlValue = parameters.FindPropertyRelative(nameof(LightLimitChangerParameters.InitialTempControlValue));
InitialSaturationControlValue = parameters.FindPropertyRelative(nameof(LightLimitChangerParameters.InitialSaturationControlValue));
InitialMonochromeControlValue = parameters.FindPropertyRelative(nameof(LightLimitChangerParameters.InitialMonochromeControlValue));
Expand All @@ -70,6 +73,7 @@ private void OnEnable()
Excludes = serializedObject.FindProperty(nameof(LightLimitChangerSettings.Excludes));
WriteDefaults = serializedObject.FindProperty(nameof(LightLimitChangerSettings.WriteDefaults));
MonochromeAdditiveLightingValue = parameters.FindPropertyRelative(nameof(LightLimitChangerParameters.MonochromeAdditiveLightingValue));
ShadowEnvStrengthValue = parameters.FindPropertyRelative(nameof(LightLimitChangerParameters.ShadowEnvStrengthValue));
}

public override void OnInspectorGUI()
Expand Down Expand Up @@ -159,6 +163,8 @@ public override void OnInspectorGUI()
Localization.G("label.allow_color_tmp", "tip.allow_color_tmp"));
EditorGUILayout.PropertyField(AllowSaturationControl,
Localization.G("label.allow_saturation", "tip.allow_saturation"));
EditorGUILayout.PropertyField(AllowShadowControl,
Localization.G("label.allow_shadow", "tip.allow_shadow"));
EditorGUILayout.PropertyField(AllowMonochromeControl,
Localization.G("label.allow_monochrome", "tip.allow_monochrome"));
EditorGUI.BeginDisabledGroup(AllowMonochromeControl.boolValue == false);
Expand Down Expand Up @@ -194,7 +200,14 @@ public override void OnInspectorGUI()
EditorGUI.BeginDisabledGroup(AllowSaturationControl.boolValue == false);
EditorGUILayout.PropertyField(InitialSaturationControlValue, Localization.G(""));
EditorGUI.EndDisabledGroup();

}
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.Space(10);
EditorGUILayout.LabelField(Localization.G("label.shadow_env_strength"), GUILayout.MaxWidth(70.0f), GUILayout.ExpandWidth(false));
EditorGUI.BeginDisabledGroup(AllowShadowControl.boolValue == false);
EditorGUILayout.PropertyField(ShadowEnvStrengthValue, Localization.G(""));
EditorGUI.EndDisabledGroup();
}
using (new EditorGUILayout.HorizontalScope())
{
Expand All @@ -204,7 +217,6 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(InitialMonochromeControlValue, Localization.G(""));
EditorGUI.EndDisabledGroup();
}

using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.Space(10);
Expand Down
3 changes: 2 additions & 1 deletion Editor/LightLimitControlType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum LightLimitControlType : long
Monochrome = 1 << 6,
MonochromeAdditive = 1 << 7,
Emission = 1 << 8,
ShadowEnvStrength = 1 << 9,

AdditionalControls = Saturation | Unlit | ColorTemperature | Monochrome | MonochromeAdditive | Emission,
AdditionalControls = Saturation | Unlit | ColorTemperature | Monochrome | MonochromeAdditive | Emission | ShadowEnvStrength,
}
}
40 changes: 40 additions & 0 deletions Editor/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ internal static class Localization
"채도 조정 활성화"
}
},
{
"label.allow_shadow", new []
{
"Enable Unlit Control",
"影調整を有効にする",
"啟用陰影控制",
"启用陰影控制",
"그림자 조정 활성화"
}
},
{
"label.allow_monochrome", new []
{
Expand Down Expand Up @@ -375,6 +385,16 @@ internal static class Localization
"채도"
}
},
{
"label.shadow_env_strength", new []
{
"Shadow Environment Strength",
"環境光",
"環境迷",
"环境迷",
"환경광에 의한 그림자 색"
}
},
{
"label.monochrome", new []
{
Expand Down Expand Up @@ -640,6 +660,16 @@ internal static class Localization
"채도 조정 기능을 활성화할 수 있습니다"
}
},
{
"tip.allow_shadow", new []
{
"Enables shadow adjustment functionality",
"影の調整機能を有効化することができます",
"啟用陰影度調整功能",
"启用陰影度调整功能",
"그림자 조정 기능을 활성화할 수 있습니다"
}
},
{
"tip.allow_monochrome", new []
{
Expand Down Expand Up @@ -987,6 +1017,16 @@ 최신 버전의 Poiyomi Shader로 업데이트 해야 기능을 정상적으로
"채도"
}
},
{
"ExpressionMenu.shadow_env_strength", new []
{
"Shadow Env Strength",
"環境光",
"環境迷",
"环境迷",
"환경광"
}
},
{
"ExpressionMenu.unlit", new []
{
Expand Down
3 changes: 3 additions & 0 deletions Editor/NDMF/ParameterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public IEnumerable<ProvidedParameter> GetSuppliedParameters(BuildContext context
if (parameters.AllowSaturationControl)
yield return Parameter<float>(Passes.ParameterName_Saturation);

if (parameters.AllowShadowControl)
yield return Parameter<float>(Passes.ParameterName_ShadowEnvStrength);

if (parameters.AllowMonochromeControl)
{
yield return Parameter<float>(Passes.ParameterName_Monochrome);
Expand Down
8 changes: 5 additions & 3 deletions Editor/NDMF/Passes.GenerateAnimationsPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ internal static void Run(Session session, LightLimitChangerObjectCache cache)
var min = parameters.MinLightValue;
var max = parameters.MaxLightValue;

float defaultMinLight, defaultMaxLight, defaultMonochromeLighting, defaultMonochromeAdditiveLighting;
float defaultMinLight, defaultMaxLight, defaultMonochromeLighting, defaultMonochromeAdditiveLighting, defaultShadowEnvStrength;
if (!parameters.OverwriteDefaultLightMinMax &&
renderer.sharedMaterial is Material mat &&
x.IsTargetShader(mat?.shader) &&
x.TryGetLightMinMaxValue(mat, out defaultMinLight, out defaultMaxLight) &&
x.TryGetMonochromeValue(mat, out defaultMonochromeLighting, out defaultMonochromeAdditiveLighting))
x.TryGetMonochromeValue(mat, out defaultMonochromeLighting, out defaultMonochromeAdditiveLighting) &&
x.TryGetShadowEnvStrengthValue(mat, out defaultShadowEnvStrength))
{
// OverwriteDefaultLightMinMax disabled.
// Now we get defaultMinLight and defaultMaxLight from first material slot.
Expand All @@ -52,6 +53,7 @@ renderer.sharedMaterial is Material mat &&
{
defaultMonochromeLighting = parameters.InitialMonochromeControlValue;
defaultMonochromeAdditiveLighting = parameters.MonochromeAdditiveLightingValue;
defaultShadowEnvStrength = parameters.ShadowEnvStrengthValue;

if (parameters.IsSeparateLightControl)
{
Expand All @@ -67,7 +69,7 @@ renderer.sharedMaterial is Material mat &&
}
}

var param = new ControlAnimationParameters(relativePath, type, min, max, defaultMinLight, defaultMaxLight, defaultMonochromeLighting, defaultMonochromeAdditiveLighting);
var param = new ControlAnimationParameters(relativePath, type, min, max, defaultMinLight, defaultMaxLight, defaultMonochromeLighting, defaultMonochromeAdditiveLighting, defaultShadowEnvStrength);
foreach (ref readonly var container in animationContainers)
{
x.SetControlAnimation(container, param, parameters);
Expand Down
7 changes: 7 additions & 0 deletions Editor/NDMF/Passes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static void RunningPasses(Sequence sequence)
internal const string ParameterName_Reset = "LightLimitReset";
internal const string ParameterName_Monochrome = "LightLimitMonochrome";
internal const string ParameterName_MonochromeAdditive = "LightLimitMonochromeAdditive";
internal const string ParameterName_ShadowEnvStrength = "LightLimitShadowEnvStrength";

private static Session GetSession(BuildContext context)
{
Expand Down Expand Up @@ -163,6 +164,12 @@ public void InitializeSession(LightLimitChangerSettings settings, LightLimitChan
controls.Add(ControlAnimationContainer.Create(LightLimitControlType.Emission, Localization.S("ExpressionMenu.emission"), "Emission", ParameterName_Emission, 1.0f, Icons.Emission, defaultAnimation));
}

if (parameters.AllowShadowControl)
{
targetControl |= LightLimitControlType.ShadowEnvStrength;
controls.Add(ControlAnimationContainer.Create(LightLimitControlType.ShadowEnvStrength, Localization.S("ExpressionMenu.shadow_env_strength"), "Shadow Environment Strength", ParameterName_ShadowEnvStrength, parameters.ShadowEnvStrengthValue, Icons.Unlit, defaultAnimation));
}


Controls = controls.ToArray();

Expand Down
15 changes: 15 additions & 0 deletions Editor/ShaderInfo/ShaderInfo.LilToon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed class LilToon : ShaderInfo
public const string _MonochromeLighting = "_MonochromeLighting";
public const string _EmissionBlend = "_EmissionBlend";
public const string _Emission2ndBlend = "_Emission2ndBlend";
public const string _ShadowEnvStrength = "_ShadowEnvStrength";

private static class PropertyIDs
{
Expand All @@ -43,6 +44,7 @@ private static class PropertyIDs
public static readonly int MainGradationStrength = Shader.PropertyToID(_MainGradationStrength);
public static readonly int MainColorAdjustMask = Shader.PropertyToID(_MainColorAdjustMask);
public static readonly int MonochromeLighting = Shader.PropertyToID(_MonochromeLighting);
public static readonly int ShadowEnvStrength = Shader.PropertyToID(_ShadowEnvStrength);
}

private static class DefaultParameters
Expand All @@ -55,6 +57,7 @@ private static class DefaultParameters
public static readonly Vector4 MainTexHSVG = new Vector4(0, 1, 1, 1);
public static readonly float MainGradationStrength = 0;
public static readonly float MonochromeLighting = 0;
public static readonly float ShadowEnvStrength = 0;
}

public override bool TryNormalizeMaterial(Material material, LightLimitChangerObjectCache cache)
Expand Down Expand Up @@ -231,6 +234,12 @@ public override void SetControlAnimation(in ControlAnimationContainer container,
container.Control.SetColorTempertureAnimation(parameters, _Color3rd);
}

if (container.ControlType.HasFlag(LightLimitControlType.ShadowEnvStrength))
{
container.Default.SetParameterAnimation(parameters, _ShadowEnvStrength, parameters.DefaultShadowEnvStrengthValue);
container.Control.SetParameterAnimation(parameters, _ShadowEnvStrength, 0, 1);
}

}

public override bool TryGetLightMinMaxValue(Material material, out float min, out float max)
Expand All @@ -246,6 +255,12 @@ public override bool TryGetMonochromeValue(Material material, out float monochro
monochromeAdditive = 1;
return true;
}

public override bool TryGetShadowEnvStrengthValue(Material material, out float shadowEnvStrength)
{
shadowEnvStrength = material.GetOrDefault(PropertyIDs.ShadowEnvStrength, DefaultParameters.ShadowEnvStrength);
return true;
}
}
}
}
Loading

0 comments on commit 81fa918

Please sign in to comment.