# Plane Crash

A crashed plane wreck with animated crows on a Leva-toggled day/night hill, layering a targeted spotlight rig and seven @react-three/postprocessing effects at once: autofocus depth of field, bloom, vignette, brightness/contrast, hue/saturation, noise, and chromatic aberration.

Demo: https://pmndrs.github.io/examples/examples/plane-crash
Source: https://github.com/pmndrs/examples/tree/main/examples/plane-crash
Scaffold: npx degit pmndrs/examples/examples/plane-crash
Authors: Łukasz Kwas
Tags: gltf, animation, spotlight, environment, postprocessing, bloom, dof, autofocus, vignette, brightness-contrast, hue-saturation, noise, chromatic-aberration
Ported from: https://github.com/kvvasuu/fiber-photo-mode
Dependencies: @react-three/drei@10.7.9, @react-three/fiber@9.8.2, @react-three/postprocessing@^3.2.0, leva@^0.10.1, maath@^0.10.8, react@19.2.9, react-dom@19.2.9, three@0.186.1
Binary files, in the repository but not below: src/crow-transformed.glb, src/plane.glb

## Asset attribution

- Crow — by LostBoyz2078 — CC-BY-4.0 — modified (https://sketchfab.com/3d-models/crow-2001eaf8e667446c969a69ca5b1b65ae)
- Plane Crash by a Brothel in Nevada — by Azad Balabanian — CC-BY-4.0 (https://sketchfab.com/3d-models/plane-crash-by-a-brothel-in-nevada-9931703442a14a3db2cd53c368706c64)

## src/App.tsx

```tsx
import { CameraControls, Loader, Preload } from "@react-three/drei";
import { Canvas } from "@react-three/fiber";
import { EffectComposer, EffectGroup } from "@react-three/postprocessing";
import { Leva, useControls } from "leva";
import { Suspense, useEffect, useState } from "react";
import { ColorAndEffects, FocusEffect } from "./Effects";
import { Lighting } from "./Lighting";
import { Scene } from "./Scene";

export default function App() {
  const [controls, setControls] = useState<CameraControls | null>(null);

  const { enabled } = useControls({
    enabled: { value: true, label: "Postprocessing" },
  });

  useEffect(() => {
    if (!controls) return;
    controls.enabled = false;
    controls.setLookAt(-7, 5, -8, -1, 1.3, 2, false);
  }, [controls]);

  const onSceneLoad = () => {
    requestAnimationFrame(() => {
      controls?.setLookAt(-2.5, 1.4, -1.2, -1.2, 2, 2, true).then(() => {
        if (controls) {
          controls.smoothTime = 0.2;
          controls.enabled = true;
        }
      });
    });
  };

  return (
    <>
      <Canvas
        gl={{ powerPreference: "high-performance" }}
        camera={{ position: [-7, 5, -8], fov: 80, far: 100 }}
      >
        <CameraControls
          ref={setControls}
          makeDefault
          smoothTime={0.7}
          maxDistance={20}
          restThreshold={0.02}
        />

        <Suspense fallback={null}>
          <Scene onLoaded={onSceneLoad} />
          <Lighting />
          <Preload all />

          <EffectComposer>
            <EffectGroup enabled={enabled}>
              <FocusEffect />
              <ColorAndEffects />
            </EffectGroup>
          </EffectComposer>
        </Suspense>
      </Canvas>
      <Loader />
      <Leva theme={{ sizes: { rootWidth: "20rem" } }} />
    </>
  );
}
```

## src/Crow.tsx

```tsx
/*
Auto-generated by: https://github.com/pmndrs/gltfjsx
Command: npx gltfjsx@6.5.3 crow.glb --transform --types
Author: LostBoyz2078 (https://sketchfab.com/LostModels2025)
License: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)
Source: https://sketchfab.com/3d-models/crow-2001eaf8e667446c969a69ca5b1b65ae
Title: Crow
*/

import { useAnimations, useGLTF } from "@react-three/drei";
import { useGraph } from "@react-three/fiber";
import React, { useEffect, useRef, type JSX } from "react";
import type {
  AnimationClip,
  Bone,
  Group,
  MeshStandardMaterial,
  SkinnedMesh,
} from "three";
import type { GLTF } from "three-stdlib";
import { SkeletonUtils } from "three-stdlib";

import crowModel from "./crow-transformed.glb?url";

type ActionName = "GltfAnimation 0";

interface GLTFAction extends AnimationClip {
  name: ActionName;
}

type GLTFResult = GLTF & {
  nodes: {
    Object_7: SkinnedMesh;
    Object_10: SkinnedMesh;
    GLTF_created_0_rootJoint: Bone;
  };
  materials: {
    M_CrowWings: MeshStandardMaterial;
    M_CrowBody: MeshStandardMaterial;
  };
  animations: GLTFAction[];
};

export function Crow(props: JSX.IntrinsicElements["group"]) {
  const group = useRef<Group>(null);
  const { scene, animations } = useGLTF(crowModel);
  const clone = React.useMemo(() => SkeletonUtils.clone(scene), [scene]);
  const { nodes, materials } = useGraph(clone) as unknown as GLTFResult;
  const { actions } = useAnimations(animations, group);

  useEffect(() => {
    actions["GltfAnimation 0"]?.play();
  }, [actions]);

  return (
    <group ref={group} {...props} dispose={null} scale={0.006}>
      <group name="Sketchfab_Scene">
        <primitive object={nodes.GLTF_created_0_rootJoint} />
        <skinnedMesh
          name="Object_7"
          geometry={nodes.Object_7.geometry}
          material={materials.M_CrowWings}
          skeleton={nodes.Object_7.skeleton}
        />
        <skinnedMesh
          name="Object_10"
          geometry={nodes.Object_10.geometry}
          material={materials.M_CrowBody}
          skeleton={nodes.Object_10.skeleton}
        />
      </group>
    </group>
  );
}

useGLTF.preload(crowModel);
```

## src/Effects.tsx

```tsx
import { useFrame, useThree } from "@react-three/fiber";
import {
  Autofocus,
  Bloom,
  BrightnessContrast,
  ChromaticAberration,
  HueSaturation,
  Noise,
  Vignette,
} from "@react-three/postprocessing";
import { useControls } from "leva";
import { useMemo, useState } from "react";
import { Vector3 } from "three";

export function ColorAndEffects() {
  const {
    chromaticAberration,
    bloom,
    vignette,
    hue,
    saturation,
    brightness,
    contrast,
    grain,
  } = useControls("Color & Effects", {
    chromaticAberration: {
      value: 0.05,
      min: 0,
      max: 1,
      step: 0.01,
      label: "Chromatic Aberration",
    },
    bloom: { value: 1, min: 0, max: 5, step: 0.05, label: "Bloom" },
    vignette: { value: 0.65, min: 0, max: 1, step: 0.01, label: "Vignette" },
    hue: {
      value: 0,
      min: -Math.PI,
      max: Math.PI,
      step: 0.01,
      label: "Hue Shift",
    },
    saturation: {
      value: 0.2,
      min: -1,
      max: 1,
      step: 0.01,
      label: "Saturation",
    },
    brightness: {
      value: 0,
      min: -0.75,
      max: 0.75,
      step: 0.01,
      label: "Brightness",
    },
    contrast: {
      value: 0,
      min: -0.75,
      max: 0.75,
      step: 0.01,
      label: "Contrast",
    },
    grain: { value: 0.4, min: 0, max: 1, step: 0.01, label: "Grain" },
  });

  return (
    <>
      <ChromaticAberration
        offset={[chromaticAberration * 0.01, chromaticAberration * 0.01]}
      />
      <Bloom intensity={bloom} mipmapBlur />
      <Vignette darkness={vignette} offset={0.4 * Math.pow(1 - vignette, 2)} />
      <HueSaturation hue={hue} saturation={saturation} />
      <BrightnessContrast brightness={brightness} contrast={contrast} />
      <Noise opacity={grain} premultiply />
    </>
  );
}

export function FocusEffect() {
  const { enabled, autoFocus, focusDistance, focusRange, bokehScale } =
    useControls("Focus", {
      enabled: { value: true, label: "Depth of Field" },
      autoFocus: { value: true, label: "Autofocus" },
      focusDistance: {
        value: 5,
        min: 0.1,
        max: 100,
        step: 0.1,
        label: "Focus Distance",
        render: (get) => !get("Focus.autoFocus"),
      },
      focusRange: {
        value: 20,
        min: 0.5,
        max: 200,
        step: 0.5,
        label: "Focus Range",
      },
      bokehScale: {
        value: 4.46,
        min: 0,
        max: 10,
        step: 0.1,
        label: "Bokeh Scale",
      },
    });

  const camera = useThree((state) => state.camera);
  const [manualTarget] = useState(() => new Vector3());
  const direction = useMemo(() => new Vector3(), []);

  useFrame(() => {
    if (autoFocus) return;
    camera.getWorldDirection(direction);
    manualTarget
      .copy(camera.position)
      .addScaledVector(direction, focusDistance);
  });

  return (
    <Autofocus
      bokehScale={enabled ? bokehScale : 0}
      focusRange={focusRange}
      target={autoFocus ? undefined : manualTarget}
    />
  );
}
```

## src/Lighting.tsx

```tsx
import { Environment } from "@react-three/drei";
import { useFrame, useThree } from "@react-three/fiber";
import { useControls } from "leva";
import { easing } from "maath";
import { useRef } from "react";
import { PulsingPointLight } from "./PulsingPointLight";
import { TargetedSpotLight } from "./TargetedSpotLight";

export function Lighting() {
  const { isDay } = useControls("Lighting", {
    isDay: { value: true, label: "Is day?" },
  });

  const scene = useThree((state) => state.scene);
  const values = useRef({ env: 1.5, background: 1 });

  useFrame((_, delta) => {
    const target = isDay
      ? { env: 1.5, background: 1 }
      : { env: 0.02, background: 0.001 };

    easing.damp(values.current, "env", target.env, 0.4, delta);
    easing.damp(values.current, "background", target.background, 0.4, delta);

    scene.environmentIntensity = values.current.env;
    scene.backgroundIntensity = values.current.background;
  });

  return (
    <>
      <TargetedSpotLight
        intensity={isDay ? 0 : 6}
        color={0xfffce6}
        position={[3, 3.8, 13]}
        target={[2.4, 4.5, 14]}
      />
      <TargetedSpotLight
        intensity={isDay ? 0 : 6}
        color={0xfffce6}
        position={[5.2, 3.8, 14.6]}
        target={[4.6, 4.5, 15.6]}
      />
      <PulsingPointLight
        enabled={!isDay}
        position={[-1.7, 1, -7]}
        color="red"
        speed={3}
      />

      <Environment
        preset="sunset"
        background
        blur={0.5}
        frames={1}
        environmentIntensity={1.5}
        backgroundIntensity={1}
        backgroundRotation={[0, -Math.PI / 1.3, 0]}
      />
    </>
  );
}
```

## src/Plane.tsx

```tsx
/*
Auto-generated by: https://github.com/pmndrs/gltfjsx
Command: npx gltfjsx@6.5.3 plane.glb --transform --types --resolution 4096
Author: Azad Balabanian (https://sketchfab.com/azadbal)
License: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)
Source: https://sketchfab.com/3d-models/plane-crash-by-a-brothel-in-nevada-9931703442a14a3db2cd53c368706c64
Title: Plane Crash by a Brothel in Nevada
*/

import { useGLTF } from "@react-three/drei";
import { useLayoutEffect } from "react";
import * as THREE from "three";
import type { GLTF } from "three-stdlib";

import planeModel from "./plane.glb?url";

type GLTFResult = GLTF & {
  nodes: {
    Object_2: THREE.Mesh;
    Object_3: THREE.Mesh;
    Object_4: THREE.Mesh;
    Object_5: THREE.Mesh;
    Object_6: THREE.Mesh;
    Object_7: THREE.Mesh;
    Object_8: THREE.Mesh;
    Object_9: THREE.Mesh;
  };
  materials: {
    Crash_plane_brothel_Material_u1_v1: THREE.MeshBasicMaterial;
    Crash_plane_brothel_Material_u1_v2: THREE.MeshBasicMaterial;
    Crash_plane_brothel_Material_u1_v3: THREE.MeshBasicMaterial;
    Crash_plane_brothel_Material_u2_v1: THREE.MeshBasicMaterial;
    Crash_plane_brothel_Material_u2_v2: THREE.MeshBasicMaterial;
    Crash_plane_brothel_Material_u2_v3: THREE.MeshBasicMaterial;
    Crash_plane_brothel_Material_u3_v1: THREE.MeshBasicMaterial;
    Crash_plane_brothel_Material_u3_v2: THREE.MeshBasicMaterial;
  };
};

export function Plane() {
  const { nodes, materials } = useGLTF(planeModel) as unknown as GLTFResult;

  useLayoutEffect(() => {
    Object.values(materials).forEach((mat) => {
      const newMat = new THREE.MeshStandardMaterial({
        map: mat.map,
      });
      mat.dispose();
      Object.assign(mat, newMat);
    });
  }, [materials]);

  return (
    <group dispose={null} position={[0, -0.5, 0]}>
      <mesh
        receiveShadow
        castShadow
        geometry={nodes.Object_2.geometry}
        material={materials.Crash_plane_brothel_Material_u1_v1}
        rotation={[-Math.PI, 0, 0]}
      />
      <mesh
        receiveShadow
        castShadow
        geometry={nodes.Object_3.geometry}
        material={materials.Crash_plane_brothel_Material_u1_v2}
        rotation={[-Math.PI, 0, 0]}
      />
      <mesh
        receiveShadow
        castShadow
        geometry={nodes.Object_4.geometry}
        material={materials.Crash_plane_brothel_Material_u1_v3}
        rotation={[-Math.PI, 0, 0]}
      />
      <mesh
        receiveShadow
        castShadow
        geometry={nodes.Object_5.geometry}
        material={materials.Crash_plane_brothel_Material_u2_v1}
        rotation={[-Math.PI, 0, 0]}
      />
      <mesh
        receiveShadow
        castShadow
        geometry={nodes.Object_6.geometry}
        material={materials.Crash_plane_brothel_Material_u2_v2}
        rotation={[-Math.PI, 0, 0]}
      />
      <mesh
        receiveShadow
        castShadow
        geometry={nodes.Object_7.geometry}
        material={materials.Crash_plane_brothel_Material_u2_v3}
        rotation={[-Math.PI, 0, 0]}
      />
      <mesh
        receiveShadow
        castShadow
        geometry={nodes.Object_8.geometry}
        material={materials.Crash_plane_brothel_Material_u3_v1}
        rotation={[-Math.PI, 0, 0]}
      />
      <mesh
        receiveShadow
        castShadow
        geometry={nodes.Object_9.geometry}
        material={materials.Crash_plane_brothel_Material_u3_v2}
        rotation={[-Math.PI, 0, 0]}
      />
    </group>
  );
}

useGLTF.preload(planeModel);
```

## src/PulsingPointLight.tsx

```tsx
import { useFrame } from "@react-three/fiber";
import { useRef } from "react";
import { PointLight } from "three";

type Props = {
  position?: [number, number, number];
  color?: string;
  baseIntensity?: number;
  pulseIntensity?: number;
  speed?: number;
  enabled?: boolean;
};

export function PulsingPointLight({
  position = [0, 0, 0],
  color = "white",
  baseIntensity = 1,
  pulseIntensity = 0.5,
  speed = 1,
  enabled = true,
}: Props) {
  const lightRef = useRef<PointLight>(null);

  useFrame(({ clock }) => {
    if (!lightRef.current) return;

    lightRef.current.intensity = enabled
      ? baseIntensity +
        Math.sin(clock.getElapsedTime() * speed) * pulseIntensity
      : 0;
  });

  return (
    <pointLight
      ref={lightRef}
      decay={2}
      position={position}
      color={color}
      intensity={baseIntensity}
    />
  );
}
```

## src/Scene.tsx

```tsx
import { Sparkles, useProgress } from "@react-three/drei";
import { degToRad } from "maath/misc";
import { useEffect, useRef } from "react";
import { Crow } from "./Crow";
import { Plane } from "./Plane";

export function Scene({ onLoaded }: { onLoaded: () => void }) {
  const { active } = useProgress();
  const initialized = useRef(false);

  useEffect(() => {
    if (!active && !initialized.current) {
      onLoaded?.();
      initialized.current = true;
    }
  }, [active, onLoaded]);

  return (
    <group>
      <Crow position={[1.5, 6.23, 14]} rotation={[0, degToRad(-20), 0]} />
      <Crow position={[-0.648, 1.69, 2]} rotation={[0, degToRad(110), 0]} />
      <Sparkles
        count={50}
        scale={[10, 4, 10]}
        size={1}
        speed={1}
        position={[0, 2, 0]}
      />
      <Plane />
    </group>
  );
}
```

## src/TargetedSpotLight.tsx

```tsx
import { useEffect, useRef } from "react";
import { Object3D, SpotLight } from "three";

type Props = {
  position?: [number, number, number];
  target?: [number, number, number];
  intensity?: number;
  color?: string | number;
  angle?: number;
  penumbra?: number;
};

export function TargetedSpotLight({
  position = [0, 5, 0],
  target = [0, 0, 0],
  intensity = 1,
  color = "white",
  angle = Math.PI / 3.8,
  penumbra = 0.5,
}: Props) {
  const lightRef = useRef<SpotLight>(null);
  const targetRef = useRef<Object3D>(null);

  useEffect(() => {
    if (!lightRef.current || !targetRef.current) return;
    lightRef.current.target = targetRef.current;
    lightRef.current.target.updateMatrixWorld();
  }, [target]);

  return (
    <>
      <spotLight
        ref={lightRef}
        position={position}
        intensity={intensity}
        color={color}
        angle={angle}
        penumbra={penumbra}
        castShadow
      />
      <object3D ref={targetRef} position={target} />
    </>
  );
}
```

## src/index.tsx

```tsx
import { createRoot } from "react-dom/client";
import "./styles.css";
import App from "./App";

createRoot(document.getElementById("root")!).render(<App />);
```

## src/styles.css

```css
* {
  box-sizing: border-box;
}

html,
body,
#root {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: #202020;
}
```

## src/vite-env.d.ts

```ts
/// <reference types="vite/client" />
```
