# Blur (2-Pass) ```html http://i.imgur.com/3On9QEu.jpg ``` ![](7.gif) ## Implementation The classical example where you need multiple pass is **Blur**. Implementing an efficient and realist Blur is tricky, one simple and fast way is to implement it with 2-Pass (on X and on Y). To do that, we first define a one dimensional Blur (`Blur1D`) and stack it into these 2 passes. ```js const Blur1D = GL.createComponent( ({ width, height, direction, children }) => {children} , { displayName: "Blur1D" }); ``` And then, we create a Blur that composes Blur1D two times: ```js const Blur = GL.createComponent(({ width, height, factor, children }) => {children} , { displayName: "Blur" }); ``` In this simple example, `Blur` has 2 passes: one on X dimension, then one on Y dimension. ### 4-pass (Used in [Examples/Blur](https://github.com/ProjectSeptemberInc/gl-react/tree/master/Examples/Blur)) ```js const Blur = GL.createComponent(({ width, height, factor, children }) => { const sharedProps = { width, height }; return ( {children} ); }); ``` ### N-pass (Used in [Examples/VideoBlur](https://github.com/ProjectSeptemberInc/gl-react/tree/master/Examples/VideoBlur)) ```js 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]; } module.exports = GL.createComponent( ({ width, height, factor, children, passes, ...rest }) => { const rec = p => p <= 0 ? children : {rec(p-1)} ; return rec(passes); }, { displayName: "Blur", defaultProps: { passes: 2 }, propTypes: { width: PropTypes.number, height: PropTypes.number, factor: PropTypes.number.isRequired, children: PropTypes.any.isRequired, passes: PropTypes.number } }); ``` **Usages:** - Small blur: ```html {any} ``` - Medium blur: ```html {any} ``` - Powerful blur: ```html {any} ```