feat: more advanced armor highlighting

This commit is contained in:
TrèsAbhi committed 2024-01-12 13:57:32 -06:00
1 parent 909474d4cb
commit d469f990f6
10 files changed
+119 -199

No files matched your search

+21 -32
View File
@@ -1,69 +1,58 @@
import { MeshProps } from '@react-three/fiber';
import { MeshStandardMaterial } from 'three';
import CustomShaderMaterial from 'three-custom-shader-material';
import fragment from './shaders/fragment.glsl';
import vertex from './shaders/vertex.glsl';
import fragmentShader from './shaders/fragment.glsl';
interface ArmorMeshProps extends MeshProps {
isExplosive: boolean;
canSplash: boolean;
isSpaced: boolean;
isArmor: boolean;
thickness: number;
penetration: number;
caliber: number;
spaced?: boolean;
canRicochet: boolean;
canSplash: boolean;
ricochet?: number;
normalization?: number;
isAffectedBySpaced: boolean;
ricochet: number;
normalization: number;
}
// shader split: https://github.com/FarazzShaikh/THREE-CustomShaderMaterial/issues/48
export function ArmorMesh({
isExplosive,
canSplash,
isSpaced,
isArmor,
thickness,
penetration,
caliber,
canRicochet,
ricochet,
canSplash,
isAffectedBySpaced,
normalization,
spaced = false,
...props
}: ArmorMeshProps) {
return (
<>
{!spaced && (
{!isSpaced && (
<mesh {...props}>
<meshBasicMaterial colorWrite={false} />
</mesh>
)}
<mesh {...props} renderOrder={spaced ? 3 : 1}>
<mesh {...props} renderOrder={1}>
<CustomShaderMaterial
silent
baseMaterial={MeshStandardMaterial}
transparent
silent
depthWrite={false}
fragmentShader={fragmentShader}
uniforms={{
isExplosive: { value: isExplosive },
canSplash: { value: canSplash },
isSpaced: { value: isSpaced },
isArmor: { value: isArmor },
thickness: { value: thickness },
penetration: { value: penetration },
ricochet: {
value: ricochet === undefined ? 0 : ricochet * (Math.PI / 180),
},
normalization: {
value:
normalization === undefined
? 0
: normalization * (Math.PI / 180),
},
caliber: { value: caliber },
spaced: { value: spaced ?? false },
canRicochet: { value: canRicochet },
canSplash: { value: canSplash },
isAffectedBySpaced: { value: isAffectedBySpaced },
ricochet: { value: ricochet * (Math.PI / 180) },
normalization: { value: normalization * (Math.PI / 180) },
}}
vertexShader={vertex}
fragmentShader={fragment}
/>
</mesh>
</>