fix: cos domain

This commit is contained in:
TrèsAbhi committed 2024-02-29 15:54:15 -06:00
1 parent c626e84f7d
commit 206ac373d2
4 files changed
+4 -7

No files matched your search

@@ -197,7 +197,6 @@ export function TankSandbox() {
<Suspense fallback={<ModelLoader />}>
{/* TODO: add rotation cube to the top right */}
{/* <SpacedArmorScene /> */}
<Lighting />
<TankModel />
<Armor />
@@ -40,7 +40,7 @@ void main() {
} else {
bool twoCalibersRule = caliber > thickness * 2.0 && thickness > 0.0;
float finalNormalization = twoCalibersRule ? ((1.4 * normalization * caliber) / (2.0 * thickness)) : normalization;
float finalThickness = thickness / cos(angle - finalNormalization);
float finalThickness = thickness / cos(max(0.0, angle - finalNormalization));
float remainingPenetration = penetration;
// world space is in meters
@@ -18,7 +18,7 @@ void main() {
bool twoCalibersRule = caliber > thickness * 2.0 && thickness > 0.0;
float finalNormalization = twoCalibersRule ? ((1.4 * normalization * caliber) / (2.0 * thickness)) : normalization;
float finalThickness = thickness / cos(angle - finalNormalization);
float finalThickness = thickness / cos(max(0.0, angle - finalNormalization));
gl_FragColor = vec4(finalThickness / penetration, 0.0, 0.0, 1.0);
}
@@ -73,7 +73,6 @@ export function SpacedArmorSceneComponent({
...props
}: SpacedArmorSceneComponentProps) {
const camera = useThree((state) => state.camera);
// const cameraNormal = new Vector3();
return (
<>
@@ -107,8 +106,6 @@ export function SpacedArmorSceneComponent({
point: event.point,
}; // TODO: type this
let remainingPenetration = penetration;
let penetrationChance = -1;
let splashChance = -1;
const shellNormal = camera.position
.clone()
@@ -242,7 +239,8 @@ export function SpacedArmorSceneComponent({
const finalThickness =
thickness === 0
? 0
: thickness / Math.cos(angle - finalNormalization);
: thickness /
Math.cos(Math.max(0, angle - finalNormalization));
if (!threeCalibersRule && angle >= ricochet) {
shot.layers.push({