add-dvergar-color-and-skeleton-menu #14

Merged
kanym merged 30 commits from add-dvergar-color-and-skeleton-menu into main 2026-08-05 22:08:39 +02:00
Showing only changes of commit bb952ac4c2 - Show all commits

fix(dvergar): make the eyes solid, so the camera angle stops deciding whether they exist

Two symptoms, one cause each, and both were choices from the first version.

Vanishing from certain angles: the eyes were quads. A quad has no thickness, so
seen edge-on it is a line and there is nothing to draw. Now spheres, which read
the same from every direction.

Drawing in front of the face, and visible from behind: the shader resolver was
asked for Sprites/Default first and got it. That is a transparent shader with
depth writing off and backface culling off - so the eyes drew over whatever was
in front of them and stayed visible through the back of the head. The resolver
now asks for an unlit opaque shader first, which the skull occludes like any
other solid thing.

Between them, an eye is now a small solid glowing ball in a face rather than a
sticker that only exists at some angles.
kanym 2026-08-05 20:20:53 +02:00

View file

@ -210,23 +210,27 @@ namespace RacesOfValheim
{
float side = i == 0 ? -1f : 1f;
GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
quad.name = "Eye" + i;
// Spheres, not quads. A quad has no thickness: seen edge-on it is a line and the
// eyes vanish, which is why they came and went with the camera angle. A sphere
// reads the same from every direction and is properly hidden by the skull when
// the head is between it and the camera.
GameObject eye = GameObject.CreatePrimitive(PrimitiveType.Sphere);
eye.name = "Eye" + i;
// A primitive comes with a collider, which on a player's face would be its own
// kind of bug.
foreach (Collider collider in quad.GetComponents<Collider>())
foreach (Collider collider in eye.GetComponents<Collider>())
{
Object.Destroy(collider);
}
quad.transform.SetParent(holder.transform, false);
quad.transform.localPosition = new Vector3(
eye.transform.SetParent(holder.transform, false);
eye.transform.localPosition = new Vector3(
side * DvergarConfig.EyeSeparation, DvergarConfig.EyeHeight, DvergarConfig.EyeForward);
quad.transform.localRotation = Quaternion.identity;
quad.transform.localScale = Vector3.one * DvergarConfig.EyeSize;
eye.transform.localRotation = Quaternion.identity;
eye.transform.localScale = Vector3.one * DvergarConfig.EyeSize;
Renderer renderer = quad.GetComponent<Renderer>();
Renderer renderer = eye.GetComponent<Renderer>();
renderer.material = new Material(glow);
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
renderer.receiveShadows = false;
@ -239,13 +243,19 @@ namespace RacesOfValheim
/// Finds a shader that will render a flat colour past 1 so the bloom pass picks it up.
/// Unity strips shaders nothing references, so this asks for several and reports which one
/// the game actually shipped rather than assuming.
///
/// Opaque first, deliberately. The first version took Sprites/Default, which is a
/// transparent shader with depth writing switched off - so the eyes drew over the head
/// from angles that should have hidden them, and were visible from behind because it also
/// disables backface culling. An unlit opaque shader is occluded by the skull like any
/// other solid thing, which is the whole point of putting them in the face.
/// </summary>
private static Shader ResolveGlowShader()
{
if (glowShaderResolved) return cachedGlowShader;
glowShaderResolved = true;
string[] candidates = { "Sprites/Default", "Unlit/Color", "UI/Default", "Particles/Standard Unlit", "Standard" };
string[] candidates = { "Unlit/Color", "Standard", "Particles/Standard Unlit", "Sprites/Default", "UI/Default" };
foreach (string name in candidates)
{
Shader shader = Shader.Find(name);