diff --git a/Examples/VideoBlur/Blur.js b/Examples/VideoBlur/Blur.js new file mode 100644 index 0000000..818593d --- /dev/null +++ b/Examples/VideoBlur/Blur.js @@ -0,0 +1,54 @@ +const React = require("react"); +const GL = require("gl-react"); +const { + PropTypes +} = React; +const Blur1D = require("./Blur1D"); + +const NORM = Math.sqrt(2)/2; + +function directionForPass (p, factor, total) { + const f = factor * p / total; + switch (p%4) { + case 0: return [f,0]; + case 1: return [0,f]; + case 2: return [f*NORM,f*NORM]; + case 3: return [f*NORM,-f*NORM]; + } + return p%2 ? [f,0] : [0,f]; +} + +/** Usages: + - Small blur: + {url} + - Medium blur: + {url} + - Powerful blur: + {url} + */ +class Blur extends GL.Component { + render () { + const { width, height, factor, children, passes } = this.props; + + const rec = p => p <= 0 ? children : + + {rec(p-1)} + ; + + return rec(passes); + } +} + +Blur.defaultProps = { + passes: 2 +}; + +Blur.propTypes = { + width: PropTypes.number, + height: PropTypes.number, + factor: PropTypes.number.isRequired, + children: PropTypes.any.isRequired, + passes: PropTypes.number +}; + +module.exports = Blur; diff --git a/Examples/VideoBlur/Blur1D.js b/Examples/VideoBlur/Blur1D.js new file mode 100644 index 0000000..28d6bc8 --- /dev/null +++ b/Examples/VideoBlur/Blur1D.js @@ -0,0 +1,38 @@ +const React = require("react"); +const GL = require("gl-react"); +const glslify = require("glslify"); + +const { + PropTypes +} = React; + +const shaders = GL.Shaders.create({ + blur1D: { + frag: glslify(`${__dirname}/blur1D.frag`) + } +}); + +class Blur1D extends GL.Component { + render () { + const { width, height, direction, children: t } = this.props; + return ; + } +} + +Blur1D.propTypes = { + width: PropTypes.number, + height: PropTypes.number, + direction: PropTypes.array.isRequired, + children: PropTypes.any.isRequired +}; + +module.exports = Blur1D; diff --git a/Examples/VideoBlur/Field.js b/Examples/VideoBlur/Field.js new file mode 100644 index 0000000..156cce2 --- /dev/null +++ b/Examples/VideoBlur/Field.js @@ -0,0 +1,39 @@ +const React = require("react"); + +const styles = { + field: { + display: "flex", + flexDirection: "row", + alignItems: "center", + padding: "10px 0" + }, + title: { + width: "200px", + textAlign: "right", + padding: "20px 40px", + fontSize: "2em", + fontFamily: "Helvetica" + }, + range: { + flex: 1, + height: "50px" + } +}; + +class Field extends React.Component { + render () { + const { min, max, step, value, onChange, name, width } = this.props; + return ; + } +} +module.exports = Field; diff --git a/Examples/VideoBlur/HueRotate.js b/Examples/VideoBlur/HueRotate.js new file mode 100644 index 0000000..266094e --- /dev/null +++ b/Examples/VideoBlur/HueRotate.js @@ -0,0 +1,23 @@ +const React = require("react"); +const GL = require("gl-react"); +const glslify = require("glslify"); + +const shaders = GL.Shaders.create({ + hueRotate: { + frag: glslify(`${__dirname}/hueRotate.frag`) + } +}); + +class HueRotate extends GL.Component { + render () { + const { width, height, hue, children: tex } = this.props; + return ; + } +} + +module.exports = HueRotate; diff --git a/Examples/VideoBlur/README.md b/Examples/VideoBlur/README.md new file mode 100644 index 0000000..879ff9b --- /dev/null +++ b/Examples/VideoBlur/README.md @@ -0,0 +1,2 @@ + +- [Web demo](http://projectseptemberinc.github.io/gl-react/Examples/Video/) diff --git a/Examples/VideoBlur/blur1D.frag b/Examples/VideoBlur/blur1D.frag new file mode 100644 index 0000000..676c449 --- /dev/null +++ b/Examples/VideoBlur/blur1D.frag @@ -0,0 +1,11 @@ +precision highp float; +varying vec2 uv; +uniform sampler2D t; +uniform vec2 resolution; +uniform vec2 direction; + +#pragma glslify: blur = require('glsl-fast-gaussian-blur/13') + +void main () { + gl_FragColor = blur(t, uv, resolution, direction); +} diff --git a/Examples/VideoBlur/hueRotate.frag b/Examples/VideoBlur/hueRotate.frag new file mode 100644 index 0000000..2564a16 --- /dev/null +++ b/Examples/VideoBlur/hueRotate.frag @@ -0,0 +1,16 @@ +precision highp float; +varying vec2 uv; +uniform sampler2D tex; +uniform float hue; + +const mat3 rgb2yiq = mat3(0.299, 0.587, 0.114, 0.595716, -0.274453, -0.321263, 0.211456, -0.522591, 0.311135); +const mat3 yiq2rgb = mat3(1.0, 0.9563, 0.6210, 1.0, -0.2721, -0.6474, 1.0, -1.1070, 1.7046); + +void main() { + vec3 yColor = rgb2yiq * texture2D(tex, uv).rgb; + float originalHue = atan(yColor.b, yColor.g); + float finalHue = originalHue + hue; + float chroma = sqrt(yColor.b*yColor.b+yColor.g*yColor.g); + vec3 yFinalColor = vec3(yColor.r, chroma * cos(finalHue), chroma * sin(finalHue)); + gl_FragColor = vec4(yiq2rgb*yFinalColor, 1.0); +} diff --git a/Examples/VideoBlur/index.html b/Examples/VideoBlur/index.html new file mode 100644 index 0000000..a63f23c --- /dev/null +++ b/Examples/VideoBlur/index.html @@ -0,0 +1,23 @@ + + + + + gl-react: Video + + + + Fork me on GitHub +
+ + + diff --git a/Examples/VideoBlur/index.js b/Examples/VideoBlur/index.js new file mode 100644 index 0000000..a75f6b0 --- /dev/null +++ b/Examples/VideoBlur/index.js @@ -0,0 +1,41 @@ +const React = require("react"); +const HueRotate = require("./HueRotate"); +const Blur = require("./Blur"); +const Field = require("./Field"); + +class Demo extends React.Component { + constructor (props) { + super(props); + this.state = { + time: 0, + blur: 0, + blurPasses: 2, + hue: 0 + }; + } + componentDidMount () { + const loop = time => { + requestAnimationFrame(loop); + this.setState({ time: time / 1000 }); + }; + requestAnimationFrame(loop); + } + render () { + const { width, height } = this.props; + const { time, blur, hue, blurPasses } = this.state; + return
+ + + + + + this.setState({ hue })} name="Hue" width={width} /> + this.setState({ blur })} name="Blur" width={width} /> + this.setState({ blurPasses })} name="Blur Passes" width={width} /> +
; + } +} + +React.render(, document.getElementById("container")); diff --git a/Examples/VideoBlur/package.json b/Examples/VideoBlur/package.json new file mode 100644 index 0000000..ee4e77b --- /dev/null +++ b/Examples/VideoBlur/package.json @@ -0,0 +1,30 @@ +{ + "private": true, + "name": "gl-react-example-video", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "browserify": { + "transform": [ + "babelify", + "glslify" + ] + }, + "scripts": { + "start": "budo index.js:bundle.js | garnish", + "build": "NODE_ENV=production browserify index.js | uglifyjs -cm > bundle.js" + }, + "devDependencies": { + "babelify": "^6.1.3", + "browserify": "^11.0.1", + "budo": "^4.1.0", + "garnish": "^2.2.2", + "uglify-js": "^2.4.24" + }, + "dependencies": { + "gl-react": "file:../..", + "glsl-fast-gaussian-blur": "^1.0.2", + "glslify": "^2.3.1", + "react": "^0.13.3" + } +} diff --git a/Examples/VideoBlur/video.mp4 b/Examples/VideoBlur/video.mp4 new file mode 100644 index 0000000..fdcb57d Binary files /dev/null and b/Examples/VideoBlur/video.mp4 differ