Skip to content

Commit

Permalink
comitting progress on #17
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlackParrot committed Feb 9, 2025
1 parent 33e5c0e commit 4091320
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 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);
}
}
36 changes: 15 additions & 21 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 @@ -231,34 +239,20 @@ private static void UpdateAccDotMaterial()

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

Plugin.Log.Info("Creating outline materials");
Material arrowMat0 = Resources.FindObjectsOfTypeAll<Material>().ToList().Find(x => x.name == "NoteArrowLW");
OutlineMaterial0 = new Material(arrowMat0)
{
name = "NoteTweaks_OutlineMaterialLW",
color = Color.black,
shaderKeywords = arrowMat0.shaderKeywords.Where(x => x != "_ENABLE_COLOR_INSTANCING" || x != "_CUTOUT_NONE").ToArray(),
renderQueue = 1990
};

Plugin.Log.Info("Creating outline material");
Material arrowMat1 = Resources.FindObjectsOfTypeAll<Material>().ToList().Find(x => x.name == "NoteArrowHD");
OutlineMaterial1 = new Material(arrowMat1)
OutlineMaterial = new Material(arrowMat1)
{
name = "NoteTweaks_OutlineMaterialHD",
color = Color.black,
shaderKeywords = arrowMat1.shaderKeywords.Where(x => x != "_ENABLE_COLOR_INSTANCING" || x != "_CUTOUT_NONE").ToArray(),
renderQueue = 1990
};

//arrowMat0.SetInt(ZTestID, (int)UnityEngine.Rendering.CompareFunction.GreaterEqual);
//arrowMat1.SetInt(ZTestID, (int)UnityEngine.Rendering.CompareFunction.GreaterEqual);
//arrowMat0.SetInt("_CustomZWrite", 0);
//arrowMat1.SetInt("_CustomZWrite", 0);
}

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 @@ -157,12 +157,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 @@ -210,7 +210,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 @@ -380,7 +380,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 @@ -485,8 +485,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 @@ -603,8 +602,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 @@ -502,7 +501,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 4091320

Please sign in to comment.