30 lines
1.5 KiB
JavaScript
30 lines
1.5 KiB
JavaScript
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
|
|
}
|