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