fix: the Ljoskjarne's seam is painted into a glow map, the plates look forged

The cyan bars stood on the faces and lost part of their length to the face
on one side of the world, lit or unlit. The seam is now a line in the faces'
own glow map, with a shallow channel in a new normal map. The plates take
grain and blotches from the black metal and iron beam textures, and shine
less.
This commit is contained in:
kanym 2026-10-30 19:46:55 +01:00
commit 778451bed8
6 changed files with 72 additions and 89 deletions

View file

@ -1,4 +1,3 @@
using System.Collections.Generic;
using Jotunn.Managers; using Jotunn.Managers;
using UnityEngine; using UnityEngine;
@ -9,6 +8,10 @@ namespace RacesOfValheim
/// ground. Dark steel carved with Valheim's own runes (the Ashlands rune tile's glyphs, laid out by /// ground. Dark steel carved with Valheim's own runes (the Ashlands rune tile's glyphs, laid out by
/// scripts/paint_nexus.py), and a cyan seam down the middle of each face. /// scripts/paint_nexus.py), and a cyan seam down the middle of each face.
/// ///
/// The seam is painted into the faces' glow map, not built. Bars standing on the faces, lit or
/// unlit, lost part of their length to the face on whichever side looked one way in the world,
/// as the pyramid turned; a line in the face's own pixels has nothing to hide behind.
///
/// Only the look moves. The piece keeps one still collider from the ground up, so building on it, /// Only the look moves. The piece keeps one still collider from the ground up, so building on it,
/// support, hovering and the E key behave as before; the pyramid bobs and turns on each client by /// support, hovering and the E key behave as before; the pyramid bobs and turns on each client by
/// itself, nothing over the network. The seam breathes, and burns brighter while crystals wait. /// itself, nothing over the network. The seam breathes, and burns brighter while crystals wait.
@ -18,8 +21,6 @@ namespace RacesOfValheim
private const float Height = 2f; private const float Height = 2f;
private const float HalfBase = 1f; private const float HalfBase = 1f;
private const float Lift = 0.5f; private const float Lift = 0.5f;
private const float SeamWidth = 0.04f; // half the rib's width at the base
private const float SeamHeight = 0.025f;
private const string SourceMaterialPrefab = "piece_cartographytable"; private const string SourceMaterialPrefab = "piece_cartographytable";
private const string EmbersSource = "fx_Torch_Carried"; private const string EmbersSource = "fx_Torch_Carried";
@ -30,8 +31,10 @@ namespace RacesOfValheim
public static bool Build(GameObject prefab) public static bool Build(GameObject prefab)
{ {
Texture2D face = PieceLook.LoadTexture("AlfarNexus_face.png"); Texture2D face = PieceLook.LoadTexture("AlfarNexus_face.png");
Texture2D glow = PieceLook.LoadTexture("AlfarNexus_glow.png");
Texture2D bumps = PieceLook.LoadTexture("AlfarNexus_n.png", true);
Renderer tableRenderer = prefab.transform.Find("new/high")?.GetComponent<Renderer>(); Renderer tableRenderer = prefab.transform.Find("new/high")?.GetComponent<Renderer>();
if (face == null || tableRenderer == null || tableRenderer.sharedMaterial == null) if (face == null || glow == null || tableRenderer == null || tableRenderer.sharedMaterial == null)
{ {
Jotunn.Logger.LogWarning("[Alfar] Could not build the Ljoskjarne's pyramid; it keeps the cartography table's look."); Jotunn.Logger.LogWarning("[Alfar] Could not build the Ljoskjarne's pyramid; it keeps the cartography table's look.");
return false; return false;
@ -40,16 +43,20 @@ namespace RacesOfValheim
Material stone = new Material(tableRenderer.sharedMaterial) { name = "AlfarNexus_stone" }; Material stone = new Material(tableRenderer.sharedMaterial) { name = "AlfarNexus_stone" };
stone.color = Color.white; stone.color = Color.white;
stone.SetTexture("_MainTex", face); stone.SetTexture("_MainTex", face);
foreach (string slot in new[] { "_BumpMap", "_MetallicGlossMap" }) // Forged, not polished: the plate's own grain in the normal map, and a dull sheen.
if (stone.HasProperty(slot)) stone.SetTexture(slot, null); stone.SetTexture("_BumpMap", bumps);
if (stone.HasProperty("_Metallic")) stone.SetFloat("_Metallic", 0.75f); if (bumps != null) stone.EnableKeyword("_NORMALMAP");
if (stone.HasProperty("_Glossiness")) stone.SetFloat("_Glossiness", 0.55f); else stone.DisableKeyword("_NORMALMAP");
if (stone.HasProperty("_MetallicGlossMap")) stone.SetTexture("_MetallicGlossMap", null);
Material seam = new Material(stone) { name = "AlfarNexus_seam" }; if (stone.HasProperty("_Metallic")) stone.SetFloat("_Metallic", 0.6f);
seam.SetTexture("_MainTex", null); if (stone.HasProperty("_Glossiness")) stone.SetFloat("_Glossiness", 0.3f);
seam.color = Color.black; // Custom/Piece samples its noise in world space unless told the object moves, as boats and
seam.EnableKeyword("_EMISSION"); // carts do; on a turning pyramid the blotches would slide across the faces.
seam.SetColor("_EmissionColor", Seam); stone.EnableKeyword("_MOVEABLEOBJECT_ON");
if (stone.HasProperty("_MoveableObject")) stone.SetFloat("_MoveableObject", 1f);
stone.SetTexture("_EmissionMap", glow);
stone.EnableKeyword("_EMISSION");
stone.SetColor("_EmissionColor", Seam);
// The table goes whole: its meshes, its damage states, its fragments and its four colliders. // The table goes whole: its meshes, its damage states, its fragments and its four colliders.
for (int i = prefab.transform.childCount - 1; i >= 0; i--) for (int i = prefab.transform.childCount - 1; i >= 0; i--)
@ -74,12 +81,11 @@ namespace RacesOfValheim
floating.SetParent(prefab.transform, false); floating.SetParent(prefab.transform, false);
floating.gameObject.layer = prefab.layer; floating.gameObject.layer = prefab.layer;
MeshRenderer seamRenderer = Part(floating, "seam", SeamMesh(), seam).GetComponent<MeshRenderer>(); MeshRenderer pyramid = Part(floating, "pyramid", PyramidMesh(), stone).GetComponent<MeshRenderer>();
Part(floating, "pyramid", PyramidMesh(), stone);
NexusLook look = prefab.AddComponent<NexusLook>(); NexusLook look = prefab.AddComponent<NexusLook>();
look.Float = floating; look.Float = floating;
look.SeamRenderer = seamRenderer; look.SeamRenderer = pyramid;
look.Motes = AddMotes(prefab.transform); look.Motes = AddMotes(prefab.transform);
return true; return true;
} }
@ -122,7 +128,7 @@ namespace RacesOfValheim
triangles[i * 3 + 1] = i * 3 + 1; triangles[i * 3 + 1] = i * 3 + 1;
triangles[i * 3 + 2] = i * 3 + 2; triangles[i * 3 + 2] = i * 3 + 2;
} }
for (int i = 0; i < 4; i++) { vertices[12 + i] = c[i]; uvs[12 + i] = new Vector2(0.5f, 0.02f); } for (int i = 0; i < 4; i++) { vertices[12 + i] = c[i]; uvs[12 + i] = new Vector2(0.1f, 0.02f); }
int[] under = { 12, 13, 14, 12, 14, 15 }; int[] under = { 12, 13, 14, 12, 14, 15 };
System.Array.Copy(under, 0, triangles, 12, 6); System.Array.Copy(under, 0, triangles, 12, 6);
@ -132,56 +138,6 @@ namespace RacesOfValheim
return mesh; return mesh;
} }
/// <summary>
/// The seams: a raised rib down the middle of each face, from the middle of its base edge to
/// the tip, standing on the stone with its own sides. A flat strip a centimetre off the face
/// lost the depth test to the stone at a glancing angle, and the cyan came and went in patches
/// as the pyramid turned; a rib has no surface lying that close to the face.
/// </summary>
private static Mesh SeamMesh()
{
Vector3[] c = BaseCorners;
var vertices = new List<Vector3>();
var triangles = new List<int>();
Vector3 centre = new Vector3(0f, Lift + Height / 3f, 0f);
for (int i = 0; i < 4; i++)
{
Vector3 a = c[i], b = c[(i + 1) % 4];
Vector3 middle = (a + b) / 2f;
Vector3 along = (b - a).normalized;
Vector3 normal = Vector3.Cross(b - a, Apex - a).normalized;
if (Vector3.Dot(normal, middle - centre) < 0f) normal = -normal;
Vector3 top = normal * SeamHeight, foot = normal * 0.002f;
Vector3 baseLeft = middle - along * SeamWidth, baseRight = middle + along * SeamWidth;
Vector3 tipLeft = Apex - along * 0.004f, tipRight = Apex + along * 0.004f;
Quad(vertices, triangles, baseLeft + top, baseRight + top, tipRight + top, tipLeft + top, normal);
Quad(vertices, triangles, baseLeft + foot, baseLeft + top, tipLeft + top, tipLeft + foot, -along);
Quad(vertices, triangles, baseRight + foot, baseRight + top, tipRight + top, tipRight + foot, along);
Quad(vertices, triangles, baseLeft + foot, baseRight + foot, baseRight + top, baseLeft + top, middle - Apex);
}
Mesh mesh = new Mesh { name = "AlfarNexus_seam", vertices = vertices.ToArray(), triangles = triangles.ToArray() };
mesh.RecalculateNormals();
mesh.RecalculateBounds();
return mesh;
}
/// <summary>
/// One quad with its own corners, turned so its front faces <paramref name="outward"/>: Unity's
/// front face is the side Cross(v1 - v0, v2 - v0) points to.
/// </summary>
private static void Quad(List<Vector3> vertices, List<int> triangles, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 outward)
{
int first = vertices.Count;
vertices.Add(p0); vertices.Add(p1); vertices.Add(p2); vertices.Add(p3);
bool flip = Vector3.Dot(Vector3.Cross(p1 - p0, p2 - p0), outward) < 0f;
int[] quad = flip ? new[] { 0, 2, 1, 0, 3, 2 } : new[] { 0, 1, 2, 0, 2, 3 };
foreach (int k in quad) triangles.Add(first + k);
}
/// <summary>A few cyan motes drifting up from the ground under it: the torch's embers, recoloured, /// <summary>A few cyan motes drifting up from the ground under it: the torch's embers, recoloured,
/// spread over the pyramid's shadow and slowed down.</summary> /// spread over the pyramid's shadow and slowed down.</summary>
private static ParticleSystem AddMotes(Transform root) private static ParticleSystem AddMotes(Transform root)
@ -248,7 +204,8 @@ namespace RacesOfValheim
bool ready = m_nexus != null && m_nexus.Crystals > 0; bool ready = m_nexus != null && m_nexus.Crystals > 0;
m_ready = Mathf.MoveTowards(m_ready, ready ? 1f : 0f, Time.deltaTime * 0.5f); m_ready = Mathf.MoveTowards(m_ready, ready ? 1f : 0f, Time.deltaTime * 0.5f);
float breath = 0.75f + 0.25f * Mathf.Sin(t * 2f * Mathf.PI / BreathSeconds); float breath = 0.75f + 0.25f * Mathf.Sin(t * 2f * Mathf.PI / BreathSeconds);
m_seam.SetColor("_EmissionColor", Seam * breath * Mathf.Lerp(1f, 2.2f, m_ready)); Color glow = Seam * breath * Mathf.Lerp(1f, 2.2f, m_ready);
m_seam.SetColor("_EmissionColor", glow);
} }
private void OnDestroy() private void OnDestroy()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 286 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 KiB

View file

@ -1,9 +1,11 @@
"""Paint the Ljoskjarne's pyramid face (Alfar Nexus) and render a preview. """Paint the Ljoskjarne's pyramid face (Alfar Nexus) and render a preview.
Usage: py -3.14 -I paint_nexus.py <pylib> <scripts dir> <work dir> Usage: py -3.14 -I paint_nexus.py <pylib> <scripts dir> <work dir>
<work dir> must hold runes/RuneTile_d.png (the stone) and runes/RuneTile_e.png (Valheim's glyphs, <work dir> must hold runes/RuneTile_e.png (Valheim's glyphs, the Ashlands rune tile's glow mask),
the Ashlands rune tile's glow mask), both from bundle c4210710. Writes AlfarNexus_face.png (one metal/blackmetal_d.png and metal/Ironbeam_d.png, all from bundle c4210710. Writes
face, u 0..1 along the base, v 1 at the apex), AlfarNexus_icon.png and prev_nexus.png; copy the face and icon to AlfarNexus_face.png (one face, u 0..1 along the base, v 1 at the apex), AlfarNexus_glow.png (its glow
JotunnModStub/Assets/AlfarNexus/. The cyan seam down the middle is geometry, not paint.""" map: the cyan seam down the middle), AlfarNexus_n.png (its normal map), AlfarNexus_icon.png and
prev_nexus.png; copy the face, glow, normal map and icon to
JotunnModStub/Assets/AlfarNexus/."""
import sys, os, math import sys, os, math
sys.path.insert(0, sys.argv[1]); sys.path.insert(0, sys.argv[2]) sys.path.insert(0, sys.argv[1]); sys.path.insert(0, sys.argv[2])
import numpy as np import numpy as np
@ -32,11 +34,15 @@ wide = [b for b in blobs if b not in tall and (b[2]-b[0]) < 200]
glyph = lambda b: Image.fromarray((mask[b[1]:b[3], b[0]:b[2]]*255).astype(np.uint8)) glyph = lambda b: Image.fromarray((mask[b[1]:b[3], b[0]:b[2]]*255).astype(np.uint8))
print("glyphs: tall", len(tall), "short", len(wide)) print("glyphs: tall", len(tall), "short", len(wide))
# --- the plate: the rune tile's own stone, greyed toward steel # --- the plate: forged steel. Fine grain from the black metal bar's texture, tiled every 37 cm, and
stone = Image.open(os.path.join(d,"runes","RuneTile_d.png")).convert("RGB").resize((S,S), Image.BICUBIC) # broad blotches from the iron beam's metal, stretched over the whole face.
stone = np.asarray(stone, dtype=np.float32)/255 def norm(a): return (a - a.mean())/(a.std() + 1e-6)
grey = stone.mean(axis=2, keepdims=True) tile = Image.open(os.path.join(d,"metal","blackmetal_d.png")).convert("L").resize((96,96), Image.BICUBIC)
stone = (grey*0.8 + stone*0.2)*0.7 + np.array([0.02,0.03,0.05]) grain = norm(np.tile(np.asarray(tile, dtype=np.float32), (6,6))[:S,:S])
iron = Image.open(os.path.join(d,"metal","Ironbeam_d.png")).convert("L").crop((176,90,256,250))
mottle = norm(np.asarray(iron.resize((S,S), Image.BICUBIC).filter(ImageFilter.GaussianBlur(6)), dtype=np.float32))
tone = 0.27 + 0.035*grain + 0.05*mottle
stone = tone[...,None]*np.array([0.95,1.0,1.08])
# --- lay the glyphs out inside the face's triangle (in image space the apex is at the top middle) # --- lay the glyphs out inside the face's triangle (in image space the apex is at the top middle)
ink = Image.new("L", (S,S), 0) ink = Image.new("L", (S,S), 0)
@ -70,31 +76,51 @@ face = face*(1 - inkf[...,None]) + np.array([0.72,0.73,0.76])*inkf[...,None]
out = Image.fromarray((np.clip(face,0,1)*255).astype(np.uint8)) # top row is v = 1, the apex, as Unity reads a PNG out = Image.fromarray((np.clip(face,0,1)*255).astype(np.uint8)) # top row is v = 1, the apex, as Unity reads a PNG
out.save(os.path.join(d,"AlfarNexus_face.png")) out.save(os.path.join(d,"AlfarNexus_face.png"))
# --- the glow map: one line down the middle. u runs 0.5 per metre at every height, so a band of
# constant width in u is 9 cm wide on the pyramid from base to tip.
SEAM_HALF = 11 # pixels; GAP keeps the runes clear of it
xs = np.abs(np.arange(S) - (S-1)/2)
line = np.clip((SEAM_HALF + 1 - xs)/2, 0, 1) # two pixels of soft edge
glow = np.tile(line, (S,1))
Image.fromarray((glow*255).astype(np.uint8)).convert("RGB").save(os.path.join(d,"AlfarNexus_glow.png"))
# --- the normal map, from a height field: the grain and blotches raised a little, runes and the
# seam's channel cut in. DXT5nm, as Valheim packs it: X in alpha, Y in green and blue, red 255.
height = 0.35*grain + 0.9*mottle - 2.2*np.asarray(ink.filter(ImageFilter.GaussianBlur(1)), dtype=np.float32)/255 \
- 1.5*np.clip((SEAM_HALF + 4 - xs)/3, 0, 1)[None,:]
gx = np.zeros_like(height); gy = np.zeros_like(height)
gx[:,1:-1] = height[:,2:] - height[:,:-2]; gy[1:-1,:] = height[2:,:] - height[:-2,:]
K = 0.35
nm = np.stack([-gx*K, gy*K, np.ones_like(height)], -1) # image y runs down, texture v up
nm /= np.linalg.norm(nm, axis=-1, keepdims=True)
packed = np.zeros((S,S,4), np.float32)
packed[...,0] = 1; packed[...,1] = packed[...,2] = nm[...,1]*0.5 + 0.5; packed[...,3] = nm[...,0]*0.5 + 0.5
Image.fromarray((packed*255).astype(np.uint8), "RGBA").save(os.path.join(d,"AlfarNexus_n.png"))
# a lit check of the normal map, light from the upper left
shade = np.clip(nm @ np.array([-0.5,0.5,0.7])/np.linalg.norm([-0.5,0.5,0.7]), 0, 1)
Image.fromarray((np.clip(face*shade[...,None]*1.6,0,1)*255).astype(np.uint8)).save(os.path.join(d,"prev_nexus_bump.png"))
# --- preview: the pyramid as AlfarNexus builds it # --- preview: the pyramid as AlfarNexus builds it
HGT, B, LIFT = 2.0, 1.0, 0.5 # AlfarNexusLook: 2 m tall, 2 m base, floating 0.5 m up HGT, B, LIFT = 2.0, 1.0, 0.5 # AlfarNexusLook: 2 m tall, 2 m base, floating 0.5 m up
apex = np.array([0, LIFT+HGT, 0]); c = [np.array(p) for p in [(-B,LIFT,-B),(B,LIFT,-B),(B,LIFT,B),(-B,LIFT,B)]] apex = np.array([0, LIFT+HGT, 0]); c = [np.array(p) for p in [(-B,LIFT,-B),(B,LIFT,-B),(B,LIFT,B),(-B,LIFT,B)]]
L = []; vi = 1; seam = []; sv = 1 lit = np.asarray(out, dtype=np.float32)/255
lit = lit*(1-glow[...,None]) + np.array([0.35,0.75,1.0])*glow[...,None]
shown = Image.fromarray((lit*255).astype(np.uint8))
L = []; vi = 1
for i in range(4): for i in range(4):
a, b = c[i], c[(i+1)%4] a, b = c[i], c[(i+1)%4]
for p in (a, b, apex): L.append("v %f %f %f" % (-p[0], p[1], p[2])) for p in (a, b, apex): L.append("v %f %f %f" % (-p[0], p[1], p[2]))
L += ["vt 0 0", "vt 1 0", "vt 0.5 1", f"f {vi}/{vi} {vi+1}/{vi+1} {vi+2}/{vi+2}"]; vi += 3 L += ["vt 0 0", "vt 1 0", "vt 0.5 1", f"f {vi}/{vi} {vi+1}/{vi+1} {vi+2}/{vi+2}"]; vi += 3
m = (a+b)/2; along = (b-a)/np.linalg.norm(b-a); n = np.cross(b-a, apex-a); n /= np.linalg.norm(n)
if np.dot(n, m - np.array([0, LIFT+HGT/3, 0])) < 0: n = -n
for p in (m-along*0.04+n*0.025, m+along*0.04+n*0.025, apex+n*0.025+along*0.004, apex+n*0.025-along*0.004): # the rib's top
seam.append("v %f %f %f" % (-p[0], p[1], p[2]))
seam.append(f"f {sv}/1 {sv+1}/1 {sv+2}/1 {sv+3}/1"); sv += 4
for p in c: L.append("v %f %f %f" % (-p[0], p[1], p[2])) for p in c: L.append("v %f %f %f" % (-p[0], p[1], p[2]))
L += ["vt 0 0", f"f {vi}/{3*4+1} {vi+3}/{3*4+1} {vi+2}/{3*4+1} {vi+1}/{3*4+1}"] L += ["vt 0 0", f"f {vi}/{3*4+1} {vi+3}/{3*4+1} {vi+2}/{3*4+1} {vi+1}/{3*4+1}"]
open(os.path.join(d,"pyramid.obj"),"w").write("\n".join(L)+"\n") open(os.path.join(d,"pyramid.obj"),"w").write("\n".join(L)+"\n")
open(os.path.join(d,"seam.obj"),"w").write("vt 0 0\n" + "\n".join(seam)+"\n")
open(os.path.join(d,"ground.obj"),"w").write("v -2 0 -2\nv 2 0 -2\nv 2 0 2\nv -2 0 2\nvt 0 0\nf 1/1 2/1 3/1 4/1\n") open(os.path.join(d,"ground.obj"),"w").write("v -2 0 -2\nv 2 0 -2\nv 2 0 2\nv -2 0 2\nvt 0 0\nf 1/1 2/1 3/1 4/1\n")
sh = B*0.85 sh = B*0.85
open(os.path.join(d,"shadow.obj"),"w").write( open(os.path.join(d,"shadow.obj"),"w").write(
f"v {-sh} 0.005 {-sh}\nv {sh} 0.005 {-sh}\nv {sh} 0.005 {sh}\nv {-sh} 0.005 {sh}\nvt 0 0\nf 1/1 2/1 3/1 4/1\n") f"v {-sh} 0.005 {-sh}\nv {sh} 0.005 {-sh}\nv {sh} 0.005 {sh}\nv {-sh} 0.005 {sh}\nvt 0 0\nf 1/1 2/1 3/1 4/1\n")
parts = [{'obj':os.path.join(d,'pyramid.obj'),'tex':out}, parts = [{'obj':os.path.join(d,'pyramid.obj'),'tex':shown},
{'obj':os.path.join(d,'seam.obj'),'color':(0.35,0.75,1.0),'emissive':True},
{'obj':os.path.join(d,'ground.obj'),'color':(0.33,0.36,0.3)}, {'obj':os.path.join(d,'ground.obj'),'color':(0.33,0.36,0.3)},
{'obj':os.path.join(d,'shadow.obj'),'color':(0.18,0.2,0.17)}] {'obj':os.path.join(d,'shadow.obj'),'color':(0.18,0.2,0.17)}]
render(parts, os.path.join(d,'prev_nexus.png'), size=640, yaw=25, pitch=-12, light=(0.4,0.8,0.6), fit=(np.array([0,1.4,0]), 2.5)) render(parts, os.path.join(d,'prev_nexus.png'), size=640, yaw=25, pitch=-12, light=(0.4,0.8,0.6), fit=(np.array([0,1.4,0]), 2.5))
# the hammer icon: the pyramid and its seams alone, nearly side-on so two faces show # the hammer icon: the pyramid alone, nearly side-on so two faces show
render(parts[:2], os.path.join(d,'AlfarNexus_icon.png'), size=128, yaw=35, pitch=-12, bg=(0,0,0,0), light=(0.3,0.8,0.7)) render(parts[:1], os.path.join(d,'AlfarNexus_icon.png'), size=128, yaw=35, pitch=-12, bg=(0,0,0,0), light=(0.3,0.8,0.7))