Webcam Texture

웹캠 텍스처

Display a live webcam feed with customizable object-fit modes.

Also known as: WebcamTexturewebcamcamera texturelive camera

Moves in browsers that support WebGPU

This device could not render the demo — showing a still

React
// Renders only in browsers with WebGPU.
import { Shader, WebcamTexture } from 'shaders/react'

export default function ShaderEffect() {
  return (
    <Shader style={{ width: '100%', height: 320 }} disableTelemetry>
      <WebcamTexture />
    </Shader>
  )
}
Vue
<!-- Renders only in browsers with WebGPU. -->
<script setup lang="ts">
import { Shader, WebcamTexture } from 'shaders/vue'
</script>

<template>
  <Shader style="width: 100%; height: 320px" :disable-telemetry="true">
    <WebcamTexture/>
  </Shader>
</template>
Svelte
<!-- Renders only in browsers with WebGPU. -->
<script>
  import { Shader, WebcamTexture } from 'shaders/svelte'
</script>

<Shader style="width: 100%; height: 320px" disableTelemetry>
  <WebcamTexture />
</Shader>
Solid
// Renders only in browsers with WebGPU.
import { Shader, WebcamTexture } from 'shaders/solid'

export default function ShaderEffect() {
  return (
    <Shader style={{ width: '100%', height: '320px' }} disableTelemetry>
      <WebcamTexture />
    </Shader>
  )
}
JavaScript
// Renders only in browsers with WebGPU.
// expects <canvas id="canvas" style="width:100%;height:320px"></canvas> on the page
import { createShader } from 'shaders/js'

const shader = await createShader(document.getElementById("canvas"), {
  components: [
    {
      type: 'WebcamTexture',
    }
  ]
}, { disableTelemetry: true })

Props · WebcamTexture

Changes apply to the demo above and to the code tabs. Descriptions come from the library registry (MIT).

NameValueDefaultRange / optionsDescription
objectFitObject Fitcovercover · contain · fill · scale-down · noneHow the webcam feed should be sized within the viewport
mirrorMirrortrue—Mirror the webcam feed horizontally (selfie mode)

Every component also takes blendMode · opacity · visible · maskSource/maskType · boundingBox · id

Imagine a small camera preview inside the canvas: the current webcam feed becomes a live layer.

Choose the framing with `objectFit`. The default `cover` fills the frame and crops its edges; `contain` shows the whole feed, while `fill` stretches it to fit. `mirror` defaults to `true` and flips the image horizontally for a selfie-style preview. These are the two configurable props listed in the registry.

The webcam draws its own live image, so later effects apply to the feed. The browser needs camera permission, and the feed may be unavailable if there is no camera or another app is using it. Ask before turning it on and provide a fallback state.

When to use

Use it for selfie previews, interactive camera effects, or a visual demo on a device with a camera. Avoid it where camera access is unavailable or the user has not explicitly agreed to it.

Open as page ↗