Giter Club home page Giter Club logo

react-three-playground's Introduction

react-three-playgournd

React + Three Playground

R3, or React and Three.js, is a series of playgrounds and demos highlighting many of the features and capabilities of WebGL. It covers simple objects, textures and lighting, all the way to custom shaders, framebuffers and video. It benefits from hot reloading, Webpack, and ES6 support out of the box.

It is set up to accept a single video, either by passing a video URL via the video query string (for example, http://localhost:3000/?video=https://media.giphy.com/media/3o6Zti8Yz88sqW1nq0/giphy.mp4) or by using the webcam query string (with http://localhost:3000/?webcam=true). If neither are present, the app will fall back to using a video file, in video/video.mp4.

You can also see how React could be used in tandem with the Three.js canvas element, which can be activated with the overlay query string. http://localhost:3000/?overlay=true.

Getting started

To get started, clone the repo locally:

git clone [email protected]:superhighfives/react-three-playground.git
cd react-three-playground
npm install

Then, fire it up:

npm run start

Playgrounds

To view different playgrounds, edit the Playground import in App.js. For example, to view Playground 01:

// App.js
import Playground from './playgrounds/01'

Though each playground showcases a different feature, shaders can be interchanged simply by changing the Shader variable that is imported. There is no need to change the settings / uniforms passed to the shaders. Unless you want to. In which case, go for it, you!


Playground 01

An example of playground 01

Geometry

// App.js
import Playground from './playgrounds/01'
  • Navigable by mouse

A wireframe box, floating in space.


Playground 02

An example of playground 02

Light And Shadow

// App.js
import Playground from './playgrounds/02'
  • Navigable by mouse

A cube that accepts light and casts shadows.


Playground 03

An example of playground 03

Video And Texture

// App.js
import Playground from './playgrounds/03'

// 03.js
import { vertexShader, fragmentShader, uniforms } from '../shaders/gradient' // Update for different shaders
  • Navigable by mouse
  • Accepts one shader
  • Perspective camera

A shaded texture on a box geometry, floating in space, with a cube that accepts light.


Playground 04

An example of playground 04

Single Shader

// App.js
import Playground from './playgrounds/04'

// 04.js
import { vertexShader, fragmentShader, uniforms } from '../shaders/gradient' // Update for different shaders

A flat display, with a single shader on a video texture.

  • Accepts one shader
  • Orthonographic camera

Playground 05

An example of playground 05

Dual-Pass Shader

// App.js
import Playground from './playgrounds/05'

// 05.js
import * as BaseShader from '../shaders/dots' // First shader
import * as SecondaryShader from '../shaders/greyscale' // Second shader

A flat display, with a two shaders on a video texture.

  • Accepts two shaders via a framebuffer
  • Orthonographic Camera

Playground 06

An example of playground 06

Multi-Pass Shader

// App.js
import Playground from './playgrounds/06'

// 06.js
import * as DotsShader from '../shaders/dots'
import * as MirrorShader from '../shaders/mirror'
import ShaderManager from '../tools/ShaderManager'

this.shaderManager = new ShaderManager(this.texture) // Constuct with your base texture
this.shaderManager.add(DotsShader) // Add shaders
this.shaderManager.add(MirrorShader) // Add shaders

// Add to render()
this.shaderManager.render()

// Use the texture and celebrate your success
const uniforms = { texture: {type: 't', value: this.shaderManager.texture()} }

A flat display, with as many shaders as you like, on a video texture.

  • Accepts multiple shaders via a framebuffer using ShaderManager
  • Orthonographic Camera

Playground 07

An example of playground 07

Shadows And Shaders

// App.js
import Playground from './playgrounds/07'

// 04.js
import * as LightingShader from '../shaders/lighting'

A shaded texture that receives shadow on a box geometry, floating in space, with a cube that accepts light.

  • Orthonographic camera

Shaders

Playground 03 - 07 accept a shader. The following shaders are currently available:

  • shaders/base.js Base (single colour)
  • shaders/dots.js Dots
  • shaders/flip.js Flip (horizontally)
  • shaders/glitch.js Glitch
  • shaders/gradient.js Gradient
  • shaders/greyscale.js Greyscale
  • shaders/mirror.js Mirror (mirror's texture horizontally)
  • shaders/texture.js Texture (displays texture)
  • shaders/tv.js TV (Old rolling TV)

Why?

This repo was written for a workshop at Decompress 2016, in Melbourne, Australia.

A note on React

Though this app is built on Create React App, it keeps a distinct line between React and Three. This allows for the benefits of React and Webpack without an overcomplicated architecture. There are many projects that support a more tightly integrated relationship between React and Three.js, like React Three Renderer and React Three, and you should definetely check them out.

Create React App

This project was bootstrapped with Create React App.

You can find the most recent documentation for using create-react-app here.

react-three-playground's People

Contributors

superhighfives avatar

Watchers

Antonio Molinari avatar James Cloos 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.