# Video Cookies

How to use drei/AccumulativeShadows and RandomizedLight

Demo: https://pmndrs.github.io/examples/examples/video-cookies
Source: https://github.com/pmndrs/examples/tree/main/examples/video-cookies
Scaffold: npx degit pmndrs/examples/examples/video-cookies
Published: 2022-08-31
Authors: Paul Henschel
Tags: video-texture, gobo, soft-shadows, postprocessing
Ported from: https://codesandbox.io/s/hmbn1l
Dependencies: @react-three/drei@10.7.9, @react-three/fiber@9.8.2, @react-three/postprocessing@^3.2.0, react@19.2.9, react-dom@19.2.9, three@0.186.1
Binary files, in the repository but not below: src/assets/suzanne-high-poly.gltf, src/caustics.mp4

## src/App.tsx

```tsx
import * as THREE from "three";
import { type GLTF } from "three-stdlib";
import { type ThreeElements } from "@react-three/fiber";
import { Canvas } from "@react-three/fiber";
import {
  AccumulativeShadows,
  RandomizedLight,
  OrbitControls,
  useGLTF,
  useVideoTexture,
} from "@react-three/drei";
import {
  EffectComposer,
  Bloom,
  HueSaturation,
  BrightnessContrast,
  TiltShift2,
  WaterEffect,
  ToneMapping,
} from "@react-three/postprocessing";
import { ToneMappingMode } from "postprocessing";

import causticsVid from "./caustics.mp4?url";

// From the poimandres market (https://market.pmnd.rs/), vendored locally since the original CDN is offline.
import suzanneModel from "./assets/suzanne-high-poly.gltf?url";

type GLTFResult = GLTF & {
  nodes: { Suzanne: THREE.Mesh };
};

export default function App() {
  return (
    <Canvas
      gl={{ antialias: false }}
      flat
      shadows
      camera={{ position: [0, 0, 8], fov: 35 }}
    >
      <color attach="background" args={["#353535"]} />
      <fog attach="fog" args={["#353535", 5, 20]} />
      <ambientLight intensity={2} />
      <Suzi rotation={[-0.63, 0, 0]} scale={2} position={[0, -1.175, 0]} />
      <Cookie
        distance={100}
        intensity={15}
        angle={0.6}
        penumbra={1}
        position={[2, 5, 0]}
      />
      <AccumulativeShadows
        receiveShadow
        temporal
        frames={100}
        opacity={0.8}
        alphaTest={0.9}
        scale={12}
        position={[0, -0.5, 0]}
      >
        <RandomizedLight
          radius={4}
          ambient={0.5}
          position={[5, 8, -10]}
          bias={0.001}
        />
      </AccumulativeShadows>
      <mesh castShadow position={[-1.5, -0.245, 1]}>
        <sphereGeometry args={[0.25, 64, 64]} />
        <meshStandardMaterial color="#353535" />
      </mesh>
      <mesh
        castShadow
        position={[1.5, -0.24, 1]}
        rotation={[0, Math.PI / 4, 0]}
      >
        <boxGeometry args={[0.5, 0.5, 0.5]} />
        <meshStandardMaterial color="#353535" />
      </mesh>
      <mesh
        rotation={[-Math.PI / 2, 0, 0]}
        position={[0, -0.51, 0]}
        scale={100}
      >
        <planeGeometry />
        <meshLambertMaterial color="#353535" />
      </mesh>
      <OrbitControls
        autoRotate
        autoRotateSpeed={0.1}
        enableZoom={false}
        minPolarAngle={0}
        maxPolarAngle={Math.PI / 2.5}
      />
      <Postpro />
    </Canvas>
  );
}

function Postpro() {
  return (
    <>
      {/* `disableNormalPass` no longer exists in this postprocessing version; the normal pass is already disabled by default */}
      <EffectComposer>
        <HueSaturation saturation={-1} />
        <BrightnessContrast brightness={0} contrast={0.25} />
        <WaterEffect factor={0.75} />
        <TiltShift2 samples={6} blur={0.5} />
        <Bloom mipmapBlur luminanceThreshold={0} intensity={30} />
        <ToneMapping mode={ToneMappingMode.ACES_FILMIC} />
      </EffectComposer>
    </>
  );
}

function Cookie(props: ThreeElements["spotLight"]) {
  const texture = useVideoTexture(causticsVid);
  return <spotLight decay={0} map={texture} castShadow {...props} />;
}

function Suzi(props: ThreeElements["mesh"]) {
  const { nodes } = useGLTF(suzanneModel) as unknown as GLTFResult;
  return (
    <mesh
      castShadow
      receiveShadow
      geometry={nodes.Suzanne.geometry}
      {...props}
      dispose={null}
    >
      <meshStandardMaterial color="#353535" />
    </mesh>
  );
}
```

## 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: #333;
}
```

## src/vite-env.d.ts

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