Code Monkey home page Code Monkey logo

threejs_chromakey_video_material's Introduction

ChromaKeyMaterial

A THREE.JS ShaderMaterial that removes a specified color (e.g. green screen) from a video or image texture.

Shader code by https://github.com/Mugen87 on THREE.js forum. Inspired by https://github.com/hawksley/Threex.chromakey

Source

ChromaKeyMaterial.js is in /js directory.

Code in /ts directory is for the demo app.

Source code is vanilla JS. Typescipt types in /types directory are autogenerated with tsc.

Video file is from MixKit

Demo

View a live demo.

Usage/Example

import ChromaKeyMaterial from '../js/ChromaKeyMaterial';

// Assumes basic THREE.js camera/scene/renderer setup.
const heightAspectRatio = 9 / 16;
const geometry: THREE.BufferGeometry =
    new THREE.PlaneGeometry(1, heightAspectRatio);
// 0x19ae31 is the green color to key out. The last three arguments are
// similarity, smoothness, and spill, respectively and are used to fine
// tune the color key.
const greenScreenMaterial = new ChromaKeyMaterial(
    './assets/myVideo.mp4', 0x19ae31, 1920, 1080, 0.159, 0.082, 0.214);
const plane = new THREE.Mesh(geometry, greenScreenMaterial);
scene.add(plane);

Demo

To run the demo in this package:

  1. Clone this repo
  2. cd into repo root
  3. Install with npm install
  4. Run demo server with npm run dev
  5. Open http://localhost:1234 + browser Dev Tools.
  6. Use dat.gui controls to pause/play video and fine tune color key.

threejs_chromakey_video_material's People

Contributors

drinkspiller avatar ralphfurley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.