mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
feat: spaced armor
This commit is contained in:
1 parent
cae4836e17
commit
9218eb09d6
4 files changed
+34
-9
No files matched your search
@@ -12,25 +12,31 @@ interface ArmorMeshProps extends MeshProps {
|
||||
ricochet: number;
|
||||
caliber: number;
|
||||
normalization: number;
|
||||
spaced?: boolean;
|
||||
}
|
||||
|
||||
// shader split: https://github.com/FarazzShaikh/THREE-CustomShaderMaterial/issues/48
|
||||
|
||||
export function ArmorMesh({
|
||||
thickness,
|
||||
penetration,
|
||||
caliber,
|
||||
ricochet,
|
||||
normalization,
|
||||
spaced = false,
|
||||
...props
|
||||
}: ArmorMeshProps) {
|
||||
const opaqueArmor = useTankopedia((state) => state.model.opaqueArmor);
|
||||
|
||||
return (
|
||||
<>
|
||||
<mesh {...props}>
|
||||
<meshBasicMaterial colorWrite={false} />
|
||||
</mesh>
|
||||
{!spaced && (
|
||||
<mesh {...props}>
|
||||
<meshBasicMaterial colorWrite={false} />
|
||||
</mesh>
|
||||
)}
|
||||
|
||||
<mesh {...props} renderOrder={1}>
|
||||
<mesh {...props} renderOrder={spaced ? 3 : 1}>
|
||||
<CustomShaderMaterial
|
||||
baseMaterial={MeshStandardMaterial}
|
||||
transparent
|
||||
@@ -42,10 +48,10 @@ export function ArmorMesh({
|
||||
ricochet: { value: ricochet * (Math.PI / 180) },
|
||||
caliber: { value: caliber },
|
||||
normalization: { value: normalization * (Math.PI / 180) },
|
||||
spaced: { value: spaced },
|
||||
}}
|
||||
vertexShader={vertex}
|
||||
// split shaders due to https://github.com/FarazzShaikh/THREE-CustomShaderMaterial/issues/48
|
||||
fragmentShader={opaqueArmor ? fragmentOpaque : fragment}
|
||||
fragmentShader={opaqueArmor && !spaced ? fragmentOpaque : fragment}
|
||||
/>
|
||||
</mesh>
|
||||
</>
|
||||
|
||||
@@ -6,6 +6,7 @@ uniform float penetration;
|
||||
uniform float ricochet;
|
||||
uniform float caliber;
|
||||
uniform float normalization;
|
||||
uniform bool spaced;
|
||||
|
||||
void main() {
|
||||
vec3 normalizedNormal = normalize(vNormal);
|
||||
@@ -41,5 +42,11 @@ void main() {
|
||||
}
|
||||
}
|
||||
|
||||
csm_FragColor = vec4(1.0, 0.0, 0.0, (1.0 - penetrationChance) * 0.5);
|
||||
float alpha = (1.0 - penetrationChance) * 0.5;
|
||||
|
||||
if (spaced) {
|
||||
csm_FragColor = vec4(0.0, 0.0, 1.0, alpha);
|
||||
} else {
|
||||
csm_FragColor = vec4(1.0, 0.0, 0.0, alpha);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user