UNPKG

inertialrush-game-test

Version:

This package enables the integration of the Inertial Rush game into any React application, making it easy to showcase the game.

121 lines (78 loc) 2.61 kB
/** * @author Thibaut Despoulain / http://bkcore.com * @author alteredq / http://alteredqualia.com/ * @author mr.doob / http://mrdoob.com/ */ var bkcore = bkcore || {}; bkcore.threejs = bkcore.threejs || {}; bkcore.threejs.Shaders = { /* ------------------------------------------------------------------------------------------------ // Hexagonal Vignette shader // by BKcore.com ------------------------------------------------------------------------------------------------ */ 'hexvignette': { uniforms: { tDiffuse: { value: null }, tHex: { value: null }, size: { value: 512.0 }, rx: { value: 1024.0 }, ry: { value: 768.0 }, color: { value: new THREE.Color(0x458ab1) } }, vertexShader: [ "varying vec2 vUv;", "void main() {", "vUv = uv;", "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", "}" ].join("\n"), fragmentShader: [ "uniform float size;", "uniform float rx;", "uniform float ry;", "uniform vec3 color;", "uniform sampler2D tDiffuse;", "uniform sampler2D tHex;", "varying vec2 vUv;", "void main() {", "vec4 vcolor = vec4(color,1.0);", "vec2 hexuv;", "hexuv.x = mod(vUv.x * rx, size) / size;", "hexuv.y = mod(vUv.y * ry, size) / size;", "vec4 hex = texture2D( tHex, hexuv );", "float tolerance = 0.2;", "float vignette_size = 0.6;", "vec2 powers = pow(abs(vec2(vUv.x - 0.5,vUv.y - 0.5)),vec2(2.0));", "float radiusSqrd = vignette_size*vignette_size;", "float gradient = smoothstep(radiusSqrd-tolerance, radiusSqrd+tolerance, powers.x+powers.y);", "vec2 uv = ( vUv - vec2( 0.5 ) );", "vec2 sample = uv * gradient * 0.5 * (1.0-hex.r);", "vec4 texel = texture2D( tDiffuse, vUv-sample );", "gl_FragColor = (((1.0-hex.r)*vcolor) * 0.5 * gradient) + vec4( mix( texel.rgb, vcolor.xyz*0.7, dot( uv, uv ) ), texel.a );", "}" ].join("\n") }, 'screen' : { uniforms: { tDiffuse: { value: null }, opacity: { value: 1.0 } }, vertexShader: [ "varying vec2 vUv;", "void main() {", "vUv = uv;", "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", "}" ].join("\n"), fragmentShader: [ "uniform float opacity;", "uniform sampler2D tDiffuse;", "varying vec2 vUv;", "void main() {", "vec4 texel = texture2D( tDiffuse, vUv );", "gl_FragColor = opacity * texel;", "}" ].join("\n") }, };