From b90938108a5dc907fdd691cae440f11a05604a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Fri, 29 Dec 2023 12:41:21 -0600 Subject: [PATCH] feat: more game parity --- scripts/buildAssets.ts | 3 +++ src/core/blitzkrieg/readTexture.ts | 38 ++++++++++++++---------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/scripts/buildAssets.ts b/scripts/buildAssets.ts index cd7d52471..20655338a 100644 --- a/scripts/buildAssets.ts +++ b/scripts/buildAssets.ts @@ -514,8 +514,11 @@ if (allTargets || targets?.includes('tankModels')) { const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1; if (id !== 15697) continue; // chieftain TODO: investigate vertices stream over read + // if (id !== 24609) continue; // concept 1b // if (id !== 4417) continue; // amx m4 mle // if (id !== 7297) continue; // 60tp + // if (id !== 1) continue; // t-34 + console.log(`Building model ${id} @ ${nation}/${tankIndex}`); const parameters = await readYAMLDVPL( diff --git a/src/core/blitzkrieg/readTexture.ts b/src/core/blitzkrieg/readTexture.ts index a014abf13..4d025f082 100644 --- a/src/core/blitzkrieg/readTexture.ts +++ b/src/core/blitzkrieg/readTexture.ts @@ -1,3 +1,4 @@ +import { clamp } from 'lodash'; import sharp from 'sharp'; import { Vector3Tuple } from 'three'; import { readDVPLFile } from '../blitz/readDVPLFile'; @@ -35,20 +36,15 @@ export async function readTexture(path: string, options?: ReadTextureOptions) { switch (options?.mutation) { case TextureMutation.Normal: { for (let index = 0; index < channels; index += 4) { - let x = dds.data[index + 3] / 255; - let y = dds.data[index + 1] / 255; - let z = Math.sqrt(1 - x ** 2 - y ** 2); - const hypot = Math.sqrt(x ** 2 + y ** 2 + z ** 2); + // TODO: this math is pretty sus and looks very goofy when rendered + let x = dds.data[index + 3] * (2 / 255) - 1; + let y = dds.data[index + 1] * (2 / 255) - 1; + const underSqrt = 1 - x ** 2 - y ** 2; + let z = underSqrt > 0 ? Math.sqrt(underSqrt) : -Math.sqrt(-underSqrt); - if (isFinite(hypot)) { - x /= hypot; - y /= hypot; - z /= hypot; - } - - dds.data[index] = Math.round(x * 255); - dds.data[index + 1] = Math.round(y * 255); - dds.data[index + 2] = Math.round(z * 255); + dds.data[index] = Math.round((x + 1) * (255 / 2)); + dds.data[index + 1] = Math.round((y + 1) * (255 / 2)); + dds.data[index + 2] = Math.round((z + 1) * (255 / 2)); dds.data[index + 3] = 255; } @@ -71,18 +67,20 @@ export async function readTexture(path: string, options?: ReadTextureOptions) { case TextureMutation.BaseColor: { for (let index = 0; index < channels; index += 4) { + // treating as pre multiplied but I can't fully confirm + const r = dds.data[index] / 255; const g = dds.data[index + 1] / 255; const b = dds.data[index + 2] / 255; const a = dds.data[index + 3] / 255; - const inverseA = 1 - a; - const mixedR = a * r + inverseA * options.baseColor[0]; - const mixedG = a * g + inverseA * options.baseColor[1]; - const mixedB = a * b + inverseA * options.baseColor[2]; + const invA = 1 - a; + const rPrime = invA * options.baseColor[0] + r; + const gPrime = invA * options.baseColor[1] + g; + const bPrime = invA * options.baseColor[2] + b; - dds.data[index] = mixedR * 255; - dds.data[index + 1] = mixedG * 255; - dds.data[index + 2] = mixedB * 255; + dds.data[index] = Math.round(clamp(rPrime * 255, 0, 255)); + dds.data[index + 1] = Math.round(clamp(gPrime * 255, 0, 255)); + dds.data[index + 2] = Math.round(clamp(bPrime * 255, 0, 255)); dds.data[index + 3] = 255; }