Skip to content

insert: compact bakes, eight-bit optical maps - #582

Merged
freezy merged 2 commits into
masterfrom
feat/compact-insert-bakes
Oct 10, 2026
Merged

freezy merged 2 commits into
masterfrom
feat/compact-insert-bakes

Conversation

@freezy

@freezy freezy commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Insert bakes were the bulk of a table's diff: InsertBakeData kept its UVs and tangents as Vector2[]/Vector4[], which Unity writes as one YAML line per triangle corner. A ringed 1" insert's bake was 23k lines and 1 MB of text.

Compact UVs and tangents

  • Each distinct UV and tangent pair is saved once (8 bytes: UV in 16 bits per axis, tangent in 8 bits per component with the sign), plus a 16-bit index per corner (32-bit past 65,536 distinct pairs), all as byte[], which Unity writes as one hex line.
  • 8-bit tangents are as fine as the 8-bit normal map baked against them; 16-bit UVs are 1/64 of a texel at 1024 px. The UV grid is a power of two, so halves and quarters stay exact.
  • Uvs and Tangents stay as they were for the baker, TryApply and the packaging payload. On save they take the stored precision in place, so what the insert wears is what's saved, before and after a reload.
  • Old bakes are read through FormerlySerializedAs and take the compact form on their next save.

The LookDev bakes: 1.04 MB to 88 KB for the rings, 23k lines to 30 for each.

Eight-bit optical maps

  • Optical Normals are baked in 8 bits, like the normal map.
  • Optical Response is baked in 8 bits with the sRGB curve and imported as sRGB, so the GPU decodes it back to linear without shader changes. Plain linear 8 bits would err by up to 9% in the glow's dim tail; with the curve it stays within 2.2%.
  • Together the LookDev maps went from 23 MB to 5.5 MB. Before/after renders of three showcase inserts, lit and unlit, differ on under 0.1% of pixels by more than 2 levels, with the renders themselves reproducing exactly.

The HDRP exporter records the response's colour space from the texture (VisualPinball/VisualPinball.Unity.Hdrp#30), so older 16-bit linear maps keep exporting as linear.

Tests

  • New InsertBakeDataTests: a compact save and read round trip, and reading a bake in the old form.
  • All 1,982 insert edit-mode tests pass in the HDRP project, and both Blender suites (test_bake_insert.py, test_insert_optics.py) pass in Blender 5.2.

A bake kept its UVs and tangents as a YAML line per triangle corner, a megabyte of text for a ringed insert. Each distinct UV and tangent is now saved once, the UV in 16 bits per axis and the tangent in 8 per component, as fine as the normal map baked against it, with a 16-bit index per corner, all as hex: 30 lines and 88 KB for the same insert. What is saved is what the insert wears, also before a reload. Bakes in the old form are read and take the new one on their next save.

The optical normals are baked in eight bits like the normal map, and the optical response in eight bits with the sRGB curve, which its importer takes off again, so the glow's dim tail doesn't band. The maps shrink to about a quarter, and renders of the showcase inserts differ by a pixel here and there.
@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; both previous findings are addressed and no new actionable issue was found.

Summary

The PR stores insert UVs and tangents as compact bytes and switches optical maps to eight bits.

  • Insert bakes save compact corner data while keeping the same arrays available.
  • Insert optical maps use eight-bit data with the response decoded correctly.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[UVs and tangents] --> B[Quantized unique pairs]
  B --> C[Eight-byte records and corner indices]
  C --> D{Check sizes and indices}
  D -->|Valid| E[Restore UVs and tangents]
  D -->|Damaged| F[Keep generated mesh]
Loading

Reviews (2) · Last reviewed commit: "insert: read a damaged bake as none, tes..." · Reviewed by Greptile

Comment thread VisualPinball.Unity/VisualPinball.Unity/VPT/Insert/InsertBakeData.cs Outdated
A bake whose corner data was cut short or half merged threw while it loaded. Its index width has to be two or four bytes now, its records whole and every index within them, or it reads as no bake and the generated mesh stays as it is.

Tests reload a saved bake from disk at 65,536 distinct pairs, the last that fit 16-bit indices, and one more, both with repeated pairs, and read a damaged bake.
@freezy
freezy merged commit 3b1af29 into master Oct 10, 2026
15 checks passed
@freezy
freezy deleted the feat/compact-insert-bakes branch October 10, 2026 23:38
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.

1 participant