fix(skeleton): hide the helmet on the menu preview too
SkeletonRace hides it every frame, but that script only ever runs for the local player in a loaded world - so the moment the body swap started working in the menu, the helmet came back with it. Hiding it from the visuals postfix instead covers the preview, remote players and the first frame after a race change, none of which reach SkeletonRace. Scaled to zero rather than deactivated, since Valheim re-enables the instance on every refresh, and restored only from zero so another race scaling the same helmet is left alone. Armour is untouched, as asked. fix(dvergar): stop the two-star tier turning back into a pink human The star offsets are authored against a dverger's own texture, where a brightened, desaturated result is a pale dverger. Ours multiplies the human skin texture, where the same result is white - and a white multiplier is no tint at all, which is exactly what two stars produced: an ordinary human. One star survived only because its offset was smaller. Saturation now has a floor and value a ceiling, so a tier can shift the colour but never wash it out. The resolved offsets and the colour each one lands on are logged once per session, so if a tier still reads wrong it can be tuned against the real numbers rather than by eye.
This commit is contained in:
parent
eabc1c54bf
commit
9f6308ec94
3 changed files with 64 additions and 7 deletions
|
|
@ -62,6 +62,15 @@ namespace RacesOfValheim
|
|||
public const int OneStarState = 4; // Bonemass
|
||||
public const int TwoStarState = 8; // Fader
|
||||
|
||||
// Those offsets are authored against a dverger's own texture. Ours is a multiplier over
|
||||
// the human skin, where white means "no tint at all" - so an offset that brightens and
|
||||
// desaturates far enough lands on white and hands back an ordinary pink human. That is
|
||||
// exactly what the two-star tier did. These bounds keep every tier recognisably the same
|
||||
// colour, shifted rather than washed out.
|
||||
public const float StarMinSaturation = 0.25f;
|
||||
public const float StarMinValue = 0.20f;
|
||||
public const float StarMaxValue = 0.85f;
|
||||
|
||||
// ─── Cosmetic hood ───────────────────────────────────────────────────
|
||||
// The helmet slot itself stays free — whatever the player equips keeps all of its stats,
|
||||
// only the mesh is swapped.
|
||||
|
|
|
|||
|
|
@ -127,23 +127,39 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
cachedStarSetups = effects.m_levelSetups.ToArray();
|
||||
Jotunn.Logger.LogInfo(
|
||||
$"[Dvergar] Star colours resolved: {cachedStarSetups.Length} setups from " +
|
||||
$"'{DvergarConfig.DvergerPrefabName}'.");
|
||||
|
||||
// The offsets themselves, so a tier that lands on the wrong colour can be tuned
|
||||
// against the real numbers rather than by eye.
|
||||
for (int i = 0; i < cachedStarSetups.Length; i++)
|
||||
{
|
||||
LevelEffects.LevelSetup setup = cachedStarSetups[i];
|
||||
Jotunn.Logger.LogInfo(
|
||||
$"[Dvergar] Star {i + 1}: hue={setup.m_hue:F3} saturation={setup.m_saturation:F3} " +
|
||||
$"value={setup.m_value:F3} emissive={(setup.m_setEmissiveColor ? setup.m_emissiveColor.ToString() : "none")} " +
|
||||
$"-> skin {ShiftHsv(DvergarConfig.SkinColor, setup.m_hue, setup.m_saturation, setup.m_value)}");
|
||||
}
|
||||
|
||||
return cachedStarSetups;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies an HSV offset the way the creature shader does - hue wraps, the other two
|
||||
/// clamp - so the result is the same shift a starred dverger gets, on our colour.
|
||||
/// Applies a star's HSV offset to our tint. Hue wraps the way the creature shader's does;
|
||||
/// saturation and value are bounded rather than merely clamped to 0..1.
|
||||
///
|
||||
/// The bounds are the whole trick. The shader applies these offsets to a dverger's own
|
||||
/// texture, where a bright desaturated result is a pale dverger. Ours multiplies the human
|
||||
/// skin texture, where the same result is *white* - and a white multiplier is no tint at
|
||||
/// all, which is why the two-star Dvergar came out looking like an ordinary pink human.
|
||||
/// Keeping saturation off the floor and value off the ceiling means every tier stays a
|
||||
/// colour.
|
||||
/// </summary>
|
||||
private static Color ShiftHsv(Color color, float hue, float saturation, float value)
|
||||
{
|
||||
Color.RGBToHSV(color, out float h, out float s, out float v);
|
||||
|
||||
h = Mathf.Repeat(h + hue, 1f);
|
||||
s = Mathf.Clamp01(s + saturation);
|
||||
v = Mathf.Clamp01(v + value);
|
||||
s = Mathf.Clamp(s + saturation, DvergarConfig.StarMinSaturation, 1f);
|
||||
v = Mathf.Clamp(v + value, DvergarConfig.StarMinValue, DvergarConfig.StarMaxValue);
|
||||
|
||||
Color shifted = Color.HSVToRGB(h, s, v);
|
||||
shifted.a = color.a;
|
||||
|
|
|
|||
|
|
@ -335,6 +335,7 @@ namespace RacesOfValheim
|
|||
|
||||
HideItemInstances(__instance, "m_hairItemInstances");
|
||||
HideItemInstances(__instance, "m_beardItemInstances");
|
||||
SetHelmetVisible(__instance, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -358,10 +359,41 @@ namespace RacesOfValheim
|
|||
|
||||
ShowItemInstances(__instance, "m_hairItemInstances");
|
||||
ShowItemInstances(__instance, "m_beardItemInstances");
|
||||
SetHelmetVisible(__instance, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A helmet on a skull looks like a helmet floating in a skull, so the race hides it.
|
||||
///
|
||||
/// SkeletonRace does this every frame in a world, but it only ever runs for the local
|
||||
/// player - which is why the helmet came back on the main-menu preview once the body
|
||||
/// swap started working there. Doing it here covers the menu, remote players and the
|
||||
/// first frame after a race change, all of which reach this postfix and none of which
|
||||
/// reach SkeletonRace.
|
||||
///
|
||||
/// Scaled rather than deactivated, because Valheim re-enables the instance whenever it
|
||||
/// refreshes visuals - the approach the Dvergar's hood already proved out.
|
||||
/// </summary>
|
||||
private static void SetHelmetVisible(VisEquipment visEq, bool visible)
|
||||
{
|
||||
GameObject helmet = Traverse.Create(visEq).Field<GameObject>("m_helmetItemInstance").Value;
|
||||
if (helmet == null) return;
|
||||
|
||||
Vector3 wanted = visible ? Vector3.one : Vector3.zero;
|
||||
|
||||
// Only ever undo our own hiding: another race may legitimately be scaling this.
|
||||
if (!visible && helmet.transform.localScale != Vector3.zero)
|
||||
{
|
||||
helmet.transform.localScale = wanted;
|
||||
}
|
||||
else if (visible && helmet.transform.localScale == Vector3.zero)
|
||||
{
|
||||
helmet.transform.localScale = wanted;
|
||||
}
|
||||
}
|
||||
|
||||
private static void HideItemInstances(VisEquipment visEq, string fieldName)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue