Skip to content

Commit

Permalink
comitting progress on #17
Browse files Browse the repository at this point in the history
(cherry picked from commit 4091320)
  • Loading branch information
TheBlackParrot committed Feb 11, 2025
1 parent 2ae8bf2 commit 963e5bc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 65 deletions.
8 changes: 7 additions & 1 deletion NoteTweaks/Managers/DynamicColorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ internal abstract class RainbowGradient
{
private static PluginConfig Config => PluginConfig.Instance;
private static float Time => UnityEngine.Time.time;
public static Color Color => Color.HSVToRGB((Time / Config.RainbowBombTimeScale * 3.0f) % 1.0f, Config.RainbowBombSaturation, Config.RainbowBombValue) * (1.0f + Config.BombColorBoost);
public static Color Color =>
(Color.HSVToRGB(
(Time / Config.RainbowBombTimeScale * 3.0f) % 1.0f,
Config.RainbowBombSaturation,
Config.RainbowBombValue)
* (1.0f + Config.BombColorBoost))
.ColorWithAlpha(Materials.SaneAlphaValue);
}
}
68 changes: 18 additions & 50 deletions NoteTweaks/Managers/MaterialManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ internal abstract class Materials
internal static Material NoteMaterial;
internal static Material DebrisMaterial;
internal static Material BombMaterial;
internal static Material OutlineMaterial0;
internal static Material OutlineMaterial1;
internal static Material OutlineMaterial;

internal static readonly Material AccDotDepthMaterial = new Material(Resources.FindObjectsOfTypeAll<Shader>().First(x => x.name == "Custom/ClearDepth"))
{
Expand All @@ -45,6 +44,9 @@ internal abstract class Materials
new KeyValuePair<string, int>("Smoothness", Shader.PropertyToID("_Smoothness")),
new KeyValuePair<string, int>("RimCameraDistanceOffset", Shader.PropertyToID("_RimCameraDistanceOffset"))
};

private static readonly BoolSO MainEffectContainer = Resources.FindObjectsOfTypeAll<BoolSO>().First(x => x.name.StartsWith("MainEffectContainer"));
internal static float SaneAlphaValue => MainEffectContainer.value ? 1f : 0f;

internal static async Task UpdateAll()
{
Expand Down Expand Up @@ -97,8 +99,7 @@ internal static void UpdateFogValues(string which = null)
NoteMaterial.SetFloat(keyword.Value, value);
DebrisMaterial.SetFloat(keyword.Value, value);
BombMaterial.SetFloat(keyword.Value, value);
OutlineMaterial0.SetFloat(keyword.Value, value);
OutlineMaterial1.SetFloat(keyword.Value, value);
OutlineMaterial.SetFloat(keyword.Value, value);
AccDotMaterial.SetFloat(keyword.Value, value);
}
});
Expand Down Expand Up @@ -141,6 +142,13 @@ private static void UpdateReplacementDotMaterial()
color = Color.white,
shaderKeywords = arrowMat.shaderKeywords.Where(x => x != "_ENABLE_COLOR_INSTANCING" || x != "_CUTOUT_NONE").ToArray()
};

foreach (string propertyName in ReplacementDotMaterial.GetPropertyNames(MaterialPropertyType.Float))
{
Plugin.Log.Info($"{propertyName} = {ReplacementDotMaterial.GetFloat(propertyName)}");
}

//ReplacementDotMaterial.SetFloat("_BlendSrcFactor");
}

private static void UpdateReplacementArrowMaterial()
Expand Down Expand Up @@ -234,11 +242,11 @@ private static void UpdateAccDotMaterial()

private static void UpdateOutlineMaterial()
{
if (OutlineMaterial0 != null)
if (OutlineMaterial != null)
{
return;
}

if (_blankCubemap == null)
{
_blankCubemap = new Cubemap(512, TextureFormat.RGBA32, false);
Expand All @@ -257,26 +265,19 @@ private static void UpdateOutlineMaterial()
_blankCubemap.Apply();
}

Plugin.Log.Info("Creating outline materials");
Plugin.Log.Info("Creating outline material");

Material noteMat = Resources.FindObjectsOfTypeAll<Material>().ToList().Find(x => x.name == "NoteLW");
string[] keywords = noteMat.shaderKeywords
.Where(x => x != "_ENABLE_COLOR_INSTANCING" || x != "_CUTOUT_NONE" || x != "_ENABLE_RIM_DIM" || x != "_ENABLE_RIM_COLOR").ToArray();

OutlineMaterial0 = new Material(noteMat)
OutlineMaterial = new Material(noteMat)
{
name = "NoteTweaks_OutlineMaterialLW",
color = Color.white,
shaderKeywords = keywords,
renderQueue = 1990
};
OutlineMaterial1 = new Material(noteMat)
{
name = "NoteTweaks_OutlineMaterialHD",
color = Color.white,
shaderKeywords = keywords,
renderQueue = 1990
};

new List<KeyValuePair<string, float>>
{
Expand All @@ -285,41 +286,8 @@ private static void UpdateOutlineMaterial()
new KeyValuePair<string, float>("_RimDarkening", 0),
new KeyValuePair<string, float>("_RimScale", 0),
new KeyValuePair<string, float>("_Smoothness", 0)
}.Do(pair =>
{
OutlineMaterial0.SetFloat(pair.Key, pair.Value);
OutlineMaterial1.SetFloat(pair.Key, pair.Value);
});
OutlineMaterial0.SetTexture(EnvironmentReflectionCubeID, _blankCubemap);
OutlineMaterial1.SetTexture(EnvironmentReflectionCubeID, _blankCubemap);

/*for (int i = 0; i < OutlineMaterial1.shader.GetPropertyCount(); i++)
{
Plugin.Log.Info($"{OutlineMaterial1.shader.GetPropertyName(i)} -- {OutlineMaterial1.GetFloat(OutlineMaterial1.shader.GetPropertyNameId(i))}");
}
Plugin.Log.Info("----");
OutlineMaterial0.shaderKeywords.Do(x => Plugin.Log.Info(x));
Plugin.Log.Info("----");
OutlineMaterial1.shaderKeywords.Do(x => Plugin.Log.Info(x));
Plugin.Log.Info("----");
Resources.FindObjectsOfTypeAll<Shader>().Do(shader =>
{
Plugin.Log.Info(shader.name);
for (int i = 0; i < shader.GetPropertyCount(); i++)
{
if (shader.GetPropertyName(i).Contains("Cull"))
{
Plugin.Log.Info($"!! {shader.name} contains {shader.GetPropertyName(i)}");
}
}
});
Plugin.Log.Info("----");
Resources.FindObjectsOfTypeAll<Material>().Do(material =>
{
Plugin.Log.Info(material.name);
});*/
}.Do(pair => OutlineMaterial.SetFloat(pair.Key, pair.Value));
OutlineMaterial.SetTexture(EnvironmentReflectionCubeID, _blankCubemap);
}

private static async Task UpdateNoteMaterial()
Expand Down
6 changes: 3 additions & 3 deletions NoteTweaks/Managers/OutlineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ public static void AddOutlineObject(Transform rootTransform, Mesh wantedMesh)
outlineMaterialPropertyBlockController.SetField("_renderers", new [] { outlineRenderer });

outlineMeshFilter.sharedMesh = wantedMesh;
outlineRenderer.sharedMaterial = Materials.OutlineMaterial1;
outlineRenderer.sharedMaterial = Materials.OutlineMaterial;
outlineRenderer.SetPropertyBlock(outlineMaterialPropertyBlockController.materialPropertyBlock);
outlineCutoutEffect._materialPropertyBlockController = outlineMaterialPropertyBlockController;

outlineMaterialSwitcher._material0 = Materials.OutlineMaterial0;
outlineMaterialSwitcher._material1 = Materials.OutlineMaterial1;
outlineMaterialSwitcher._material0 = Materials.OutlineMaterial;
outlineMaterialSwitcher._material1 = Materials.OutlineMaterial;
outlineMaterialSwitcher._renderer = outlineRenderer;
if (rootTransform.TryGetComponent(out ConditionalMaterialSwitcher switcher))
{
Expand Down
6 changes: 4 additions & 2 deletions NoteTweaks/Patches/BombPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ internal static void BombNoteControllerInitPatch(BombNoteController __instance)

if (noteOutline.gameObject.TryGetComponent(out MaterialPropertyBlockController controller))
{
controller.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId,
Color outlineColor =
Config.EnableRainbowBombs && (Config.RainbowBombMode == "Both" ||
Config.RainbowBombMode == "Only Outlines")
? RainbowGradient.Color
: Config.BombOutlineColor);
: Config.BombOutlineColor;

controller.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId, outlineColor.ColorWithAlpha(Materials.SaneAlphaValue));
controller.ApplyChanges();
}
}
Expand Down
9 changes: 3 additions & 6 deletions NoteTweaks/Patches/NoteArrowPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ internal static void Postfix(ref BurstSliderGameNoteController __instance, ref B

Color outlineColor = Color.LerpUnclamped(isLeft ? Config.NoteOutlineLeftColor : Config.NoteOutlineRightColor, noteColor, isLeft ? Config.NoteOutlineLeftColorSkew : Config.NoteOutlineRightColorSkew);

controller.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId, outlineColor);
controller.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId, outlineColor.ColorWithAlpha(Materials.SaneAlphaValue));
controller.ApplyChanges();
}
}
Expand Down Expand Up @@ -383,7 +383,7 @@ internal static void Postfix(ref GameNoteController __instance, ref BoxCuttableB

Color outlineColor = Color.LerpUnclamped(isLeft ? Config.NoteOutlineLeftColor : Config.NoteOutlineRightColor, noteColor, isLeft ? Config.NoteOutlineLeftColorSkew : Config.NoteOutlineRightColorSkew);

controller.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId, outlineColor);
controller.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId, outlineColor.ColorWithAlpha(Materials.SaneAlphaValue));
controller.ApplyChanges();
}
}
Expand Down Expand Up @@ -488,8 +488,7 @@ internal static void Postfix(ColorNoteVisuals __instance, ref MeshRenderer[] ___
}

Color c = Color.LerpUnclamped(isLeft ? Config.LeftFaceColor : Config.RightFaceColor, faceColor, isLeft ? Config.LeftFaceColorNoteSkew : Config.RightFaceColorNoteSkew);
c.a = 1f;
materialPropertyBlockController.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId, c);
materialPropertyBlockController.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId, c.ColorWithAlpha(Materials.SaneAlphaValue));
materialPropertyBlockController.ApplyChanges();
}

Expand Down Expand Up @@ -602,8 +601,6 @@ internal static void Postfix(ColorNoteVisuals __instance, ref MeshRenderer[] ___
CutoutEffect cutoutEffect = originalDotTransform.gameObject.AddComponent<CutoutEffect>();
cutoutEffect._materialPropertyBlockController = materialPropertyBlockController;
cutoutEffect._useRandomCutoutOffset = parentCutoutEffect._useRandomCutoutOffset;
//cutoutEffect._cutout = 0f;
//materialPropertyBlockController.materialPropertyBlock.SetFloat(CutoutEffect._cutoutPropertyID, 0f);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions NoteTweaks/UI/PreviewViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ public static void UpdateColors()
faceColor /= colorScalar;
}

faceColor = Color.LerpUnclamped(i % 2 == 0 ? Config.LeftFaceColor : Config.RightFaceColor, faceColor, i % 2 == 0 ? Config.LeftFaceColorNoteSkew : Config.RightFaceColorNoteSkew);
faceColor.a = 1f;
faceColor = Color.LerpUnclamped(i % 2 == 0 ? Config.LeftFaceColor : Config.RightFaceColor, faceColor, i % 2 == 0 ? Config.LeftFaceColorNoteSkew : Config.RightFaceColorNoteSkew).ColorWithAlpha(Materials.SaneAlphaValue);

Color glowColor = Color.LerpUnclamped(i % 2 == 0 ? Config.LeftFaceGlowColor : Config.RightFaceGlowColor, noteColor, i % 2 == 0 ? Config.LeftFaceGlowColorNoteSkew : Config.RightFaceGlowColorNoteSkew);

Expand Down Expand Up @@ -507,7 +506,7 @@ public static void UpdateOutlines()

if (noteOutline.gameObject.TryGetComponent(out MaterialPropertyBlockController controller))
{
controller.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId, outlineColor);
controller.materialPropertyBlock.SetColor(ColorNoteVisuals._colorId, outlineColor.ColorWithAlpha(Materials.SaneAlphaValue));
controller.ApplyChanges();
}
}
Expand Down

0 comments on commit 963e5bc

Please sign in to comment.