Skip to content

Commit

Permalink
rework examples (cra -> vite), enable glitch by default, remove defau…
Browse files Browse the repository at this point in the history
…lt for buffer type
  • Loading branch information
v1rtl committed Apr 1, 2021
1 parent f24928d commit 6e9afbb
Show file tree
Hide file tree
Showing 38 changed files with 225 additions and 476 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
4 changes: 1 addition & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
},
"extends": [
"prettier",
"prettier/react",
"prettier/@typescript-eslint",
"plugin:prettier/recommended",
"plugin:react-hooks/recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"plugins": ["@typescript-eslint", "react", "prettier", "react-hooks", "import", "jest"],
"plugins": ["@typescript-eslint", "react", "prettier", "react-hooks", "import"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ npm install @react-three/postprocessing
```

<p align="center">
<a href="https://m94xb.csb.app" target="_blank"><img width="274" src="./examples/src/demos/Bubbles/resources/screenshot.jpg" alt="Bubbles" /></a>
<a href="https://5jgjz.csb.app" target="_blank"><img width="274" src="./examples/src/demos/TakeControl/resources/screenshot.jpg" alt="Take Control" /></a>
<a href="https://m94xb.csb.app" target="_blank"><img width="274" src="bubbles.jpg" alt="Bubbles" /></a>
<a href="https://5jgjz.csb.app" target="_blank"><img width="274" src="control.jpg" alt="Take Control" /></a>
</p>
<p align="middle">
<i>These demos are real, you can click them! They contain the full code, too. 📦</i>
Expand All @@ -33,7 +33,7 @@ Postprocessing also supports srgb-encoding out of the box, as well as WebGL2 MSA
Well, you can do pretty much anything, but here's an example combining a couple of effects ([live demo](https://codesandbox.io/s/vigorous-currying-3r6l2)).

<a href="https://codesandbox.io/s/vigorous-currying-3r6l2" target="_blank" rel="noopener">
<img src="https://i.imgur.com/mZucXdX.jpg" alt="Bubbles Demo" />
<img src="bubbles.jpg" alt="Bubbles Demo" />
</a>

```jsx
Expand Down
File renamed without changes
File renamed without changes
22 changes: 0 additions & 22 deletions examples/config-overrides.js

This file was deleted.

6 changes: 4 additions & 2 deletions examples/public/index.html → examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="stylesheet" href="style.css" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link href="https://fonts.googleapis.com/css?family=Playfair+Display:700" rel="stylesheet" />
<meta name="description" content="@react-three/fiber react-postprocessing postprocessing sketch" />
<title>React Postprocessing</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="./src/index.tsx"></script>
<noscript>You need to enable JavaScript to run this app.</noscript>
</body>
</html>
40 changes: 15 additions & 25 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,31 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject",
"serve": "serve -s ./build"
"dev": "vite",
"build": "vite build",
"start": "vite preview"
},
"dependencies": {
"@react-spring/core": "^9.0.0",
"@react-spring/three": "^9.0.0",
"@react-three/drei": "^4.0.1",
"@react-three/fiber": "^6.0.1",
"@react-three/postprocessing": "^2.0.0",
"classnames": "2.2.6",
"immer": "^8.0.1",
"immer": "^9.0.1",
"leva": "^0.8.4",
"postprocessing": "^6.16.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router": "5.2.0",
"react-router-dom": "^5.1.5",
"react-scripts": "3.4.1",
"react-use-gesture": "^7.0.15",
"styled-components": "^5.1.1",
"three": "^0.127.0"
"postprocessing": "^6.21.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-use-gesture": "^9.1.3",
"three": "^0.127.0",
"wouter": "^2.7.4"
},
"devDependencies": {
"@types/react-router": "^5.1.8",
"@types/react-router-dom": "^5.1.5",
"@types/styled-components": "^5.1.2",
"customize-cra": "^1.0.0",
"customize-cra-react-refresh": "^1.1.0",
"glslify-loader": "^2.0.0",
"raw-loader": "^4.0.1",
"react-app-rewired": "^2.1.6",
"serve": "^11.3.2"
"@rollup/plugin-commonjs": "^18.0.0",
"@types/react-router": "^5.1.13",
"@types/react-router-dom": "^5.1.7",
"@vitejs/plugin-react-refresh": "^1.3.2",
"vite": "^2.1.5"
},
"browserslist": {
"production": [
Expand Down
File renamed without changes
73 changes: 38 additions & 35 deletions examples/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
import React from 'react'
import cx from 'classnames'
import { HashRouter as Router, Switch, Route, Redirect } from 'react-router-dom'
import demos from './demos'
import { DemoWrapper, DemoPanel, Spot } from './styles'
import React, { Fragment } from 'react'
import { Route, Link, Redirect, useLocation } from 'wouter'
import EvilCube from './demos/EvilCube'
import TakeControl from './demos/TakeControl'
import Bubbles from './demos/Bubbles'

const demos = [EvilCube, TakeControl, Bubbles]

const App = () => {
const [loc] = useLocation()

const demo = demos.find((d) => d.path === loc)

const demosEntries = Object.entries(demos)
const [defaultDemoName] = demosEntries[0]
export default function App() {
return (
<Router>
<Switch>
<Route
path={`/demo/:name`}
exact
render={({ match }) => {
const ActiveDemo = demos[match.params.name]
return (
<DemoWrapper className={cx({ bright: ActiveDemo?.bright })}>
{!!ActiveDemo ? (
<React.Suspense fallback={null}>
<ActiveDemo.Component />
</React.Suspense>
) : (
<Redirect to={`/demo/${defaultDemoName}`} />
)}
</DemoWrapper>
)
}}
/>
<>
<Route path="/">
<Redirect to="/evil-cube" />
</Route>

<Redirect to={`/demo/${defaultDemoName}`} />
</Switch>
<DemoPanel>
{demosEntries.map(([name, { bright }]) => (
<Spot key={name} to={`/demo/${name}`} title={name} activeClassName="active" className={cx({ bright })} />
{demo && (
<>
<Route path={demo.path}>
<demo.component />
</Route>
<div id="desc">
<h1>{demo.name}</h1>
<p>{demo.description}</p>
</div>
</>
)}
<div id="controls">
{demos.map((demo) => (
<Link href={demo.path} key={demo.name}>
<a>
<div></div>
</a>
</Link>
))}
</DemoPanel>
</Router>
</div>
</>
)
}

export default App
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as THREE from 'three'
import React, { Suspense, useRef, useState } from 'react'
import React, { Suspense, useMemo, useRef, useState } from 'react'
import { Canvas, useFrame } from '@react-three/fiber'
import { EffectComposer, DepthOfField, Bloom, Noise, Vignette } from '@react-three/postprocessing'
import { EffectComposer, Bloom, Noise, Vignette, DepthOfField } from '@react-three/postprocessing'
import { Html, Icosahedron, Environment, MeshDistortMaterial, useTexture } from '@react-three/drei'
import { LoadingMsg } from '../../styles'
import img from './resources/bump.jpg'

function MainSphere({ material }) {
const main = useRef(null)
Expand Down Expand Up @@ -59,13 +57,14 @@ function Instances({ material }) {
}

function Scene() {
const bumpMap = useTexture(img)
const [material, set] = useState<any>()
const bumpMap = useTexture('/bump.jpg')

const [material, set] = useState()

return (
<>
<MeshDistortMaterial
ref={material}
bumpMap={bumpMap as THREE.Texture}
color={'#010101'}
roughness={0.1}
metalness={1}
Expand All @@ -74,33 +73,27 @@ function Scene() {
clearcoatRoughness={1}
radius={1}
distort={0.4}
bumpMap={bumpMap}
/>

{material && <Instances material={material} />}
</>
)
}

export default function Bubbles() {
function Bubbles() {
return (
<Canvas
linear={true}
camera={{ position: [0, 0, 10] }}
gl={{ powerPreference: 'high-performance', alpha: false, antialias: false, stencil: false, depth: false }}
>
<color attach="background" args={['#050505']} />
<color attach="background" args={['#c07c7c']} />
<fog color="#161616" attach="fog" near={8} far={30} />
<Suspense
fallback={
<Html center>
<LoadingMsg>Loading...</LoadingMsg>
</Html>
}
>
<Suspense fallback={<Html center>Loading...</Html>}>
<Scene />
<Environment preset={'studio'} />
</Suspense>
<EffectComposer>
<EffectComposer multisampling={0}>
<DepthOfField focusDistance={0} focalLength={0.02} bokehScale={2} height={480} />
<Bloom luminanceThreshold={0} luminanceSmoothing={0.9} height={300} opacity={0} />
<Noise opacity={0.025} />
Expand All @@ -109,3 +102,10 @@ export default function Bubbles() {
</Canvas>
)
}

export default {
component: Bubbles,
name: 'Bubbles',
description: 'DOF + Bloom + Vignette + Noise',
path: '/bubbles',
}
Binary file removed examples/src/demos/Bubbles/resources/cube/nx.png
Binary file not shown.
Binary file removed examples/src/demos/Bubbles/resources/cube/ny.png
Binary file not shown.
Binary file removed examples/src/demos/Bubbles/resources/cube/nz.png
Binary file not shown.
Binary file removed examples/src/demos/Bubbles/resources/cube/px.png
Binary file not shown.
Binary file removed examples/src/demos/Bubbles/resources/cube/py.png
Binary file not shown.
Binary file removed examples/src/demos/Bubbles/resources/cube/pz.png
Binary file not shown.
33 changes: 33 additions & 0 deletions examples/src/demos/EvilCube.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import { EffectComposer, Vignette, Noise, Glitch } from '@react-three/postprocessing'
import { Canvas } from '@react-three/fiber'
import { Box, OrbitControls } from '@react-three/drei'
import * as THREE from 'three'

const EvilCube = () => {
return (
<Canvas
onCreated={({ scene }) => {
scene.background = new THREE.Color('red')
}}
>
<OrbitControls />
<Box rotation={[0, 1, 2]}>
<meshBasicMaterial attach="material" color="red" />
</Box>
<ambientLight intensity={0.3} />
<EffectComposer multisampling={0}>
<Glitch delay={[1, 2]} />
<Vignette eskil={false} offset={0.1} darkness={1.1} />
<Noise />
</EffectComposer>
</Canvas>
)
}

export default {
component: EvilCube,
description: 'Glitch + Vignette + Noise',
name: 'Evil Cube',
path: '/evil-cube',
}
Loading

0 comments on commit 6e9afbb

Please sign in to comment.