Skip to content

Add normal maps - #2904

Merged
daid merged 7 commits into
daid:masterfrom
kzsh:add-normal-maps
Aug 19, 2026
Merged

Add normal maps#2904
daid merged 7 commits into
daid:masterfrom
kzsh:add-normal-maps

Conversation

@kzsh

@kzsh kzsh commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Add normal maps

Note

this builds on #2603, which laid most of the work out already.

Wires normal mapping through the mesh pipeline, ships normal maps for the
models in the resource packs, and fixes the tangent basis so mirrored UV
islands are lit correctly.

Changes

Tangent basis (src/mesh.h, src/mesh.cpp, resources/shaders/objectShader.shader)

The mesh loader derived a tangent from the UV parameterisation but discarded
the sign of the determinant, and the shader assumed every UV island was
right-handed. Models that mirror their UVs across the hull centreline (most of
the freighters and destroyers) rendered one half with an inverted bitangent,
producing a hard seam with the two sides lit from opposite directions.

MeshVertex::tangent becomes a vec4, with the handedness in w, and the
shader rebuilds the bitangent as cross(n, t.xyz) * t.w. The 1/determinant
scale is dropped, since the shader normalizes the basis, which also removes a
division by zero on triangles with degenerate UVs.

Replication (src/multiplayer/rendering.cpp)

normal_texture.name was never replicated, so clients never received the map.

Texture unit reset (src/systems/rendering.cpp)

The active texture unit is now also reset when a mesh has a normal map but no
specular or illumination map. Every model in model_data.lua that sets a
normal map also sets a specular map, so no shipped asset currently hits this,
but the loader no longer depends on that.

Model viewer (src/screenComponents/rotatingModelView.cpp)

Adds the normal map toggle to the debug view, so the map's contribution can be
judged against the flat-shaded model.

Assets (packs/, scripts/model_data.lua)

46 setNormalMap() entries. space_tug and space_cruiser_4 are not updated;
they need normal maps authored from scratch.

Note for the release: stale msgamedev.pack

msgamedev.pack is split into msgamedev-1.pack and msgamedev-2.pack, because
the added textures push the combined pack past GitHub's 100 MB file limit.

The rename means an in-place upgrade that unpacks over an existing install
may accidentally load the old msgamedev.pack, missing out on the new texture
data.

If that is a concern, the split can keep the name msgamedev.pack for one
half and add only msgamedev-2.pack, so the old file is always overwritten.
Happy to change it either way.

kzsh added 7 commits August 8, 2026 12:22
space_tug and space_cruiser_4 are not updated, because we'll need to
create normal maps from scratch for them.

Split msgamedev.pack into msgamedev-1.pack and msgamedev-2.pack
because the added textures push the combined pack past GitHub's 100MB
file limit.

License.txt names both files.
Mesh loader derived tangent from UV parameterisation but discarded
the determinant sign. The shader assumed every island was right-handed.
Models that mirror their UVs across the hull centreline (most of
the freighters/destroyers) rendered one half with an inverted
bitangent, producing a hard seam with two sides lit from
opposite directions.

We store handedness in tangent.w and apply it when rebuilding the
bitangent.

The 1/determinant scale is dropped since the shader normalizes the basis,
which also removes a possible division by zero
Every model in model_data.lua that sets a normal map also sets
specular, so no shipped asset currently leaves the active unit
at 3.
The source art is no longer in this repo, and this script cannot
rebuild the bundles that currently ship in packs/.
@daid
daid merged commit 6cb70d8 into daid:master Aug 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants