diff --git a/scripts/buildAssets/tankArmors.ts b/scripts/buildAssets/tankArmors.ts index fcc25f8d7..e2ccc282f 100644 --- a/scripts/buildAssets/tankArmors.ts +++ b/scripts/buildAssets/tankArmors.ts @@ -20,7 +20,7 @@ export async function buildTankArmors() { await Promise.all( nations.map(async (nation) => { - if (nation !== 'france') return; + if (nation !== 'china') return; const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>( `${DATA}/${DOI.vehicleDefinitions}/${nation}/list.xml.dvpl`, diff --git a/scripts/buildAssets/tankModels.ts b/scripts/buildAssets/tankModels.ts index 659bb42d8..4a982c42f 100644 --- a/scripts/buildAssets/tankModels.ts +++ b/scripts/buildAssets/tankModels.ts @@ -27,7 +27,7 @@ export async function buildTankModels() { await Promise.all( nations.map(async (nation) => { - if (nation !== 'france') return; + if (nation !== 'china') return; const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>( `${DATA}/${DOI.vehicleDefinitions}/${nation}/list.xml.dvpl`, diff --git a/src/components/ArmorMesh/index.tsx b/src/components/ArmorMesh/index.tsx index 44c5778f2..421f1a4e1 100644 --- a/src/components/ArmorMesh/index.tsx +++ b/src/components/ArmorMesh/index.tsx @@ -41,7 +41,7 @@ export function ArmorMesh({ baseMaterial={MeshStandardMaterial} transparent silent - // depthWrite={false} + depthWrite={false} uniforms={{ thickness: { value: thickness }, penetration: { value: penetration }, diff --git a/src/components/ArmorMesh/shaders/fragment.glsl b/src/components/ArmorMesh/shaders/fragment.glsl index fefe55c1a..6716a2b31 100644 --- a/src/components/ArmorMesh/shaders/fragment.glsl +++ b/src/components/ArmorMesh/shaders/fragment.glsl @@ -11,34 +11,31 @@ uniform bool spaced; void main() { vec3 normalizedNormal = normalize(vNormal); vec3 normalizedViewPosition = normalize(vCSMViewPosition); - float cosAngle = dot(normalizedNormal, -normalizedViewPosition); - float angle = acos(cosAngle); + float dotProduct = dot(normalizedNormal, -normalizedViewPosition); + float angle = acos(dotProduct); - float penetrationChance = 0.0; - bool twoCaliberRule = caliber > 2.0 * thickness; + float penetrationChance = -1.0; bool threeCaliberRule = caliber > 3.0 * thickness; - float finalNormalization = twoCaliberRule ? (normalization * 1.4 * caliber) / (2.0 * thickness) : normalization; - float finalPenetration = penetration; - float effectiveArmor = thickness / cos(angle - finalNormalization); - if (angle < ricochet) { - // no auto-ricochet, resume checks - if (threeCaliberRule) { + if (!threeCaliberRule && angle >= ricochet) { + // auto ricochet angle and three caliber rule not met + penetrationChance = 0.0; + } else { + bool twoCaliberRule = caliber > 2.0 * thickness; + float finalNormalization = twoCaliberRule ? (normalization * 1.4 * caliber) / (2.0 * thickness) : normalization; + float effectiveArmor = thickness / cos(angle - finalNormalization); + float penetrationRandomRadius = penetration * 0.05; + float penetrationDifference = effectiveArmor - penetration; + + if (penetrationDifference > penetrationRandomRadius) { + // even with a +5% buff, can't penetrate + penetrationChance = 0.0; + } else if (penetrationDifference < -penetrationRandomRadius) { + // event with a -5% nerf, can penetrate penetrationChance = 1.0; } else { - float maxRandomPenetrationBuff = finalPenetration * 0.05; - float penetrationDifference = effectiveArmor - finalPenetration; - - if (penetrationDifference > maxRandomPenetrationBuff) { - // even with a +5% buff, can't penetrate - penetrationChance = 0.0; - } else if (penetrationDifference < -maxRandomPenetrationBuff) { - // event with a -5% nerf, can penetrate - penetrationChance = 1.0; - } else { // penetration gradiant - penetrationChance = 1.0 - (penetrationDifference + maxRandomPenetrationBuff) / (2.0 * maxRandomPenetrationBuff); - } + penetrationChance = 1.0 - (penetrationDifference + penetrationRandomRadius) / (2.0 * penetrationRandomRadius); } } diff --git a/src/components/ArmorMesh/shaders/fragmentOpaque.glsl b/src/components/ArmorMesh/shaders/fragmentOpaque.glsl index d1a9b1499..eb026b47c 100644 --- a/src/components/ArmorMesh/shaders/fragmentOpaque.glsl +++ b/src/components/ArmorMesh/shaders/fragmentOpaque.glsl @@ -10,34 +10,31 @@ uniform float normalization; void main() { vec3 normalizedNormal = normalize(vNormal); vec3 normalizedViewPosition = normalize(vCSMViewPosition); - float cosAngle = dot(normalizedNormal, -normalizedViewPosition); - float angle = acos(cosAngle); + float dotProduct = dot(normalizedNormal, -normalizedViewPosition); + float angle = acos(dotProduct); - float penetrationChance = 0.0; - bool twoCaliberRule = caliber > 2.0 * thickness; + float penetrationChance = -1.0; bool threeCaliberRule = caliber > 3.0 * thickness; - float finalNormalization = twoCaliberRule ? (normalization * 1.4 * caliber) / (2.0 * thickness) : normalization; - float finalPenetration = penetration; - float effectiveArmor = thickness / cos(angle - finalNormalization); - if (angle < ricochet) { - // no auto-ricochet, resume checks - if (threeCaliberRule) { + if (!threeCaliberRule && angle >= ricochet) { + // auto ricochet angle and three caliber rule not met + penetrationChance = 0.0; + } else { + bool twoCaliberRule = caliber > 2.0 * thickness; + float finalNormalization = twoCaliberRule ? (normalization * 1.4 * caliber) / (2.0 * thickness) : normalization; + float effectiveArmor = thickness / cos(angle - finalNormalization); + float penetrationRandomRadius = penetration * 0.05; + float penetrationDifference = effectiveArmor - penetration; + + if (penetrationDifference > penetrationRandomRadius) { + // even with a +5% buff, can't penetrate + penetrationChance = 0.0; + } else if (penetrationDifference < -penetrationRandomRadius) { + // event with a -5% nerf, can penetrate penetrationChance = 1.0; } else { - float maxRandomPenetrationBuff = finalPenetration * 0.05; - float penetrationDifference = effectiveArmor - finalPenetration; - - if (penetrationDifference > maxRandomPenetrationBuff) { - // even with a +5% buff, can't penetrate - penetrationChance = 0.0; - } else if (penetrationDifference < -maxRandomPenetrationBuff) { - // event with a -5% nerf, can penetrate - penetrationChance = 1.0; - } else { // penetration gradiant - penetrationChance = 1.0 - (penetrationDifference + maxRandomPenetrationBuff) / (2.0 * maxRandomPenetrationBuff); - } + penetrationChance = 1.0 - (penetrationDifference + penetrationRandomRadius) / (2.0 * penetrationRandomRadius); } } diff --git a/src/core/blitzkrieg/tankDefinitions.ts b/src/core/blitzkrieg/tankDefinitions.ts index 0f96c84c0..ebfedcf1b 100644 --- a/src/core/blitzkrieg/tankDefinitions.ts +++ b/src/core/blitzkrieg/tankDefinitions.ts @@ -58,18 +58,24 @@ interface GunDefinitionAutoReloader { interClip: number; count: number; } -export interface ShellDefinition { +export type ShellDefinition = { id: number; name: string; speed: number; damage: { armor: number; devices: number }; caliber: number; - normalization: number; - ricochet: number; - type: ShellType; icon: string; penetration: number | Vector2Tuple; -} +} & ( + | { + type: Omit; + normalization: number; + ricochet: number; + } + | { + type: Omit; + } +); export const tankDefinitions = fetch(asset('definitions/tanks.json'), { cache: 'no-cache',