All files / components/shared/three/models FighterContactShadow.tsx

0% Statements 0/7
100% Branches 0/0
0% Functions 0/3
0% Lines 0/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                                                                 
import { useEffect, useMemo } from "react";
import * as THREE from "three";
 
/** Provides ground contact without an extra shadow map or lighting pass. */
export function FighterContactShadow(): React.JSX.Element {
  const shadow = useMemo(() => ({
    geometry: new THREE.PlaneGeometry(1.34, 1.15),
    material: new THREE.ShaderMaterial({
      transparent: true,
      depthWrite: false,
      vertexShader: `
        varying vec2 vUv;
        void main() {
          vUv = uv;
          gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
        }
      `,
      fragmentShader: `
        varying vec2 vUv;
        void main() {
          float opacity = 0.52 * (1.0 - smoothstep(0.13, 0.5, distance(vUv, vec2(0.5))));
          gl_FragColor = vec4(vec3(0.0), opacity);
        }
      `,
    }),
  }), []);
  useEffect(() => () => {
    shadow.geometry.dispose();
    shadow.material.dispose();
  }, [shadow]);
  return <mesh position-y={0.012} rotation-x={-Math.PI / 2} {...shadow} />;
}