Finished up most documentation

This commit is contained in:
2026-09-10 21:11:07 -07:00
parent 2cfa0ca690
commit 8355743ada
14 changed files with 1871 additions and 868 deletions

View File

@@ -0,0 +1,29 @@
import assert from 'node:assert/strict'
import { createHash } from 'node:crypto'
import { execFileSync } from 'node:child_process'
// SHA-256 of the whitespace-normalized fragment shader at this pre-fast-path commit.
export const referenceCommit = '2cfa0ca690134aa4988f01f0170e9e202b608c1c'
export const referenceHash = '5490249511bf2511ac78b6ef3b061fc8ef12ed42b255fe567954c16d5559f9b4'
export function baselineFragment(root) {
const source = execFileSync('git', [
'show', `${referenceCommit}:spikes/card-harness/src/cardMaterial.ts`,
], { cwd: root, encoding: 'utf8' })
const fragment = source.match(/const fragmentShader = `([\s\S]*?)`/)?.[1]
assert.ok(fragment, 'Cannot find original card fragment shader')
const hash = createHash('sha256').update(fragment.replace(/\s+/g, '')).digest('hex')
assert.equal(hash, referenceHash, 'Original shader reference must retain its recorded hash')
return fragment
}
export function originalFragment(source) {
const fragment = source.match(/const fragmentShader = `([\s\S]*?)`/)?.[1]
assert.ok(fragment, 'Cannot find card fragment shader')
const gate = /float edgeWear = 0\.0;\s*float scratchWear = 0\.0;\s*float scuffWear = 0\.0;\s*if \(condition < 1\.0\) \{([\s\S]*?)\}\s*(?=float wearDamage)/
assert.ok(gate.test(fragment), 'Expected the mint-only wear fast path')
const original = fragment.replace(gate, (_, body) => body.replace(
/^(\s*)(edgeWear|scratchWear|scuffWear) =/gm, '$1float $2 =',
))
return original
}