mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 19:19:52 +02:00
feat: all armor rules... I think?
This commit is contained in:
1 parent
8e6d2b9873
commit
232fc3140c
7 files changed
+117
-134
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { MeshProps } from '@react-three/fiber';
|
||||
import { MeshBasicMaterial } from 'three';
|
||||
import CustomShaderMaterial from 'three-custom-shader-material';
|
||||
import fragment from './shaders/fragment.glsl';
|
||||
import vertex from './shaders/vertex.glsl';
|
||||
|
||||
interface ArmorMeshProps extends MeshProps {
|
||||
thickness: number;
|
||||
penetration: number;
|
||||
ricochet: number;
|
||||
caliber: number;
|
||||
normalization: number;
|
||||
}
|
||||
|
||||
export function ArmorMesh({
|
||||
thickness,
|
||||
penetration,
|
||||
caliber,
|
||||
ricochet,
|
||||
normalization,
|
||||
...props
|
||||
}: ArmorMeshProps) {
|
||||
return (
|
||||
<>
|
||||
<mesh {...props}>
|
||||
<meshBasicMaterial colorWrite={false} />
|
||||
</mesh>
|
||||
|
||||
<mesh {...props} renderOrder={1}>
|
||||
<CustomShaderMaterial
|
||||
baseMaterial={MeshBasicMaterial}
|
||||
transparent
|
||||
silent
|
||||
depthWrite={false}
|
||||
uniforms={{
|
||||
thickness: { value: thickness },
|
||||
penetration: { value: penetration },
|
||||
ricochet: { value: ricochet * (Math.PI / 180) },
|
||||
caliber: { value: caliber },
|
||||
normalization: { value: normalization * (Math.PI / 180) },
|
||||
}}
|
||||
vertexShader={vertex}
|
||||
fragmentShader={fragment}
|
||||
/>
|
||||
</mesh>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
varying vec3 vViewPosition;
|
||||
uniform float thickness;
|
||||
uniform float penetration;
|
||||
uniform float ricochet;
|
||||
uniform float caliber;
|
||||
uniform float normalization;
|
||||
|
||||
void main() {
|
||||
vec3 normalizedNormal = normalize(vNormal);
|
||||
vec3 normalizedViewPosition = normalize(vViewPosition);
|
||||
float cosAngle = dot(normalizedNormal, -normalizedViewPosition);
|
||||
float angle = acos(cosAngle);
|
||||
|
||||
float penetrationChance = 0.0;
|
||||
bool twoCaliberRule = caliber > 2.0 * thickness;
|
||||
bool threeCaliberRule = caliber > 3.0 * thickness;
|
||||
float finalNormalization = twoCaliberRule ? (normalization * 1.4 * caliber) / (2.0 * thickness) : normalization;
|
||||
|
||||
float effectiveArmor = thickness / cos(angle - finalNormalization);
|
||||
|
||||
if(angle < ricochet) {
|
||||
// no auto-ricochet, resume checks
|
||||
if(effectiveArmor <= penetration || threeCaliberRule) {
|
||||
penetrationChance = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
csm_FragColor *= vec4(1.0, 0.0, 0.0, (1.0 - penetrationChance) * 0.5);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
varying vec3 vNormal;
|
||||
varying vec3 vViewPosition;
|
||||
|
||||
void main() {
|
||||
vec4 vViewPosition4 = modelViewMatrix * vec4(position, 1.0);
|
||||
vViewPosition = vViewPosition4.xyz;
|
||||
vNormal = normalMatrix * normal;
|
||||
}
|
||||
Reference in new issue
Block a user