├── .gitignore
├── .jshintrc
├── LICENSE
├── README.md
├── assets
├── build
│ ├── bundle.js
│ └── bundle.js.map
├── images
│ ├── bokeh.png
│ ├── cloud1024.png
│ ├── earth_atmos_2048.jpg
│ ├── gene.sys
│ │ ├── gene.sys_01.png
│ │ ├── gene.sys_02.png
│ │ ├── gene.sys_03.png
│ │ ├── gene.sys_04.png
│ │ ├── gene.sys_05.png
│ │ ├── gene.sys_06.png
│ │ ├── gene.sys_07.png
│ │ └── gene.sys_08.png
│ ├── nasa-goddard.png
│ ├── sinegravitycloud.png
│ ├── sound-mute-hover.png
│ ├── sound-mute.png
│ ├── sound-unmute-hover.png
│ └── sound-unmute.png
├── shaders
│ ├── shaderplay.example.frag
│ ├── shaderplay.example.vert
│ ├── sinegravitycloud.frag
│ └── sinegravitycloud.vert
└── vendor
│ ├── jquery-2.1.1.min.js
│ ├── jquery-2.1.1.min.map
│ ├── three.js
│ ├── three.min.js
│ ├── underscore-min.js
│ └── underscore-min.map
├── base.css
├── index.hbs
├── index.html
├── js
├── components
│ ├── Info.js
│ ├── Stars.js
│ ├── ambiance
│ │ ├── Clouds
│ │ │ ├── clouds.frag
│ │ │ ├── clouds.vert
│ │ │ └── index.js
│ │ ├── Sky
│ │ │ ├── index.js
│ │ │ ├── sky-old.frag
│ │ │ ├── sky.frag
│ │ │ └── sky.vert
│ │ ├── blobs
│ │ │ ├── blobs.frag
│ │ │ ├── blobs.js
│ │ │ └── blobs.vert
│ │ ├── light-beam
│ │ │ ├── light-beam.frag
│ │ │ ├── light-beam.js
│ │ │ └── light-beam.vert
│ │ └── particles
│ │ │ ├── particles.frag
│ │ │ ├── particles.js
│ │ │ └── particles.vert
│ ├── animator.js
│ ├── cameras
│ │ ├── Camera.js
│ │ ├── ConstantMove.js
│ │ ├── Controls.js
│ │ ├── Orientation.js
│ │ ├── RestrictedCamera.js
│ │ ├── RotateAroundOrigin.js
│ │ ├── Swivel.js
│ │ └── Trackball.js
│ ├── fbo-positioning
│ │ ├── fbo-position.shader
│ │ ├── fbo-render.frag
│ │ ├── fbo-render.vert
│ │ └── fbo.js
│ ├── hids
│ │ └── mouse-tracker.js
│ ├── lights
│ │ └── TrackCameraLights.js
│ ├── models
│ │ ├── tree.js
│ │ └── tree.json
│ ├── sound
│ │ ├── Music.js
│ │ └── SoundGenerator.js
│ └── utils
│ │ ├── Stats.js
│ │ └── drag-scroll.js
├── core
│ ├── manifestToPoem.js
│ ├── poem.js
│ ├── routing.js
│ └── ui.js
├── demos
│ ├── Earth.js
│ ├── EndlessTerrain
│ │ ├── credits.js
│ │ ├── endless.frag
│ │ ├── endless.js
│ │ ├── endless.vert
│ │ └── keyframes.js
│ ├── Grid.js
│ ├── MeshGroupBoxDemo
│ │ ├── MeshGroup.js
│ │ ├── index.js
│ │ ├── shader.frag
│ │ └── shader.vert
│ ├── TexturePositionalMatrices
│ │ ├── index.js
│ │ ├── shader.frag
│ │ └── shader.vert
│ ├── UniformPositionalMatrices
│ │ ├── index.js
│ │ ├── shader.frag
│ │ └── shader.vert
│ ├── sine-gravity-cloud
│ │ ├── sine.frag
│ │ ├── sine.js
│ │ └── sine.vert
│ ├── tetrahedra.js
│ └── wire-terrain
│ │ ├── credits.js
│ │ ├── keyframes.js
│ │ ├── terrain.frag
│ │ ├── terrain.js
│ │ └── terrain.vert
├── index.js
├── postprocessing
│ ├── BloomPass.js
│ ├── BokehPass.js
│ ├── ChromaticAberration
│ │ ├── chromatic.frag
│ │ ├── chromatic.vert
│ │ └── index.js
│ ├── DotScreenPass.js
│ ├── EffectComposer.js
│ ├── FilmPass.js
│ ├── GlitchPass.js
│ ├── MaskPass.js
│ ├── RenderPass.js
│ ├── SSAOShader.js
│ ├── SavePass.js
│ ├── ShaderPass.js
│ ├── TexturePass.js
│ ├── index.js
│ └── playground
│ │ ├── playground.frag
│ │ ├── playground.js
│ │ └── playground.vert
├── renderers
│ ├── basic-renderer.js
│ ├── cardboard-renderer.js
│ ├── effects-renderer.js
│ ├── postprocess-renderer.js
│ └── utils
│ │ ├── create-renderer.js
│ │ ├── fade-out-ui.js
│ │ ├── resize-handler.js
│ │ └── resize-renderer-fn.js
├── shaders
│ ├── BasicShader.js
│ ├── BleachBypassShader.js
│ ├── BlendShader.js
│ ├── BokehShader.js
│ ├── BokehShader2.js
│ ├── BrightnessContrastShader.js
│ ├── ChromaticAberration.js
│ ├── ColorCorrectionShader.js
│ ├── ColorifyShader.js
│ ├── ConvolutionShader.js
│ ├── CopyShader.js
│ ├── DOFMipMapShader.js
│ ├── DigitalGlitch.js
│ ├── DotScreenShader.js
│ ├── EdgeShader.js
│ ├── EdgeShader2.js
│ ├── FXAAShader.js
│ ├── FilmShader.js
│ ├── FocusShader.js
│ ├── FresnelShader.js
│ ├── HorizontalBlurShader.js
│ ├── HorizontalTiltShiftShader.js
│ ├── HueSaturationShader.js
│ ├── KaleidoShader.js
│ ├── LuminosityShader.js
│ ├── MirrorShader.js
│ ├── NormalMapShader.js
│ ├── OceanShaders.js
│ ├── RGBShiftShader.js
│ ├── SSAOShader.js
│ ├── SepiaShader.js
│ ├── TechnicolorShader.js
│ ├── TestShader.js
│ ├── TriangleBlurShader.js
│ ├── UnpackDepthRGBAShader.js
│ ├── VerticalBlurShader.js
│ ├── VerticalTiltShiftShader.js
│ └── VignetteShader.js
├── sound
│ ├── Music.js
│ ├── SoundGenerator.js
│ └── mute.js
├── utils
│ ├── Clock.js
│ ├── ClosedSplineCurve3.js
│ ├── EventDispatcher.js
│ ├── Stats.js
│ ├── ThreeConsole.js
│ ├── WebGLDetector.js
│ ├── calculateSquaredTextureWidth.js
│ ├── destroyMesh.js
│ ├── duplicate-buffer-geometry.js
│ ├── gpu-processor
│ │ ├── README.md
│ │ ├── copy-texture.js
│ │ └── gpu-processor.js
│ ├── loadImage.js
│ ├── loadText.js
│ ├── loadTexture.js
│ ├── random.js
│ ├── selectors.js
│ ├── simplex2.js
│ └── simplex3.js
└── vendor
│ ├── AssimpJSONLoader.js
│ ├── DeviceOrientationControls.js
│ ├── OrbitControls.js
│ ├── Stats.js
│ ├── StereoEffect.js
│ ├── TrackballControls.js
│ └── WebGLDetector.js
├── manifests
├── blobs.js
├── carbonDioxideEarth.js
├── cubic.js
├── endlessTerrain.js
├── fbo-positioning.js
├── index.js
├── light-beams.js
├── meshGroupBoxDemo.js
├── postprocessing.js
├── sineGravityCloud.js
├── tetrahedra.js
├── texturePositionalMatrices.js
├── uniformPositionalMatrices.js
└── vr.js
├── menu.html
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | assets/video/*
2 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "globals": {
3 | "THREE": true,
4 | "_": true,
5 | "poem": true,
6 | "LevelLoader": true,
7 | "webkitAudioContext": true,
8 | "AudioContext": true,
9 | "_gaq": true
10 | },
11 | "laxcomma": true,
12 | "node": true,
13 | "devel": true,
14 | "asi": true,
15 | "jquery": true,
16 | "sub": true,
17 | "browser": true,
18 | "debug": true, //allow debug statements
19 | "eqeqeq": true, //must use ===
20 | "latedef": "nofunc", //variables must be defined before use
21 | "undef": true //all variables must be declared
22 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Greg Tatum
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Three.js Sandbox
2 |
3 | http://gregtatum.com/sandbox/
4 |
5 | A sandbox to play around with ideas. It uses [poem-manifests](https://www.npmjs.com/package/poem-manifests), [poem-loop](https://www.npmjs.com/package/poem-loop), and [poem-menu](https://www.npmjs.com/package/poem-menu) to quickly write re-usable 3d code. See the respective module documentation pages to see how the manifests and menus work.
6 |
7 | The central poem object is the application graph. If you're looking to get oriented in the code base, the manifests are the individual experiments. They then load in components that get saved to the central poem object.
8 |
9 | ## Running
10 |
11 | Make sure npm is install, then in the directory run `npm install` to get the dependencies.
12 |
13 | To run and prototype with live-reload:
14 |
15 | npm start
16 |
17 | To build:
18 |
19 | npm run build
20 |
21 | Project copyright (c) 2014 Greg Tatum under The MIT License (MIT)
22 |
--------------------------------------------------------------------------------
/assets/images/bokeh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/bokeh.png
--------------------------------------------------------------------------------
/assets/images/cloud1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/cloud1024.png
--------------------------------------------------------------------------------
/assets/images/earth_atmos_2048.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/earth_atmos_2048.jpg
--------------------------------------------------------------------------------
/assets/images/gene.sys/gene.sys_01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/gene.sys/gene.sys_01.png
--------------------------------------------------------------------------------
/assets/images/gene.sys/gene.sys_02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/gene.sys/gene.sys_02.png
--------------------------------------------------------------------------------
/assets/images/gene.sys/gene.sys_03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/gene.sys/gene.sys_03.png
--------------------------------------------------------------------------------
/assets/images/gene.sys/gene.sys_04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/gene.sys/gene.sys_04.png
--------------------------------------------------------------------------------
/assets/images/gene.sys/gene.sys_05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/gene.sys/gene.sys_05.png
--------------------------------------------------------------------------------
/assets/images/gene.sys/gene.sys_06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/gene.sys/gene.sys_06.png
--------------------------------------------------------------------------------
/assets/images/gene.sys/gene.sys_07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/gene.sys/gene.sys_07.png
--------------------------------------------------------------------------------
/assets/images/gene.sys/gene.sys_08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/gene.sys/gene.sys_08.png
--------------------------------------------------------------------------------
/assets/images/nasa-goddard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/nasa-goddard.png
--------------------------------------------------------------------------------
/assets/images/sinegravitycloud.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/sinegravitycloud.png
--------------------------------------------------------------------------------
/assets/images/sound-mute-hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/sound-mute-hover.png
--------------------------------------------------------------------------------
/assets/images/sound-mute.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/sound-mute.png
--------------------------------------------------------------------------------
/assets/images/sound-unmute-hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/sound-unmute-hover.png
--------------------------------------------------------------------------------
/assets/images/sound-unmute.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/assets/images/sound-unmute.png
--------------------------------------------------------------------------------
/assets/shaders/shaderplay.example.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 | precision highp int;
3 |
4 |
5 | #define MAX_DIR_LIGHTS 0
6 | #define MAX_POINT_LIGHTS 0
7 | #define MAX_SPOT_LIGHTS 0
8 | #define MAX_HEMI_LIGHTS 0
9 | #define MAX_SHADOWS 0
10 |
11 | uniform mat4 viewMatrix;
12 | uniform vec3 cameraPosition;
13 | uniform vec3 color;
14 | uniform sampler2D texture;
15 |
16 | varying vec3 vColor;
17 |
18 | void main() {
19 |
20 | gl_FragColor = vec4( color * vColor, 1.0 );
21 |
22 | gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );
23 |
24 | }
--------------------------------------------------------------------------------
/assets/shaders/shaderplay.example.vert:
--------------------------------------------------------------------------------
1 | precision highp float;
2 | precision highp int;
3 |
4 | #define VERTEX_TEXTURES
5 | #define MAX_DIR_LIGHTS 0
6 | #define MAX_POINT_LIGHTS 0
7 | #define MAX_SPOT_LIGHTS 0
8 | #define MAX_HEMI_LIGHTS 0
9 | #define MAX_SHADOWS 0
10 | #define MAX_BONES 251
11 |
12 | uniform mat4 modelMatrix;
13 | uniform mat4 modelViewMatrix;
14 | uniform mat4 projectionMatrix;
15 | uniform mat4 viewMatrix;
16 | uniform mat3 normalMatrix;
17 | uniform vec3 cameraPosition;
18 | attribute vec3 position;
19 | attribute vec3 normal;
20 | attribute vec2 uv;
21 | attribute vec2 uv2;
22 | #ifdef USE_COLOR
23 | attribute vec3 color;
24 | #endif
25 | #ifdef USE_MORPHTARGETS
26 | attribute vec3 morphTarget0;
27 | attribute vec3 morphTarget1;
28 | attribute vec3 morphTarget2;
29 | attribute vec3 morphTarget3;
30 | #ifdef USE_MORPHNORMALS
31 | attribute vec3 morphNormal0;
32 | attribute vec3 morphNormal1;
33 | attribute vec3 morphNormal2;
34 | attribute vec3 morphNormal3;
35 | #else
36 | attribute vec3 morphTarget4;
37 | attribute vec3 morphTarget5;
38 | attribute vec3 morphTarget6;
39 | attribute vec3 morphTarget7;
40 | #endif
41 | #endif
42 | #ifdef USE_SKINNING
43 | attribute vec4 skinIndex;
44 | attribute vec4 skinWeight;
45 | #endif
46 | attribute float size;
47 | attribute vec3 customColor;
48 |
49 | varying vec3 vColor;
50 |
51 | void main() {
52 |
53 | vColor = customColor;
54 |
55 | vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
56 |
57 | gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) );
58 |
59 | gl_Position = projectionMatrix * mvPosition;
60 |
61 | }
--------------------------------------------------------------------------------
/assets/shaders/sinegravitycloud.frag:
--------------------------------------------------------------------------------
1 | uniform vec3 color;
2 | uniform sampler2D texture;
3 |
4 | varying vec3 vColor;
5 |
6 | void main() {
7 |
8 | gl_FragColor = vec4( color * vColor, 1.0 );
9 |
10 | gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );
11 |
12 | }
--------------------------------------------------------------------------------
/assets/shaders/sinegravitycloud.vert:
--------------------------------------------------------------------------------
1 | attribute float size;
2 | attribute vec3 customColor;
3 |
4 | varying vec3 vColor;
5 |
6 | void main() {
7 |
8 | vColor = customColor;
9 |
10 | vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
11 |
12 | gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) );
13 |
14 | gl_Position = projectionMatrix * mvPosition;
15 |
16 | }
--------------------------------------------------------------------------------
/index.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{documentTitle}}
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
46 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | A Three.js Sandbox of Experiments | Greg Tatum
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
46 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/js/components/Info.js:
--------------------------------------------------------------------------------
1 | var Info = function( poem, properties ) {
2 |
3 | var originalTitle = document.title;
4 |
5 | var $appendCredits = $( properties.appendCredits );
6 |
7 | if( properties.appendCredits ) $('.credits').append( $appendCredits );
8 | if( properties.title ) $("#info-title").text( properties.title );
9 | if( properties.subtitle ) $("#info-subtitle").text( properties.subtitle);
10 |
11 | if( properties.titleCss ) $("#info-title").css( properties.titleCss );
12 | if( properties.subtitleCss ) $("#info-subtitle").css( properties.subtitleCss );
13 |
14 |
15 | if( properties.documentTitle ) document.title = properties.documentTitle;
16 |
17 | if( properties.showArrowNext ) $(".arrow-next").show();
18 |
19 | $("#info").show();
20 |
21 | poem.emitter.on('destroy', function() {
22 | document.title = originalTitle;
23 | $("#info-title").text('');
24 | $("#info-subtitle").text('');
25 | $("#info-title").attr('style', '');
26 | $("#info-subtitle").attr('style', '');
27 | $(".arrow-next").hide();
28 | $("#info").hide();
29 | $appendCredits.remove();
30 | });
31 |
32 | };
33 |
34 | module.exports = Info;
--------------------------------------------------------------------------------
/js/components/Stars.js:
--------------------------------------------------------------------------------
1 | var Stars = function( poem ) {
2 | this.poem = poem;
3 | this.object = null;
4 |
5 | this.count = 30000;
6 | this.depth = 5000;
7 | this.minDepth = 700;
8 | this.color = 0xaaaaaa;
9 |
10 | this.addObject();
11 | };
12 |
13 | module.exports = Stars;
14 |
15 | Stars.prototype = {
16 |
17 | generateGeometry : function() {
18 | var r, theta, x, y, z, geometry;
19 |
20 | geometry = new THREE.Geometry();
21 |
22 | for(var i=0; i < this.count; i++) {
23 |
24 | r = Math.random() * this.depth + this.minDepth;
25 |
26 | theta = Math.random() * 2 * Math.PI;
27 |
28 | x = Math.cos( theta ) * r;
29 | z = Math.sin( theta ) * r;
30 | y = (0.5 - Math.random()) * this.depth;
31 |
32 | geometry.vertices.push( new THREE.Vector3(x,y,z) );
33 |
34 | }
35 |
36 | return geometry;
37 | },
38 |
39 | addObject : function() {
40 |
41 | var geometry, lineMaterial;
42 |
43 | geometry = this.generateGeometry();
44 |
45 |
46 | this.object = new THREE.PointCloud(
47 | geometry,
48 | new THREE.PointCloudMaterial({
49 | size: 3 * this.poem.ratio,
50 | color: this.color,
51 | fog: false
52 | }
53 | ) );
54 |
55 | this.poem.scene.add( this.object ) ;
56 |
57 | }
58 | };
--------------------------------------------------------------------------------
/js/components/ambiance/Clouds/clouds.frag:
--------------------------------------------------------------------------------
1 | uniform float time;
2 | uniform vec4 color;
3 | uniform vec2 offset;
4 | uniform sampler2D texture;
5 |
6 | varying vec2 vUv;
7 |
8 | void main() {
9 |
10 | vec4 texel =
11 | texture2D( texture, vUv * 0.1 + ( offset + time * 0.00001) * offset ) +
12 | texture2D( texture, vUv * 0.22 + ( offset + time * 0.0000055) * offset );
13 |
14 | float edges = 0.5 - length(vUv - 0.5);
15 |
16 | gl_FragColor = color * edges * vec4( 1.0, 1.0, 1.0, texel.w * texel.w * 2.5 );
17 |
18 | }
--------------------------------------------------------------------------------
/js/components/ambiance/Clouds/clouds.vert:
--------------------------------------------------------------------------------
1 | varying vec2 vUv;
2 |
3 | void main() {
4 |
5 | vUv = uv;
6 |
7 | gl_Position = projectionMatrix *
8 | modelViewMatrix *
9 | vec4( position, 1.0);
10 |
11 | }
--------------------------------------------------------------------------------
/js/components/ambiance/Clouds/index.js:
--------------------------------------------------------------------------------
1 | var glslify = require('glslify');
2 |
3 | function setupTexture( mesh, scene, material ) {
4 |
5 | var img = new Image();
6 | var texture = new THREE.Texture( img );
7 | img.src = 'assets/images/cloud1024.png';
8 |
9 | $('body').append(img);
10 |
11 | texture.wrapS = THREE.RepeatWrapping;
12 | texture.wrapT = THREE.RepeatWrapping;
13 |
14 | $(img).on('load', function() {
15 | material.needsUpdate = true;
16 | texture.needsUpdate = true;
17 | });
18 |
19 | scene.add( mesh );
20 |
21 | return texture;
22 |
23 | }
24 |
25 | var Clouds = function( poem, properties ) {
26 |
27 | var config = _.extend({
28 | width : 500,
29 | offset : new THREE.Vector2(1,1),
30 | color : new THREE.Vector4( 0.5, 1.0, 0.7, 1 ),
31 | height : -200,
32 | rotation : Math.PI / 2
33 | }, properties);
34 |
35 | var geometry = new THREE.PlaneGeometry( config.width, config.width );
36 |
37 | var material = new THREE.ShaderMaterial({
38 |
39 | vertexShader: glslify('./clouds.vert'),
40 | fragmentShader: glslify('./clouds.frag'),
41 |
42 | transparent: true,
43 | blending: THREE.AdditiveBlending,
44 | side: THREE.DoubleSide,
45 | depthTest: false,
46 |
47 | uniforms: {
48 | time: { type: "f", value:0 },
49 | texture: { type: "t", value: null },
50 | offset: { type: "v2", value: config.offset },
51 | color: { type: "v4", value: config.color }
52 | },
53 | attributes: {}
54 | })
55 |
56 | var mesh = new THREE.Mesh( geometry, material );
57 |
58 | mesh.rotation.x = config.rotation;
59 | mesh.position.y = config.height;
60 | mesh.scale.multiplyScalar( 10 );
61 |
62 | material.uniforms.texture.value = setupTexture( mesh, poem.scene, material );
63 |
64 | poem.emitter.on('update', function( e ) {
65 | var cameraPosition = poem.camera.object.position;
66 | material.uniforms.time.value = e.elapsed;
67 | mesh.position.set(
68 | cameraPosition.x,
69 | mesh.position.y,
70 | cameraPosition.z
71 | );
72 | });
73 | };
74 |
75 | module.exports = Clouds;
76 |
--------------------------------------------------------------------------------
/js/components/ambiance/Sky/index.js:
--------------------------------------------------------------------------------
1 | var glslify = require('glslify');
2 |
3 | var Sky = function( poem, properties ) {
4 |
5 | var config = _.extend({
6 |
7 | width : 5000
8 |
9 | }, properties );
10 |
11 | var geometry = new THREE.SphereGeometry( config.width, 64, 30 );
12 |
13 | var material = new THREE.ShaderMaterial({
14 |
15 | vertexShader : glslify('./sky.vert'),
16 | fragmentShader : glslify('./sky.frag'),
17 |
18 | side : THREE.BackSide,
19 | transparent : true,
20 | depthTest : false,
21 |
22 | uniforms: {
23 | time: { type: "f", value:0 },
24 | },
25 | attributes: {}
26 | })
27 |
28 | var mesh = new THREE.Mesh( geometry, material );
29 | poem.scene.add( mesh );
30 |
31 | poem.emitter.on('update', function( e ) {
32 | material.uniforms.time.value = e.elapsed;
33 | mesh.position.copy( poem.camera.object.position );
34 | });
35 | };
36 |
37 | module.exports = Sky;
38 |
--------------------------------------------------------------------------------
/js/components/ambiance/Sky/sky-old.frag:
--------------------------------------------------------------------------------
1 | #define PI 3.141592653589793
2 | #define TWOPI 6.283185307179586
3 |
4 | varying vec4 vColor;
5 | varying vec2 vUv;
6 | uniform float time;
7 |
8 | #pragma glslify: snoise3 = require(glsl-noise/simplex/3d)
9 |
10 | float remap( in float value, in float start, in float stop ) {
11 | return start + value * ( stop - start );
12 | }
13 |
14 | float inRange( in float value, in float start, in float stop ) {
15 |
16 | return min( 1.0, max( 0.0,
17 | (value - start) / (stop - start)
18 | ));
19 |
20 | }
21 |
22 | float generateClouds( in vec2 vUv, in float time ) {
23 |
24 | return snoise3( 10.0 * vec3(
25 | sin( vUv.x * PI ) * 0.5,
26 | vUv.y,
27 | time
28 | ));
29 |
30 | }
31 |
32 |
33 | void main() {
34 |
35 | float timeScaled = time * 0.00001;
36 |
37 | float brightness =
38 | inRange( vUv.y, 0.4, 0.6 ) *
39 | mix( sin( vUv.x * 10.0 * TWOPI ), 1.0, 0.2 );
40 |
41 | brightness += generateClouds( vUv, timeScaled );
42 |
43 | vec4 cloudColor = vec4(
44 | 0.0,
45 | 0.3 * brightness,
46 | 0.3 * brightness,
47 | 0.1
48 | );
49 |
50 | vec4 noise = vec4(
51 | snoise3( vec3( 10.0, 10.0, timeScaled ) ),
52 | snoise3( vec3( 10.0, 10.0, timeScaled ) ),
53 | snoise3( vec3( 10.0, 10.0, timeScaled ) ),
54 | 1.0
55 | );
56 |
57 | gl_FragColor = vColor + cloudColor * noise;
58 |
59 | }
--------------------------------------------------------------------------------
/js/components/ambiance/Sky/sky.frag:
--------------------------------------------------------------------------------
1 | varying vec4 vColor;
2 |
3 | // float remap( in float value, in float start, in float stop ) {
4 | // return start + value * ( stop - start );
5 | // }
6 |
7 | void main() {
8 |
9 | gl_FragColor = vColor;
10 |
11 | }
--------------------------------------------------------------------------------
/js/components/ambiance/Sky/sky.vert:
--------------------------------------------------------------------------------
1 | uniform float time;
2 | varying vec4 vColor;
3 |
4 | #pragma glslify: simplex4 = require(glsl-noise/simplex/4d)
5 | #pragma glslify: hsv2rgb = require(glsl-hsv2rgb)
6 |
7 | float inRange( in float value, in float start, in float stop ) {
8 |
9 | return min( 1.0, max( 0.0,
10 | (value - start) / (stop - start)
11 | ));
12 |
13 | }
14 |
15 | vec4 calculateColor( in vec2 uv, in vec3 position ) {
16 |
17 | float gradient =
18 | inRange( uv.y, 0.55, 0.7 ) +
19 | inRange( uv.y, 0.45, 0.3 ) ;
20 |
21 | float noise = simplex4( vec4( position * 0.03, time * 0.0001 ) );
22 |
23 | vec3 color = hsv2rgb(vec3(
24 | max(0.0, noise) * 0.2 + 0.4,
25 | 1.0,
26 | 1.0
27 | ));
28 |
29 | return vec4(
30 | color,
31 | noise * gradient
32 | );
33 |
34 | }
35 |
36 | void main() {
37 |
38 | vColor = calculateColor( uv, position );
39 |
40 | gl_Position = projectionMatrix *
41 | modelViewMatrix *
42 | vec4( position, 1.0);
43 |
44 | }
--------------------------------------------------------------------------------
/js/components/ambiance/blobs/blobs.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 |
3 | uniform float elapsed;
4 | varying float vOffset;
5 |
6 | vec2 doModel(vec3 p);
7 |
8 | #pragma glslify: raytrace = require('glsl-raytrace', map = doModel, steps = 30)
9 | #pragma glslify: normal = require('glsl-sdf-normal', map = doModel)
10 | #pragma glslify: camera = require('glsl-turntable-camera')
11 | #pragma glslify: noise = require('glsl-noise/simplex/4d')
12 | #pragma glslify: cameraRay = require('glsl-camera-ray')
13 |
14 | vec2 doModel(vec3 p) {
15 | float r = 1.0 + noise(vec4(p, elapsed / 1000.0)) * 0.25;
16 | float d = length(p) - r;
17 | float id = 0.0;
18 |
19 | return vec2(d, id);
20 | }
21 |
22 | vec2 squareFrame(vec2 screenSize, vec2 screenPosition) {
23 | vec2 position = 2.0 * (screenPosition.xy / screenSize.xy) - 1.0;
24 | position.x *= screenSize.x / screenSize.y;
25 | return position;
26 | }
27 |
28 |
29 | void orbitCamera(
30 | in float camAngle,
31 | in float camHeight,
32 | in float camDistance,
33 | in vec2 screenResolution,
34 | in vec2 screenPosition,
35 | out vec3 rayOrigin,
36 | out vec3 rayDirection
37 | ) {
38 | vec2 screenPos = squareFrame(screenResolution, screenPosition);
39 | vec3 rayTarget = vec3(0.0);
40 |
41 | rayOrigin = vec3(
42 | camDistance * sin(camAngle),
43 | camHeight,
44 | camDistance * cos(camAngle)
45 | );
46 |
47 | rayDirection = cameraRay(rayOrigin, rayTarget, screenPos, 2.0);
48 | }
49 |
50 |
51 | void main() {
52 | vec3 color = vec3(0.0);
53 | vec3 rayOrigin, rayDirection;
54 |
55 | float rotation = elapsed / 1000.0;
56 | float height = 0.0;
57 | float dist = 3.0;
58 | vec2 iResolution = vec2( 1.0, 1.0 );
59 |
60 | orbitCamera(rotation + vOffset * 100.0, height, dist, iResolution, gl_PointCoord, rayOrigin, rayDirection);
61 |
62 | vec2 t = raytrace(rayOrigin, rayDirection);
63 | if (t.x > -0.5) {
64 | vec3 pos = rayOrigin + rayDirection * t.x;
65 | vec3 nor = normal(pos);
66 |
67 | color = nor * 0.5 + 0.5;
68 | }
69 |
70 | gl_FragColor.rgb = color;
71 | gl_FragColor.a = length(color) * 10.0;
72 | }
73 |
74 | // Old shader:
75 | //
76 | // uniform vec3 color;
77 | // uniform sampler2D texture;
78 | // uniform float elapsed;
79 | //
80 | // varying float vAlpha;
81 | //
82 | // void main() {
83 | //
84 | // gl_FragColor = vec4(color, 1.0);
85 | //
86 | // }
87 | //
--------------------------------------------------------------------------------
/js/components/ambiance/blobs/blobs.js:
--------------------------------------------------------------------------------
1 | var Glslify = require('glslify')
2 | var LoadTexture = require('../../../utils/loadTexture')
3 | var Random = require('../../../utils/random')
4 |
5 |
6 | function _createMaterial( color, range ) {
7 |
8 | var material = new THREE.ShaderMaterial({
9 |
10 | vertexShader : Glslify('./blobs.vert'),
11 | fragmentShader : Glslify('./blobs.frag'),
12 | depthTest : false,
13 | blending : THREE.AdditiveBlending,
14 | transparent : true,
15 | uniforms : {
16 | elapsed : { type: 'f', value: color },
17 | uRange : { type: 'f', value: range }
18 | },
19 | attributes : {
20 | size : { type: 'f', value: [] },
21 | aOffset : { type: 'f', value: [] }
22 | }
23 |
24 | })
25 |
26 |
27 | return material
28 | }
29 |
30 | function _createGeometry( material, count, range, sizeRange, ratio ) {
31 |
32 | var geometry = new THREE.BufferGeometry()
33 |
34 | var positions = new Float32Array( count * 3 )
35 | var sizes = new Float32Array( count )
36 | var offsets = new Float32Array( count )
37 |
38 | for( var i = 0; i < count; i++ ) {
39 |
40 | positions[ i * 3 + 0 ] = Random.range( -range, range )
41 | positions[ i * 3 + 1 ] = Random.range( -range, range ) * 0.3
42 | positions[ i * 3 + 2 ] = Random.range( -range, range )
43 |
44 | sizes[ i ] = Random.range( sizeRange[0], sizeRange[1] ) * ratio
45 | offsets[ i ] = Random.range( 0, 1 )
46 |
47 | }
48 |
49 | geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) )
50 | geometry.addAttribute( 'size', new THREE.BufferAttribute( sizes, 1 ) )
51 | geometry.addAttribute( 'aOffset', new THREE.BufferAttribute( offsets, 1 ) )
52 |
53 | return geometry
54 | }
55 |
56 | function _createMeshAndStart( poem, geometry, material ) {
57 |
58 | var mesh = new THREE.PointCloud( geometry, material )
59 | mesh.frustumCulled = false
60 |
61 | var p = LoadTexture( "assets/images/bokeh.png", material.uniforms.texture, "value" ).then(function() {
62 |
63 | poem.scene.add( mesh )
64 | poem.emitter.on('update', _updateFn( poem, mesh ))
65 | })
66 |
67 | return mesh
68 | }
69 |
70 | function _updateFn( poem, mesh ) {
71 |
72 | return function(e) {
73 |
74 | // mesh.position.copy( poem.camera.object.position )
75 | mesh.material.uniforms.elapsed.value = e.elapsed;
76 | }
77 | }
78 |
79 | module.exports = function particles( poem, properties ) {
80 |
81 | var config = _.extend({
82 | count: 1000
83 | , color: new THREE.Color(0x77ffff)
84 | , range: 300
85 | , sizeRange: [10,20]
86 | }, properties)
87 |
88 | var material = _createMaterial(
89 | config.color
90 | , config.range
91 | )
92 |
93 | var geometry = _createGeometry(
94 | material
95 | , config.count
96 | , config.range
97 | , config.sizeRange
98 | , poem.ratio
99 | )
100 |
101 | var mesh = _createMeshAndStart(
102 | poem,
103 | geometry,
104 | material
105 | )
106 |
107 | return {}
108 | }
--------------------------------------------------------------------------------
/js/components/ambiance/blobs/blobs.vert:
--------------------------------------------------------------------------------
1 | uniform float elapsed;
2 | uniform float uRange;
3 | attribute float size;
4 | attribute float aOffset;
5 |
6 | varying float vOffset;
7 | #pragma glslify: snoise3 = require(glsl-noise/simplex/3d)
8 |
9 | void main() {
10 |
11 | // vec3 movement = vec3(0.0, elapsed * 0.001, 0.0);
12 | vec3 movement = vec3(
13 | sin( elapsed * 0.002 * aOffset) * uRange * 0.003,
14 | elapsed * (-uRange / 100000.0 - uRange / 100000.0 * aOffset),
15 | cos( elapsed * 0.002 * aOffset ) * uRange * 0.003
16 | );
17 |
18 | vec3 range = vec3(uRange, uRange * 0.3, uRange);
19 |
20 | vec3 cameraOffset = cameraPosition - range;
21 |
22 | vec3 moduloPosition = mod( position + movement - cameraOffset, range * 2.0 ) + cameraOffset;
23 | vec4 mvPosition = modelViewMatrix * vec4( moduloPosition, 1.0 );
24 |
25 | vOffset = aOffset;
26 |
27 | gl_PointSize = size * ( uRange / (length( mvPosition.xyz ) + 1.0) );
28 | gl_Position = projectionMatrix * mvPosition;
29 |
30 | }
--------------------------------------------------------------------------------
/js/components/ambiance/light-beam/light-beam.frag:
--------------------------------------------------------------------------------
1 | uniform vec3 color;
2 | uniform sampler2D texture;
3 | // uniform float elapsed;
4 |
5 | varying float vAlpha;
6 |
7 | void main() {
8 |
9 | gl_FragColor = vec4(color, vAlpha) * texture2D( texture, gl_PointCoord );
10 |
11 | }
--------------------------------------------------------------------------------
/js/components/ambiance/light-beam/light-beam.vert:
--------------------------------------------------------------------------------
1 | uniform float elapsed;
2 |
3 | attribute float size;
4 | attribute float opacity;
5 |
6 | varying float vAlpha;
7 |
8 | #pragma glslify: snoise3 = require(glsl-noise/simplex/3d)
9 |
10 | void main() {
11 |
12 | vAlpha = opacity;
13 |
14 | vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
15 |
16 | gl_PointSize = 100.0 * size / length( mvPosition.xyz );
17 |
18 | gl_Position = projectionMatrix * mvPosition;
19 | }
--------------------------------------------------------------------------------
/js/components/ambiance/particles/particles.frag:
--------------------------------------------------------------------------------
1 | uniform vec3 color;
2 | uniform sampler2D texture;
3 | uniform float elapsed;
4 |
5 | varying float vAlpha;
6 |
7 | void main() {
8 |
9 | gl_FragColor = vec4(color, vAlpha) * texture2D( texture, gl_PointCoord );
10 |
11 | }
--------------------------------------------------------------------------------
/js/components/ambiance/particles/particles.js:
--------------------------------------------------------------------------------
1 | var Glslify = require('glslify')
2 | var LoadTexture = require('../../../utils/loadTexture')
3 | var Random = require('../../../utils/random')
4 |
5 | var internals = {
6 |
7 | createMaterial : function( color, range ) {
8 |
9 | var material = new THREE.ShaderMaterial({
10 |
11 | vertexShader : Glslify('./particles.vert'),
12 | fragmentShader : Glslify('./particles.frag'),
13 |
14 | blending: THREE.AdditiveBlending,
15 | depthTest: false,
16 | transparent: true,
17 |
18 | uniforms: {
19 | elapsed : { type: 'f' },
20 | texture : { type: 't' },
21 | color : { type: "c", value: color },
22 | uRange : { type: "f", value: range },
23 | },
24 | attributes : {
25 | position: { type: 'v3' },
26 | size: { type: 'f' },
27 | aOffset: { type: 'f' },
28 | }
29 | })
30 |
31 | return material
32 | },
33 |
34 | createGeometry : function( material, count, range, sizeRange ) {
35 |
36 | var geometry = new THREE.BufferGeometry()
37 |
38 | var positions = new Float32Array( count * 3 )
39 | var sizes = new Float32Array( count )
40 | var offsets = new Float32Array( count )
41 |
42 | for( var i = 0; i < count; i++ ) {
43 |
44 | positions[ i * 3 + 0 ] = Random.range( -range, range )
45 | positions[ i * 3 + 1 ] = Random.range( -range, range ) * 0.3
46 | positions[ i * 3 + 2 ] = Random.range( -range, range )
47 |
48 | sizes[ i ] = Random.range( sizeRange[0], sizeRange[1] )
49 | offsets[ i ] = Random.range( 0, 1 )
50 |
51 | }
52 |
53 | geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) )
54 | geometry.addAttribute( 'size', new THREE.BufferAttribute( sizes, 1 ) )
55 | geometry.addAttribute( 'aOffset', new THREE.BufferAttribute( offsets, 1 ) )
56 |
57 | return geometry
58 | },
59 |
60 | createMeshAndStart : function( poem, geometry, material ) {
61 |
62 | var mesh = new THREE.PointCloud( geometry, material )
63 | mesh.frustumCulled = false
64 |
65 | var p = LoadTexture( "assets/images/bokeh.png", material.uniforms.texture, "value" ).then(function() {
66 |
67 | poem.scene.add( mesh )
68 | poem.emitter.on('update', internals.updateFn( poem, mesh ))
69 | })
70 |
71 | return mesh
72 | },
73 |
74 | updateFn : function( poem, mesh ) {
75 |
76 | return function(e) {
77 |
78 | // mesh.position.copy( poem.camera.object.position )
79 | mesh.material.uniforms.elapsed.value = e.elapsed;
80 | }
81 | }
82 | }
83 |
84 |
85 | module.exports = function particles( poem, properties ) {
86 |
87 | var config = _.extend({
88 | count: 3000
89 | , color: new THREE.Color(0x77ffff)
90 | , range: 300
91 | , sizeRange: [3,8]
92 | }, properties)
93 |
94 | var material = internals.createMaterial(
95 | config.color
96 | , config.range
97 | )
98 |
99 | var geometry = internals.createGeometry(
100 | material
101 | , config.count
102 | , config.range
103 | , config.sizeRange
104 | )
105 |
106 | var mesh = internals.createMeshAndStart(
107 | poem,
108 | geometry,
109 | material
110 | )
111 |
112 | return {}
113 | }
--------------------------------------------------------------------------------
/js/components/ambiance/particles/particles.vert:
--------------------------------------------------------------------------------
1 | uniform float elapsed;
2 | uniform float uRange;
3 | attribute float size;
4 | attribute float aOffset;
5 | varying float vAlpha;
6 |
7 | #pragma glslify: snoise3 = require(glsl-noise/simplex/3d)
8 |
9 | void main() {
10 |
11 | // vec3 movement = vec3(0.0, elapsed * 0.001, 0.0);
12 | vec3 movement = vec3(
13 | sin( elapsed * 0.002 * aOffset) * uRange * 0.003,
14 | elapsed * (-uRange / 100000.0 - uRange / 100000.0 * aOffset),
15 | cos( elapsed * 0.002 * aOffset ) * uRange * 0.003
16 | );
17 |
18 | vec3 range = vec3(uRange, uRange * 0.3, uRange);
19 |
20 | vec3 cameraOffset = cameraPosition - range;
21 |
22 | vec3 moduloPosition = mod( position + movement - cameraOffset, range * 2.0 ) + cameraOffset;
23 | vec4 mvPosition = modelViewMatrix * vec4( moduloPosition, 1.0 );
24 |
25 | gl_PointSize = size * ( uRange / (length( mvPosition.xyz ) + 1.0) );
26 |
27 | float flicker = mix(0.6, 1.0, snoise3( moduloPosition + elapsed * 0.0001 ));
28 |
29 | vAlpha = 0.5 * min(1.0, max(0.0,
30 | 1.0 - (length( mvPosition.xyz ) / uRange)
31 | )) * flicker;
32 |
33 | gl_Position = projectionMatrix * mvPosition;
34 |
35 | }
--------------------------------------------------------------------------------
/js/components/cameras/Camera.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | var Camera = function( properties, scene, poemEmitter ) {
4 |
5 | var config = _.extend({
6 | fov : 50,
7 | near : 3,
8 | far : 10000,
9 | aspectRatio : window.innerWidth / window.innerHeight
10 | }, properties);
11 |
12 | this.object = new THREE.PerspectiveCamera(
13 | config.fov,
14 | config.aspect,
15 | config.near,
16 | config.far
17 | );
18 |
19 | this.object.position.x = _.isNumber( properties.x ) ? properties.x : 0;
20 | this.object.position.y = _.isNumber( properties.y ) ? properties.y : 0;
21 | this.object.position.z = _.isNumber( properties.z ) ? properties.z : 500;
22 |
23 | scene.add( this.object );
24 |
25 | poemEmitter.on( 'resize', this.resize.bind(this) );
26 |
27 | };
28 |
29 | module.exports = Camera;
30 |
31 | Camera.prototype = {
32 |
33 | resize : function() {
34 | this.object.aspect = window.innerWidth / window.innerHeight;
35 | this.object.updateProjectionMatrix();
36 | },
37 |
38 | setAndUpdateFov : function( fov ) {
39 | this.object.fov = fov
40 | this.object.updateProjectionMatrix()
41 | }
42 | };
--------------------------------------------------------------------------------
/js/components/cameras/ConstantMove.js:
--------------------------------------------------------------------------------
1 | function updateCamera( position, movement ) {
2 |
3 | var changeMovement = new THREE.Vector3();
4 |
5 | return function(e) {
6 |
7 | changeMovement
8 | .copy( movement )
9 | .multiplyScalar(e.unitDt);
10 |
11 | position.add( changeMovement );
12 |
13 | };
14 | }
15 |
16 | var ConstantMove = function( poem, properties ) {
17 |
18 | var config = _.extend({
19 | x : 0,
20 | y : 0,
21 | z : 0
22 | }, properties);
23 |
24 | var movement = new THREE.Vector3( config.x, config.y, config.z );
25 |
26 | poem.emitter.on('update', updateCamera( poem.camera.object.position, movement));
27 | };
28 |
29 | module.exports = ConstantMove;
--------------------------------------------------------------------------------
/js/components/cameras/Controls.js:
--------------------------------------------------------------------------------
1 | var OrbitControls = require('../../vendor/OrbitControls');
2 |
3 | var Controls = function( poem, properties ) {
4 |
5 | this.poem = poem;
6 | this.properties = properties;
7 |
8 | this.controls = new OrbitControls( this.poem.camera.object, this.poem.canvas );
9 |
10 | _.extend( this.controls, properties );
11 |
12 | this.poem.emitter.on( 'update', this.controls.update.bind( this.controls ) );
13 |
14 | };
15 |
16 | module.exports = Controls;
17 |
--------------------------------------------------------------------------------
/js/components/cameras/Orientation.js:
--------------------------------------------------------------------------------
1 | var OrbitControls = require('../../vendor/OrbitControls');
2 | var DeviceOrientationControls = require('../../vendor/DeviceOrientationControls');
3 | var _e;
4 |
5 | $(window).one( 'deviceorientation', function( e ) {
6 | _e = e;
7 | });
8 |
9 |
10 | var Orientation = function( poem ) {
11 |
12 | this.poem = poem;
13 | this.camera = this.poem.camera.object;
14 |
15 | this.controls = new OrbitControls( this.camera, this.poem.canvas );
16 | this.controls.rotateUp(Math.PI / 4);
17 | this.controls.target.set(
18 | this.camera.position.x + 0.1,
19 | this.camera.position.y,
20 | this.camera.position.z
21 | );
22 | this.controls.noZoom = true;
23 | this.controls.noPan = true;
24 |
25 | this.deviceOrientationHandler = this.setOrientationControls.bind(this);
26 |
27 | $(window).on( 'deviceorientation', this.deviceOrientationHandler );
28 |
29 | this.poem.emitter.on( 'update', this.update.bind(this) );
30 | this.poem.emitter.on( 'destroy', this.destroy.bind(this) );
31 |
32 | if( _e ) this.setOrientationControls( _e );
33 |
34 | };
35 |
36 | module.exports = Orientation;
37 |
38 | Orientation.prototype = {
39 |
40 | setOrientationControls : function( e ) {
41 | // if( !e.originalEvent.alpha ) {
42 | // return;
43 | // }
44 |
45 | this.controls = new DeviceOrientationControls( this.camera, true );
46 | this.controls.connect();
47 | this.controls.update();
48 |
49 | $(window).off( 'deviceorientation', this.deviceOrientationHandler );
50 | },
51 |
52 | update : function( e ) {
53 | this.controls.update();
54 | },
55 |
56 | destroy : function( e ) {
57 | $(window).off( 'deviceorientation', this.deviceOrientationHandler );
58 | }
59 |
60 | };
--------------------------------------------------------------------------------
/js/components/cameras/RotateAroundOrigin.js:
--------------------------------------------------------------------------------
1 | var RotateAroundOrigin = function( poem ) {
2 |
3 | var camera = poem.camera.object;
4 | var speed = 0.00005;
5 | var baseY = camera.position.y;
6 | var baseZ = camera.position.z / 2;
7 |
8 | poem.emitter.on('update', function( e ) {
9 |
10 | poem.grid.grid.rotation.y += e.dt * speed;
11 | if( poem.pointcloud.object ) {
12 | poem.pointcloud.object.rotation.y += e.dt * speed;
13 | }
14 |
15 | camera.position.y = baseY + Math.sin( e.now * speed * 10 ) * 200;
16 | camera.position.z = baseY + Math.sin( e.now * speed * 10 ) * baseZ;
17 |
18 |
19 | });
20 |
21 | };
22 |
23 | module.exports = RotateAroundOrigin;
24 |
25 | RotateAroundOrigin.prototype = {
26 |
27 | };
--------------------------------------------------------------------------------
/js/components/cameras/Swivel.js:
--------------------------------------------------------------------------------
1 | function mouseMove( prevXY, quaternion, speedX, speedY ) {
2 |
3 | var axisX = new THREE.Vector3(1,0,0);
4 | var axisY = new THREE.Vector3(0,1,0);
5 |
6 | var q1 = new THREE.Quaternion();
7 | var q2 = new THREE.Quaternion();
8 |
9 | var rotationX = 0;
10 | var rotationY = 0;
11 |
12 | return function( e ) {
13 |
14 | e.preventDefault();
15 |
16 | var x = e.pageX;
17 | var y = e.pageY;
18 |
19 | var offsetX = prevXY.x - x;
20 | var offsetY = prevXY.y - y;
21 |
22 | rotationY += offsetX * speedX;
23 | rotationX += offsetY * speedY;
24 |
25 | rotationX = Math.min( rotationX, Math.PI * 0.45 );
26 | rotationX = Math.max( rotationX, -Math.PI * 0.45 );
27 |
28 | q1.setFromAxisAngle( axisY, rotationY );
29 | q2.setFromAxisAngle( axisX, rotationX );
30 | quaternion.multiplyQuaternions( q1, q2 );
31 |
32 |
33 | prevXY.x = x;
34 | prevXY.y = y;
35 |
36 | };
37 | }
38 |
39 | function mouseUp( $canvas, handlers ) {
40 |
41 | return function() {
42 | $canvas.off('mouseleave', handlers.mouseUp);
43 | $canvas.off('mouseup', handlers.mouseUp);
44 | $canvas.off('mousemove', handlers.mouseMove);
45 | };
46 | }
47 |
48 | function mouseDown( $canvas, handlers, prevXY ) {
49 |
50 | return function( e ) {
51 | e.preventDefault();
52 |
53 | prevXY.x = e.pageX;
54 | prevXY.y = e.pageY;
55 |
56 | $canvas.on('mouseleave', handlers.mouseUp );
57 | $canvas.on('mouseup', handlers.mouseUp );
58 | $canvas.on('mousemove', handlers.mouseMove );
59 | };
60 | }
61 |
62 | function stopHandlers( $canvas, handlers ) {
63 |
64 | return function() {
65 | $canvas.off('mouseleave', handlers.mouseUp);
66 | $canvas.off('mouseup', handlers.mouseUp);
67 | $canvas.off('mousemove', handlers.mouseMove);
68 | $canvas.off('mousedown', handlers.mouseDown);
69 | };
70 | }
71 |
72 | function startMouseHandlers( canvas, cameraObj, poem, speedX, speedY ) {
73 |
74 | var prevXY = {x:0,y:0};
75 | var $canvas = $(canvas);
76 | var handlers = {};
77 | var quaternion = new THREE.Quaternion().copy( cameraObj.quaternion );
78 |
79 | handlers.mouseMove = mouseMove( prevXY, quaternion, speedX, speedY );
80 | handlers.mouseUp = mouseUp( $canvas, handlers );
81 | handlers.mouseDown = mouseDown( $canvas, handlers, prevXY );
82 |
83 | $canvas.on('mousedown', handlers.mouseDown);
84 | poem.emitter.on('destroy', stopHandlers( $canvas, handlers ) );
85 |
86 | return quaternion;
87 | }
88 |
89 | function updateCamera( cameraQuaternion, targetQuaternion, unitI ) {
90 |
91 | return function( e ) {
92 |
93 | cameraQuaternion.slerp( targetQuaternion, unitI * e.unitDt );
94 |
95 | };
96 | }
97 |
98 | var Swivel = function( poem, properties ) {
99 |
100 | var config = _.extend({
101 | easing : 0.5,
102 | speedX : 0.002,
103 | speedY : 0.002
104 | }, properties);
105 |
106 | var targetQuaternion = startMouseHandlers(
107 | poem.canvas,
108 | poem.camera.object,
109 | poem,
110 | config.speedX, config.speedY
111 | );
112 |
113 | poem.emitter.on('update', updateCamera( poem.camera.object.quaternion, targetQuaternion, config.easing ) );
114 |
115 | };
116 |
117 | module.exports = Swivel;
--------------------------------------------------------------------------------
/js/components/cameras/Trackball.js:
--------------------------------------------------------------------------------
1 | var Trackball = require('../../vendor/TrackballControls');
2 |
3 | var Controls = function( poem, properties ) {
4 |
5 | this.poem = poem;
6 | this.properties = properties;
7 |
8 | this.controls = new Trackball( this.poem.camera.object, this.poem.canvas );
9 |
10 | _.extend( this.controls, properties );
11 |
12 | this.poem.emitter.on( 'update', this.controls.update.bind( this.controls ) );
13 |
14 | };
15 |
16 | module.exports = Controls;
17 |
--------------------------------------------------------------------------------
/js/components/fbo-positioning/fbo-position.shader:
--------------------------------------------------------------------------------
1 | uniform float textureSideLength;
2 |
3 | uniform sampler2D textureCurrPosition;
4 | uniform sampler2D texturePrevPosition;
5 |
6 |
7 | void main() {
8 |
9 | vec2 uv = gl_FragCoord.xy / textureSideLength;
10 | vec4 currPosition = texture2D( textureCurrPosition, uv );
11 | vec4 prevPosition = texture2D( texturePrevPosition, uv );
12 |
13 | vec3 velocity = currPosition.xyz - prevPosition.xyz;
14 | vec3 toOrigin = normalize(-1.0 * currPosition.xyz);
15 | vec3 orientation = normalize( velocity );
16 | vec3 newOrientation = normalize( mix( toOrigin, orientation, 0.93 ) );
17 | newOrientation += vec3(0.0001, 0.0001, 0.0001);
18 | float velocityLength = length( velocity );
19 | float toOriginLength = length( currPosition.xyz );
20 |
21 | gl_FragColor = vec4(
22 | currPosition.xyz + newOrientation * 0.02,
23 | 1.0
24 | );
25 | }
--------------------------------------------------------------------------------
/js/components/fbo-positioning/fbo-render.frag:
--------------------------------------------------------------------------------
1 | varying float vLighting;
2 | varying float vAttributeIndex;
3 |
4 | #pragma glslify: hsl2rgb = require(glsl-hsl2rgb)
5 |
6 | void main() {
7 |
8 | gl_FragColor = vec4(
9 | hsl2rgb( mod(0.5 + vAttributeIndex * 0.000002, 1.0), 0.8, 0.5 ),
10 | 1.0
11 | ) * vLighting;
12 | }
--------------------------------------------------------------------------------
/js/components/fbo-positioning/fbo-render.vert:
--------------------------------------------------------------------------------
1 | uniform float elapsed;
2 |
3 | uniform float textureSideLength;
4 | uniform sampler2D textureCurrPosition;
5 | uniform sampler2D texturePrevPosition;
6 |
7 | attribute float attributeIndex;
8 |
9 | varying float vLighting;
10 | varying float vAttributeIndex;
11 |
12 | void main() {
13 |
14 | vec2 positionLookup = vec2(
15 | mod(attributeIndex, textureSideLength),
16 | floor(attributeIndex / textureSideLength)
17 | ) / textureSideLength;
18 |
19 | vec3 currPosition = texture2D( textureCurrPosition, positionLookup ).xyz;
20 | vec3 prevPosition = texture2D( texturePrevPosition, positionLookup ).xyz;
21 |
22 | float theta = log(attributeIndex) * 8.0;
23 | float r = attributeIndex * 2.0;
24 |
25 | vec4 offset = vec4( r * sin(theta), r * cos(theta), 0.0, 0.0 );
26 |
27 | vLighting = dot( normal, normalize(cameraPosition - position) );
28 | vLighting = vLighting * 0.5 + 0.5;
29 |
30 | vAttributeIndex = attributeIndex;
31 |
32 | gl_Position =
33 | projectionMatrix *
34 | modelViewMatrix * (
35 | vec4( position, 1.0 ) + offset * 0.0 + vec4( currPosition * 100.0, 0 )
36 | );
37 | }
--------------------------------------------------------------------------------
/js/components/hids/mouse-tracker.js:
--------------------------------------------------------------------------------
1 | var Touches = require('touches')
2 | var EventEmitter = require('events').EventEmitter
3 |
4 | module.exports = function createMouseTracker( poem, config ) {
5 |
6 | var pixelPosition = new THREE.Vector2()
7 | var normalizedPosition = new THREE.Vector2()
8 |
9 | var savePosition = function(e, position) {
10 | e.preventDefault()
11 |
12 | normalizedPosition.x = 2 * (position[0] / poem.canvas.offsetWidth) - 1
13 | normalizedPosition.y = -2 * (position[1] / poem.canvas.offsetHeight) + 1
14 |
15 | pixelPosition.x = position[0]
16 | pixelPosition.y = position[1]
17 | }
18 |
19 | var emitter = Touches( poem.canvas, { filtered: true })
20 |
21 | .on('start', savePosition )
22 |
23 | .on('move', savePosition)
24 |
25 | .on('end', function(e) {
26 | pixelPosition.x = null
27 | pixelPosition.y = null
28 | normalizedPosition.x = null
29 | normalizedPosition.y = null
30 | })
31 |
32 | poem.emitter.on('destroy', function() {
33 | emitter.disable()
34 | })
35 |
36 | return {
37 | emitter : emitter
38 | , pixelPosition : pixelPosition
39 | , normalizedPosition : normalizedPosition
40 | }
41 | }
--------------------------------------------------------------------------------
/js/components/lights/TrackCameraLights.js:
--------------------------------------------------------------------------------
1 | var TrackCameraLights = function( poem, properties ) {
2 |
3 | this.lights = [];
4 |
5 | var ambient = new THREE.AmbientLight( 0x111111, 1, 0 );
6 | ambient.position.set(0, 2000, 1000);
7 |
8 | var front = new THREE.PointLight( 0xffffff, 0.3, 0 );
9 |
10 | var rightFill = new THREE.PointLight( 0xffffff, 1, 0 );
11 | rightFill.position.set(3000, 2000, 5000);
12 |
13 | var rimBottom = new THREE.PointLight( 0xffffff, 1, 0 );
14 | rimBottom.position.set(-1000, -1000, -1000);
15 |
16 | var rimBackLeft = new THREE.PointLight( 0xffffff, 2, 0 );
17 | rimBackLeft.position.set(-700, 500, -1000);
18 |
19 | poem.scene.add( ambient );
20 | // poem.camera.object.add( front );
21 | poem.camera.object.add( rightFill );
22 | poem.camera.object.add( rimBottom );
23 | poem.camera.object.add( rimBackLeft );
24 |
25 | };
26 |
27 | module.exports = TrackCameraLights;
28 |
29 | TrackCameraLights.prototype = {
30 |
31 | };
--------------------------------------------------------------------------------
/js/components/models/tree.js:
--------------------------------------------------------------------------------
1 | var AssimpJSONLoader = require('../../vendor/AssimpJSONLoader')
2 |
3 | var statics = {
4 | tree : null
5 | }
6 |
7 | function _loadTreePromise() {
8 |
9 | return new Promise(function( resolve, reject ) {
10 |
11 | if( statics.tree ) {
12 | resolve( statics.tree )
13 | return
14 | }
15 |
16 | var loader = new THREE.AssimpJSONLoader();
17 |
18 | var doneLoading = function ( object ) {
19 | _updateMaterials( object )
20 | statics.tree = object
21 | resolve( object )
22 | }
23 | var onProgress = function() {}
24 |
25 | loader.load(
26 | './js/components/models/tree.json',
27 | doneLoading,
28 | onProgress,
29 | reject
30 | );
31 | })
32 | }
33 |
34 | function _updateMaterials( obj ) {
35 |
36 | if( obj.material ) {
37 | obj.material.side = THREE.DoubleSide
38 | obj.material.shading = THREE.SmoothShading
39 | obj.material.specular = new THREE.Color(0x555555)
40 | obj.material.shininess = 1
41 | }
42 |
43 | for( var i=0; i < obj.children.length; i++ ) {
44 | _updateMaterials( obj.children[i] )
45 | }
46 | }
47 |
48 | module.exports = function createTree( poem, props ) {
49 |
50 | var config = _.extend({
51 | position: [0,0,0],
52 | scale: [10,10,10],
53 | }, props)
54 |
55 | var geometry = new THREE.SphereGeometry( 20, 32, 32 );
56 | var material = new THREE.MeshPhongMaterial( {color: 0xffff00} );
57 | var sphere = new THREE.Mesh( geometry, material );
58 | sphere.position.x = 20
59 | poem.scene.add( sphere );
60 |
61 | return _loadTreePromise().then(function( tree ) {
62 |
63 | poem.scene.add( tree )
64 | tree.position.fromArray( config.position )
65 | tree.scale.fromArray( config.scale )
66 |
67 | window.tree = tree.children[0].children[0]
68 |
69 | return tree
70 | })
71 | }
--------------------------------------------------------------------------------
/js/components/sound/Music.js:
--------------------------------------------------------------------------------
1 | var soundcloud = require('soundcloud-badge');
2 |
3 | var Music = function( poem, properties ) {
4 |
5 | if(window.location.hash === "#musicoff") return;
6 |
7 | var audio;
8 | var alive = true;
9 |
10 | soundcloud({
11 | client_id: '6057c9af862bf245d4c402179e317f52',
12 | song: properties.url,
13 | dark: false,
14 | getFonts: false
15 | }, function(err, src, data, div) {
16 |
17 | if( !alive ) return;
18 | if( err ) throw err;
19 |
20 | audio = new Audio();
21 | audio.src = src;
22 | audio.play();
23 | audio.loop = true;
24 | audio.volume = properties.volume || 0.6;
25 |
26 | $(audio).on('loadedmetadata', function() {
27 | audio.currentTime = properties.startTime || 0;
28 | });
29 |
30 | var playing = true;
31 |
32 | $(window).on('keydown.Music', function(e) {
33 | if( e.keyCode !== 83 ) return;
34 | if( playing ) {
35 | audio.pause();
36 | playing = false;
37 | } else {
38 | audio.play();
39 | playing = true;
40 | }
41 | });
42 | });
43 |
44 | poem.emitter.on('destroy', function() {
45 | if(audio) {
46 | audio.pause();
47 | audio = null;
48 | }
49 | $(window).off('keydown.Music');
50 | $('.npm-scb-white').remove();
51 | });
52 |
53 | };
54 |
55 | module.exports = Music;
56 |
--------------------------------------------------------------------------------
/js/components/utils/Stats.js:
--------------------------------------------------------------------------------
1 | var MrDoobStats = require('../../vendor/Stats');
2 |
3 | var Stats = function( poem ) {
4 |
5 | this.poem = poem;
6 |
7 | this.stats = new MrDoobStats();
8 | this.stats.domElement.style.position = 'absolute';
9 | this.stats.domElement.style.top = '0px';
10 | $( this.poem.div ).append( this.stats.domElement );
11 |
12 | this.poem.emitter.on( 'update', this.stats.update.bind( this.stats ) );
13 |
14 | };
15 |
16 | module.exports = Stats;
--------------------------------------------------------------------------------
/js/components/utils/drag-scroll.js:
--------------------------------------------------------------------------------
1 | var Lerp = require('lerp')
2 |
3 | function _getWheelEventName() {
4 |
5 | if( "onwheel" in document.createElement("div") ) {
6 | return "wheel"
7 | } else if( document.onmousewheel !== undefined ) {
8 | return "mousewheel"
9 | } else {
10 | return "DOMMouseScroll"
11 | }
12 | }
13 |
14 | module.exports = function dragScroll( poem, properties ) {
15 |
16 | var config = _.extend({
17 | distance : 0.1,
18 | resetSpeed : 0.05,
19 | center : poem.camera.object.position.clone()
20 | }, properties)
21 |
22 | var current = {
23 | center : config.center.clone()
24 | }
25 |
26 | poem.canvas.addEventListener( _getWheelEventName(), function handleMouseWheel(e) {
27 | current.center.y += config.distance * -e.deltaY
28 | current.center.x += config.distance * e.deltaX * 5
29 |
30 | }, false );
31 |
32 | poem.emitter.on('update', function updateDragScroll() {
33 | current.center.y = Lerp(
34 | current.center.y,
35 | config.center.y,
36 | config.resetSpeed
37 | )
38 | current.center.x = Lerp(
39 | current.center.x,
40 | config.center.x,
41 | config.resetSpeed
42 | )
43 | current.center.z = Lerp(
44 | current.center.z,
45 | config.center.z,
46 | config.resetSpeed
47 | )
48 |
49 | poem.camera.object.position.copy( current.center )
50 | })
51 | }
--------------------------------------------------------------------------------
/js/core/manifestToPoem.js:
--------------------------------------------------------------------------------
1 | var createManifestLoader = require('poem-manifests');
2 | var EventEmitter = require('events').EventEmitter;
3 |
4 | var _emitter = new EventEmitter();
5 | var _loader = null;
6 |
7 | var init = function( createPoemGraph, manifests ) {
8 |
9 | _loader = createManifestLoader( manifests, {
10 | emitter : _emitter,
11 | getGraph : function( manifest, slug ) { return createPoemGraph( manifest, _emitter ); },
12 | globalManifest : {}
13 | });
14 |
15 | _emitter.on('load', function( e ) {
16 | window.poem = e.graph;
17 | });
18 |
19 | };
20 |
21 | var load = function( slug ) {
22 | return _loader.load( slug );
23 | };
24 |
25 | module.exports = {
26 | init : init,
27 | load : load,
28 | emitter : _emitter
29 | };
30 |
--------------------------------------------------------------------------------
/js/core/poem.js:
--------------------------------------------------------------------------------
1 | var Camera = require('../components/cameras/Camera')
2 | var CreateLoop = require('poem-loop')
3 |
4 | const RATIO = _.isNumber( window.devicePixelRatio ) ? window.devicePixelRatio : 1
5 |
6 | function _createFog( scene, properties, cameraPositionZ ) {
7 |
8 | var config = _.extend({
9 | color : 0x222222,
10 | nearFactor : 0.5,
11 | farFactor : 2
12 | }, properties )
13 |
14 | scene.fog = new THREE.Fog(
15 | config.color,
16 | cameraPositionZ * config.nearFactor,
17 | cameraPositionZ * config.farFactor
18 | )
19 |
20 | }
21 |
22 | function _startAfterPromises( poem ) {
23 |
24 | var promisesUnfiltered = _.map( poem, function( component ) {
25 | return _.isObject( component ) ? component.promise : undefined
26 | })
27 | var promises = _.filter(promisesUnfiltered, function( component ) {
28 | return !_.isUndefined( component )
29 | })
30 |
31 | Promise.all( promises ).then(
32 | function() {
33 | poem.emitter.emit('promises')
34 | poem.loop.start()
35 | },
36 | console.log.bind(console)
37 | )
38 | }
39 |
40 | module.exports = function createPoem( manifest, loaderEmitter ) {
41 |
42 | var config = _.extend({
43 | camera : null,
44 | fog : null,
45 | renderer : null
46 | }, manifest.config)
47 |
48 | var poem = {}
49 | var loop = CreateLoop()
50 | var emitter = loop.emitter // Steal the emitter for the poem
51 |
52 | var scene = new THREE.Scene()
53 | var camera = new Camera( config.camera, scene, emitter )
54 |
55 | _createFog( scene, config.fog, camera.object.position.z )
56 |
57 | // Renderer( config.renderer, scene, camera.object, emitter )
58 |
59 | loaderEmitter.once( 'load', _.partial( _startAfterPromises, poem ) )
60 |
61 | loaderEmitter.on( 'unload', function() {
62 | loop.stop()
63 | emitter.emit('destroy')
64 | })
65 |
66 | return _.extend( poem, {
67 | emitter : emitter,
68 | canvas : null,
69 | scene : scene,
70 | ratio : RATIO,
71 | camera : camera,
72 | $div : $("#container"),
73 | loop : loop,
74 | start : loop.start,
75 | stop : loop.stop
76 | })
77 | }
--------------------------------------------------------------------------------
/js/core/routing.js:
--------------------------------------------------------------------------------
1 | var crossroads = require('crossroads');
2 | var hasher = require('hasher');
3 | var manifestToPoem = require('./manifestToPoem');
4 |
5 | var _baseUrl = '/sandbox';
6 | var _defaultLevel
7 |
8 | var routing = {
9 |
10 | start : function( Poem, manifests ) {
11 |
12 | _defaultLevel = _.first( _.keys( manifests ) )
13 |
14 | manifestToPoem.init( Poem, manifests );
15 |
16 | function parseHash( newHash, oldHash ){
17 | crossroads.parse( newHash );
18 | }
19 |
20 | crossroads.addRoute( '/', routing.showMainTitles );
21 | crossroads.addRoute( '/{name}', routing.loadUpALevel );
22 |
23 | crossroads.addRoute( /.*/, function reRouteToMainTitlesIfNoMatch() {
24 | hasher.replaceHash('');
25 | });
26 |
27 | hasher.initialized.add(parseHash); // parse initial hash
28 | hasher.changed.add(parseHash); //parse hash changes
29 | hasher.init(); //start listening for history change
30 |
31 | },
32 |
33 | showMainTitles : function() {
34 |
35 | _gaq.push( [ '_trackPageview', _baseUrl ] );
36 |
37 | manifestToPoem.load( _defaultLevel );
38 |
39 | },
40 |
41 | loadUpALevel : function( levelName ) {
42 |
43 | _gaq.push( [ '_trackPageview', _baseUrl+'/#level/'+levelName ] );
44 |
45 | var levelFound = manifestToPoem.load( levelName );
46 |
47 | if( !levelFound ) {
48 | manifestToPoem.load( _defaultLevel );
49 | }
50 |
51 | }
52 |
53 | };
54 |
55 | module.exports = routing;
--------------------------------------------------------------------------------
/js/core/ui.js:
--------------------------------------------------------------------------------
1 | var poemMenu = require('poem-menu');
2 | var routing = require('./routing');
3 | var mute = require('../sound/mute');
4 | var manifestToPoem = require('./manifestToPoem');
5 |
6 | window.mute = mute;
7 |
8 | function handlers( menu ) {
9 |
10 | var poem;
11 |
12 | manifestToPoem.emitter.on( 'load', function( e ) {
13 | poem = e.graph;
14 | });
15 |
16 | menu.emitter.on('close', function() {
17 | if( poem ) poem.start();
18 | });
19 |
20 | menu.emitter.on('open', function() {
21 | if( poem ) poem.stop();
22 | });
23 |
24 | }
25 |
26 | //Start
27 |
28 | module.exports = function startUI( manifests ) {
29 |
30 | var menu = poemMenu( manifests, {
31 | top: "Three.js Sandbox",
32 | bottom : mute.el
33 | });
34 |
35 | handlers( menu );
36 |
37 | };
--------------------------------------------------------------------------------
/js/demos/EndlessTerrain/credits.js:
--------------------------------------------------------------------------------
1 | var LoadImage = require('../../utils/loadImage')
2 |
3 | var internals = {
4 |
5 | createTexture : function( video ) {
6 |
7 | var canvas = document.createElement( 'canvas' )
8 | canvas.width = 1024
9 | canvas.height = 256
10 |
11 | var ctx2d = canvas.getContext( '2d' )
12 |
13 | var texture = new THREE.Texture( canvas )
14 | texture.minFilter = THREE.LinearFilter
15 | texture.magFilter = THREE.LinearFilter
16 |
17 | return [ canvas, ctx2d, texture ]
18 | },
19 |
20 | createVideo : function() {
21 |
22 | return new Promise(function( resolve, reject ) {
23 |
24 | var video = document.createElement( 'video' )
25 | var $video = $(video)
26 |
27 | // video.muted = true
28 | video.controls = false
29 | video.loop = false
30 |
31 | video.src = video.canPlayType("video/mp4") ?
32 | "assets/video/gene.sys.mp4" :
33 | "assets/video/gene.sys.webm"
34 |
35 | video.load()
36 |
37 | $(video).on('canplaythrough', () => { resolve( video ) })
38 | $(video).on('error, stalled, abort', (e) => { reject( e.originalEvent ) })
39 | })
40 |
41 | },
42 |
43 | createMesh : function( poem, texture, canvas ) {
44 |
45 | var mesh = new THREE.Mesh(
46 | new THREE.PlaneGeometry( canvas.width, canvas.height ),
47 | new THREE.MeshBasicMaterial({
48 | color: 0xffffff
49 | , transparent: true
50 | , side: THREE.DoubleSide
51 | // , map: texture
52 | , alphaMap: texture
53 | })
54 | )
55 | return mesh
56 | },
57 |
58 | updateFn : function( mesh, ctx2d, video, texture ) {
59 |
60 | return function() {
61 |
62 | if ( video.readyState === video.HAVE_ENOUGH_DATA && video.ended === false ) {
63 |
64 | ctx2d.drawImage( video, 0, 0 )
65 | texture.needsUpdate = true
66 | }
67 | }
68 | },
69 |
70 | add : ( cameraObj, mesh, video, update ) => {
71 |
72 | mesh.scale.set(0.005, 0.005, 0.005)
73 | mesh.position.z = -10
74 | mesh.position.y = 0.2
75 | cameraObj.add( mesh )
76 |
77 | setTimeout(function() {
78 | console.warn('TODO: remove setTimeout')
79 | video.currentTime = 0
80 | video.play()
81 |
82 | poem.emitter.on( 'update', update )
83 |
84 | }, 2000)
85 | },
86 |
87 | remove : ( cameraObj, mesh, video, update ) => {
88 |
89 | cameraObj.remove( mesh )
90 | video.pause(0)
91 |
92 |
93 | poem.emitter.removeListener( 'update', update )
94 | }
95 |
96 | }
97 |
98 | module.exports = function( poem ) {
99 |
100 | var api = {
101 | promise : internals.createVideo()
102 | }
103 |
104 | api.promise.then( function( video ) {
105 |
106 | var [ canvas, ctx2d, texture ] = internals.createTexture( video )
107 | var mesh = internals.createMesh( poem, texture, canvas )
108 |
109 | var update = internals.updateFn( mesh, ctx2d, video, texture )
110 |
111 | _.extend( api, {
112 | mesh : mesh
113 | , canvas : canvas
114 | , ctx2d : ctx2d
115 | , texture : texture
116 | , video : video
117 | , add : _.partial( internals.add, poem.camera.object, mesh, video, update )
118 | , remove : _.partial( internals.remove, poem.camera.object, mesh, video, update )
119 | })
120 | })
121 |
122 | return api
123 | }
--------------------------------------------------------------------------------
/js/demos/EndlessTerrain/endless.frag:
--------------------------------------------------------------------------------
1 | #pragma glslify: hsv2rgb = require(glsl-hsv2rgb)
2 | uniform float width;
3 | uniform float heightFactor;
4 |
5 | varying float height;
6 | varying vec2 vUv;
7 | varying float vCameraDistance;
8 |
9 | void main() {
10 |
11 | float hueX = abs(0.5 - fract(vUv.x * 0.8)) * 2.0;
12 | float hueY = abs(0.5 - fract(vUv.y * 0.63)) * 2.0;
13 |
14 | gl_FragColor = vec4(
15 | hsv2rgb(
16 | vec3(
17 | // mod(xHue, 1.0),
18 | (hueX + hueY) * 0.2 + 0.3,
19 | mix(heightFactor, mix(height, 0.5, 0.8), 0.8),
20 | mix(heightFactor, mix(height, 1.2, 0.35), 0.35)
21 | )
22 | ),
23 | 1.0
24 | );
25 |
26 | float fogFactor = smoothstep( 0.0, 1.0, vCameraDistance / width );
27 | vec3 fogColor = vec3( 0.14, 0.14, 0.14 );
28 |
29 | gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );
30 |
31 | }
--------------------------------------------------------------------------------
/js/demos/EndlessTerrain/endless.vert:
--------------------------------------------------------------------------------
1 | uniform sampler2D terrain;
2 | uniform float heightFactor;
3 | uniform float width;
4 |
5 | varying float height;
6 | varying vec2 vUv;
7 | varying float vCameraDistance;
8 |
9 | void main() {
10 |
11 | vec4 modelPosition = modelMatrix * vec4(position, 1.0);
12 |
13 | vUv = vec2( modelPosition.x, modelPosition.z ) / width;
14 |
15 | height = texture2D( terrain, vUv * 0.3 ).w;
16 |
17 | vCameraDistance = distance( modelPosition.xyz, cameraPosition );
18 |
19 |
20 | vec4 modifiedPosition = vec4(
21 | position.x,
22 | position.y + height * width / 20.0 * heightFactor,
23 | position.z,
24 | 1.0
25 | );
26 |
27 | gl_Position = projectionMatrix * modelViewMatrix * modifiedPosition;
28 |
29 | }
--------------------------------------------------------------------------------
/js/demos/EndlessTerrain/keyframes.js:
--------------------------------------------------------------------------------
1 | var CubicBezier = require('cubic-bezier')
2 | var QuickIn = CubicBezier(.12,.51,.8,.85, 32)
3 | var Pi = Math.PI
4 | var HalfPi = Math.PI / 2
5 |
6 | module.exports = {
7 | loop : true,
8 | speed : 1,
9 | keyframes : [
10 | {
11 | duration: 15,
12 | easing: QuickIn,
13 | actions: [
14 | [ "camera.object.position.x", [ 0, 0 ] ],
15 | [ "camera.object.position.y", [ -250, 0 ] ],
16 | [ "camera.object.position.z", [ 0, -5000 ] ],
17 | [ "camera.setAndUpdateFov", [ 5, 30 ] ],
18 | [ "endlessTerrain.height", [ 0, 1 ] ],
19 | [ "restrictedCamera.rotation.x", [ -0.3, 0 ] ],
20 | [ "restrictedCamera.rotation.y", [ -0.3, 0.1 ] ],
21 |
22 | [ "restrictedCamera.rotateAll", { x:-0.3, y:-0.3, z:0 }],
23 |
24 | [ "credits.mesh.position.z", [ -30, -10 ] ],
25 | [ "credits.add", {} ]
26 |
27 | ]
28 | },
29 | {
30 | duration: 10,
31 | easing: "linear",
32 | isolate: false,
33 | startHere: false,
34 | actions: [
35 | [ "credits.remove", {} ],
36 |
37 | [ "camera.object.position.x", [ 0, 0 ] ],
38 | [ "camera.object.position.y", [ 0, 0 ] ],
39 | [ "camera.object.position.z", [ -5000, -5700 ] ],
40 | [ "camera.setAndUpdateFov", [ 70, 40 ] ],
41 |
42 | [ "restrictedCamera.rotateAll", { x:-0.1, y:HalfPi, z: 0 }]
43 | ]
44 | },
45 | {
46 | duration: 13,
47 | easing: "linear",
48 | isolate: false,
49 | actions: [
50 | [ "camera.object.position.x", 600 ],
51 | [ "camera.object.position.y", [ 0, 0 ] ],
52 | [ "camera.object.position.z", [ -5700, -6000 ] ],
53 | [ "camera.setAndUpdateFov", [ 100, 50 ] ],
54 |
55 | [ "restrictedCamera.rotateAll", { x:-Pi*0.5, y:0, z: 0 }],
56 |
57 | [ "restrictedCamera.rotation.x", [ -Pi*0.5, 0 ] ]
58 |
59 | ]
60 | },
61 | {
62 | duration: 10,
63 | easing: "linear",
64 | isolate: false,
65 | actions: [
66 | [ "camera.object.position.x", 600 ],
67 | [ "camera.object.position.y", [ 0, 0 ] ],
68 | [ "camera.object.position.z", [ -5700, -6400 ] ],
69 |
70 | [ "restrictedCamera.rotateAll", { x:0, y:Pi, z: 0 }],
71 |
72 | // [ "restrictedCamera.rotation.x", [ -0.2, 0.2 ] ]
73 |
74 | ]
75 | }
76 | ]
77 | }
--------------------------------------------------------------------------------
/js/demos/Grid.js:
--------------------------------------------------------------------------------
1 | var random = require('../utils/random');
2 |
3 | var Grid = function( poem, properties ) {
4 |
5 | this.poem = poem;
6 |
7 | var lineMaterial = new THREE.LineBasicMaterial( { color: 0x303030 } ),
8 | geometry = new THREE.Geometry(),
9 | floor = -75, step = 25;
10 |
11 | for ( var i = 0; i <= 40; i ++ ) {
12 |
13 | geometry.vertices.push( new THREE.Vector3( - 500, floor, i * step - 500 ) );
14 | geometry.vertices.push( new THREE.Vector3( 500, floor, i * step - 500 ) );
15 |
16 | geometry.vertices.push( new THREE.Vector3( i * step - 500, floor, -500 ) );
17 | geometry.vertices.push( new THREE.Vector3( i * step - 500, floor, 500 ) );
18 |
19 | }
20 |
21 | this.grid = new THREE.Line( geometry, lineMaterial, THREE.LinePieces );
22 | this.poem.scene.add( this.grid );
23 |
24 | };
25 |
26 | module.exports = Grid;
--------------------------------------------------------------------------------
/js/demos/MeshGroupBoxDemo/index.js:
--------------------------------------------------------------------------------
1 | var MeshGroup = require('./MeshGroup')
2 | , random = require('../../utils/random')
3 | , twoPi = Math.PI * 2;
4 |
5 | var MeshGroupBoxDemo = function( poem, properties ) {
6 |
7 | this.poem = poem;
8 |
9 | this.count = 10000;
10 |
11 | this.poem.emitter.on('update', this.update.bind(this) );
12 |
13 | this.group = new MeshGroup( poem );
14 |
15 | this.boxes = this.generateBoxes( this.group );
16 |
17 | this.group.build( poem.scene );
18 |
19 | };
20 |
21 | module.exports = MeshGroupBoxDemo;
22 |
23 | MeshGroupBoxDemo.prototype = {
24 |
25 | generateBoxes : function( group ) {
26 |
27 | var boxes = [];
28 |
29 | var geometry = new THREE.BoxGeometry( 1, 1, 1 );
30 | var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
31 | var box;
32 |
33 | var i = this.count; while (i--) {
34 |
35 | box = new THREE.Mesh( new THREE.BoxGeometry( 1, 1, 1 ) );
36 |
37 | box.position.x = random.range( -100, 100 );
38 | box.position.y = random.range( -100, 100 );
39 | box.position.z = random.range( -100, 100 );
40 |
41 | box.rotation.x = random.range( -twoPi, twoPi );
42 | box.rotation.y = random.range( -twoPi, twoPi );
43 | box.rotation.z = random.range( -twoPi, twoPi );
44 |
45 | box.velocity = new THREE.Vector3(
46 |
47 | random.range( -1, 1 ),
48 | random.range( -1, 1 ),
49 | random.range( -1, 1 )
50 |
51 | ).multiplyScalar(0.1);
52 |
53 | box.spin = new THREE.Vector3(
54 |
55 | random.range( -twoPi, twoPi ),
56 | random.range( -twoPi, twoPi ),
57 | random.range( -twoPi, twoPi )
58 |
59 | ).multiplyScalar(0.01);
60 |
61 | box.scale.multiplyScalar( random.range( 1, 2) );
62 |
63 | box.updateMatrix();
64 |
65 | boxes.push( box );
66 |
67 | group.add( box );
68 |
69 | }
70 |
71 | return boxes;
72 |
73 | },
74 |
75 | update : function( e ) {
76 |
77 | var box;
78 |
79 | for( var i = 0; i < this.count; i++ ) {
80 |
81 | box = this.boxes[i];
82 |
83 | box.position.add( box.velocity );
84 |
85 | box.rotation.x += box.spin.x;
86 | box.rotation.y += box.spin.y;
87 | box.rotation.z += box.spin.z;
88 |
89 | box.updateMatrix();
90 |
91 | }
92 |
93 | }
94 |
95 | };
--------------------------------------------------------------------------------
/js/demos/MeshGroupBoxDemo/shader.frag:
--------------------------------------------------------------------------------
1 | uniform sampler2D texture;
2 |
3 | void main() {
4 |
5 | // gl_FragColor = texture2D( texture, gl_PointCoord );
6 |
7 | gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 );
8 |
9 | }
--------------------------------------------------------------------------------
/js/demos/MeshGroupBoxDemo/shader.vert:
--------------------------------------------------------------------------------
1 | attribute float size;
2 | attribute float transformMatrixIndex;
3 |
4 | uniform float time;
5 | uniform sampler2D texture;
6 | uniform sampler2D matricesTexture;
7 | uniform float matricesTextureWidth;
8 |
9 | vec3 wave;
10 |
11 | mat4 getMatrixFromTexture( const in float i ) {
12 |
13 | float j = i * 4.0;
14 | float x = mod( j, float( matricesTextureWidth ) );
15 | float y = floor( j / float( matricesTextureWidth ) );
16 |
17 | float dx = 1.0 / float( matricesTextureWidth );
18 | float dy = 1.0 / float( matricesTextureWidth );
19 |
20 | y = dy * ( y + 0.5 );
21 |
22 | vec4 v1 = texture2D( matricesTexture, vec2( dx * ( x + 0.5 ), y ) );
23 | vec4 v2 = texture2D( matricesTexture, vec2( dx * ( x + 1.5 ), y ) );
24 | vec4 v3 = texture2D( matricesTexture, vec2( dx * ( x + 2.5 ), y ) );
25 | vec4 v4 = texture2D( matricesTexture, vec2( dx * ( x + 3.5 ), y ) );
26 |
27 | return mat4( v1, v2, v3, v4 );
28 |
29 | // Debug:
30 | // return mat4(
31 | // 1.0, 0.0, 0.0, 0.0,
32 | // 0.0, 1.0, 0.0, 0.0,
33 | // 0.0, 0.0, 1.0, 0.0,
34 | // 0.0, 0.0, 0.0, 1.0
35 | // );
36 | }
37 |
38 | void main() {
39 |
40 | mat4 transformMatrix = getMatrixFromTexture( transformMatrixIndex );
41 |
42 | vec4 mvPosition = modelViewMatrix * transformMatrix * vec4( position, 1.0 );
43 |
44 | gl_PointSize = 300.0 / length( mvPosition.xyz );
45 |
46 | gl_Position = projectionMatrix * mvPosition;
47 |
48 | }
--------------------------------------------------------------------------------
/js/demos/TexturePositionalMatrices/shader.frag:
--------------------------------------------------------------------------------
1 | uniform vec3 color;
2 | uniform sampler2D texture;
3 |
4 | varying vec3 vColor;
5 |
6 | void main() {
7 |
8 | gl_FragColor = vec4( color * vColor, 1.0 );
9 |
10 | gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );
11 |
12 | }
--------------------------------------------------------------------------------
/js/demos/TexturePositionalMatrices/shader.vert:
--------------------------------------------------------------------------------
1 | attribute float size;
2 | attribute vec3 customColor;
3 | attribute float transformIndex;
4 |
5 | uniform float time;
6 | uniform sampler2D texture;
7 | uniform sampler2D matricesTexture;
8 | uniform float matricesTextureSize;
9 |
10 | varying vec3 vColor;
11 |
12 | vec3 wave;
13 |
14 | mat4 getMatrixFromTexture( const in float i ) {
15 |
16 | float j = i * 4.0;
17 | float x = mod( j, float( matricesTextureSize ) );
18 | float y = floor( j / float( matricesTextureSize ) );
19 |
20 | float dx = 1.0 / float( matricesTextureSize );
21 | float dy = 1.0 / float( matricesTextureSize );
22 |
23 | y = dy * ( y + 0.5 );
24 |
25 | vec4 v1 = texture2D( matricesTexture, vec2( dx * ( x + 0.5 ), y ) );
26 | vec4 v2 = texture2D( matricesTexture, vec2( dx * ( x + 1.5 ), y ) );
27 | vec4 v3 = texture2D( matricesTexture, vec2( dx * ( x + 2.5 ), y ) );
28 | vec4 v4 = texture2D( matricesTexture, vec2( dx * ( x + 3.5 ), y ) );
29 |
30 | return mat4( v1, v2, v3, v4 );
31 |
32 | }
33 |
34 | void main() {
35 |
36 | vColor = customColor;
37 |
38 | mat4 transformMatrix = getMatrixFromTexture( transformIndex );
39 |
40 | vec4 mvPosition = modelViewMatrix * transformMatrix * vec4( position, 1.0 );
41 |
42 | gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) );
43 |
44 | gl_Position = projectionMatrix * mvPosition;
45 |
46 | }
--------------------------------------------------------------------------------
/js/demos/UniformPositionalMatrices/shader.frag:
--------------------------------------------------------------------------------
1 | uniform vec3 color;
2 | uniform sampler2D texture;
3 |
4 | varying vec3 vColor;
5 |
6 | void main() {
7 |
8 | gl_FragColor = vec4( color * vColor, 1.0 );
9 |
10 | gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );
11 |
12 | }
--------------------------------------------------------------------------------
/js/demos/UniformPositionalMatrices/shader.vert:
--------------------------------------------------------------------------------
1 |
2 | attribute float size;
3 | attribute vec3 customColor;
4 | attribute float transformIndex;
5 |
6 | uniform float time;
7 | uniform mat4 transformMatrix[ TRANSFORM_MATRIX_COUNT ];
8 |
9 | varying vec3 vColor;
10 |
11 | vec3 wave;
12 |
13 | void main() {
14 |
15 | vColor = customColor;
16 |
17 | wave = position;
18 |
19 | wave.y += sin( (position.x / (10.0 + transformIndex) ) + ( time / 150.0 ) ) * 2.0;
20 | wave.y += sin( (position.z / (12.0 + transformIndex) ) + ( time / 160.0 ) ) * 2.0;
21 | wave.y += sin( (position.x / (30.0 + transformIndex) ) + ( time / 120.0 ) ) * 5.0;
22 | wave.y += sin( (position.z / (31.0 + transformIndex) ) + ( time / 130.0 ) ) * 5.0;
23 |
24 | vec4 mvPosition = modelViewMatrix * transformMatrix[ int(transformIndex) ] * vec4( wave, 1.0 );
25 |
26 | gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) );
27 |
28 | gl_Position = projectionMatrix * mvPosition;
29 |
30 | }
--------------------------------------------------------------------------------
/js/demos/sine-gravity-cloud/sine.frag:
--------------------------------------------------------------------------------
1 | uniform vec3 color;
2 | uniform sampler2D texture;
3 |
4 | varying vec3 vColor;
5 |
6 | void main() {
7 |
8 | gl_FragColor = vec4( color * vColor, 1.0 );
9 |
10 | gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );
11 |
12 | }
--------------------------------------------------------------------------------
/js/demos/sine-gravity-cloud/sine.vert:
--------------------------------------------------------------------------------
1 | attribute float size;
2 | attribute vec3 customColor;
3 |
4 | varying vec3 vColor;
5 |
6 | void main() {
7 |
8 | vColor = customColor;
9 |
10 | vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
11 |
12 | gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) );
13 |
14 | gl_Position = projectionMatrix * mvPosition;
15 |
16 | }
--------------------------------------------------------------------------------
/js/demos/wire-terrain/credits.js:
--------------------------------------------------------------------------------
1 | var LoadImage = require('../../utils/loadImage')
2 |
3 | var internals = {
4 |
5 | createTexture : function( video ) {
6 |
7 | var canvas = document.createElement( 'canvas' )
8 | canvas.width = 1024
9 | canvas.height = 256
10 |
11 | var ctx2d = canvas.getContext( '2d' )
12 |
13 | var texture = new THREE.Texture( canvas )
14 | texture.minFilter = THREE.LinearFilter
15 | texture.magFilter = THREE.LinearFilter
16 |
17 | return [ canvas, ctx2d, texture ]
18 | },
19 |
20 | createVideo : function() {
21 |
22 | return new Promise(function( resolve, reject ) {
23 |
24 | var video = document.createElement( 'video' )
25 | var $video = $(video)
26 |
27 | // video.muted = true
28 | video.controls = false
29 | video.loop = false
30 |
31 | video.src = video.canPlayType("video/mp4") ?
32 | "assets/video/gene.sys.mp4" :
33 | "assets/video/gene.sys.webm"
34 |
35 | video.load()
36 |
37 | $(video).on('canplaythrough', () => { resolve( video ) })
38 | $(video).on('error, stalled, abort', (e) => { reject( e.originalEvent ) })
39 | })
40 |
41 | },
42 |
43 | createMesh : function( poem, texture, canvas ) {
44 |
45 | var mesh = new THREE.Mesh(
46 | new THREE.PlaneGeometry( canvas.width, canvas.height ),
47 | new THREE.MeshBasicMaterial({
48 | color: 0xffffff
49 | , transparent: true
50 | , side: THREE.DoubleSide
51 | // , map: texture
52 | , alphaMap: texture
53 | })
54 | )
55 | return mesh
56 | },
57 |
58 | updateFn : function( mesh, ctx2d, video, texture ) {
59 |
60 | return function() {
61 |
62 | if ( video.readyState === video.HAVE_ENOUGH_DATA && video.ended === false ) {
63 |
64 | ctx2d.drawImage( video, 0, 0 )
65 | texture.needsUpdate = true
66 | }
67 | }
68 | },
69 |
70 | add : ( cameraObj, mesh, video, update ) => {
71 |
72 | mesh.scale.set(0.005, 0.005, 0.005)
73 | mesh.position.z = -10
74 | mesh.position.y = 0.2
75 | cameraObj.add( mesh )
76 |
77 | setTimeout(function() {
78 | console.warn('TODO: remove setTimeout')
79 | video.currentTime = 0
80 | video.play()
81 |
82 | poem.emitter.on( 'update', update )
83 |
84 | }, 2000)
85 | },
86 |
87 | remove : ( cameraObj, mesh, video, update ) => {
88 |
89 | cameraObj.remove( mesh )
90 | video.pause(0)
91 |
92 |
93 | poem.emitter.removeListener( 'update', update )
94 | }
95 |
96 | }
97 |
98 | module.exports = function( poem ) {
99 |
100 | var api = {
101 | promise : internals.createVideo()
102 | }
103 |
104 | api.promise.then( function( video ) {
105 |
106 | var [ canvas, ctx2d, texture ] = internals.createTexture( video )
107 | var mesh = internals.createMesh( poem, texture, canvas )
108 |
109 | var update = internals.updateFn( mesh, ctx2d, video, texture )
110 |
111 | _.extend( api, {
112 | mesh : mesh
113 | , canvas : canvas
114 | , ctx2d : ctx2d
115 | , texture : texture
116 | , video : video
117 | , add : _.partial( internals.add, poem.camera.object, mesh, video, update )
118 | , remove : _.partial( internals.remove, poem.camera.object, mesh, video, update )
119 | })
120 | })
121 |
122 | return api
123 | }
--------------------------------------------------------------------------------
/js/demos/wire-terrain/keyframes.js:
--------------------------------------------------------------------------------
1 | var CubicBezier = require('cubic-bezier')
2 | var QuickIn = CubicBezier(.12,.51,.8,.85, 32)
3 | var Pi = Math.PI
4 | var HalfPi = Math.PI / 2
5 |
6 | module.exports = {
7 | loop : true,
8 | speed : 1,
9 | keyframes : [
10 | {
11 | duration: 15,
12 | easing: QuickIn,
13 | actions: [
14 | [ "camera.object.position.x", [ 0, 0 ] ],
15 | [ "camera.object.position.y", [ -250, 0 ] ],
16 | [ "camera.object.position.z", [ 0, -5000 ] ],
17 | [ "camera.setAndUpdateFov", [ 5, 30 ] ],
18 | [ "endlessTerrain.height", [ 0, 1 ] ],
19 | [ "restrictedCamera.rotation.x", [ -0.3, 0 ] ],
20 | [ "restrictedCamera.rotation.y", [ -0.3, 0.1 ] ],
21 |
22 | [ "restrictedCamera.rotateAll", { x:-0.3, y:-0.3, z:0 }],
23 |
24 | [ "credits.mesh.position.z", [ -30, -10 ] ],
25 | [ "credits.add", {} ]
26 |
27 | ]
28 | },
29 | {
30 | duration: 10,
31 | easing: "linear",
32 | isolate: false,
33 | startHere: false,
34 | actions: [
35 | [ "credits.remove", {} ],
36 |
37 | [ "camera.object.position.x", [ 0, 0 ] ],
38 | [ "camera.object.position.y", [ 0, 0 ] ],
39 | [ "camera.object.position.z", [ -5000, -5700 ] ],
40 | [ "camera.setAndUpdateFov", [ 70, 40 ] ],
41 |
42 | [ "restrictedCamera.rotateAll", { x:-0.1, y:HalfPi, z: 0 }]
43 | ]
44 | },
45 | {
46 | duration: 13,
47 | easing: "linear",
48 | isolate: false,
49 | actions: [
50 | [ "camera.object.position.x", 600 ],
51 | [ "camera.object.position.y", [ 0, 0 ] ],
52 | [ "camera.object.position.z", [ -5700, -6000 ] ],
53 | [ "camera.setAndUpdateFov", [ 100, 50 ] ],
54 |
55 | [ "restrictedCamera.rotateAll", { x:-Pi*0.5, y:0, z: 0 }],
56 |
57 | [ "restrictedCamera.rotation.x", [ -Pi*0.5, 0 ] ]
58 |
59 | ]
60 | },
61 | {
62 | duration: 10,
63 | easing: "linear",
64 | isolate: false,
65 | actions: [
66 | [ "camera.object.position.x", 600 ],
67 | [ "camera.object.position.y", [ 0, 0 ] ],
68 | [ "camera.object.position.z", [ -5700, -6400 ] ],
69 |
70 | [ "restrictedCamera.rotateAll", { x:0, y:Pi, z: 0 }],
71 |
72 | // [ "restrictedCamera.rotation.x", [ -0.2, 0.2 ] ]
73 |
74 | ]
75 | }
76 | ]
77 | }
--------------------------------------------------------------------------------
/js/demos/wire-terrain/terrain.frag:
--------------------------------------------------------------------------------
1 | #pragma glslify: hsv2rgb = require(glsl-hsv2rgb)
2 | uniform float width;
3 | uniform float heightFactor;
4 | uniform float elapsed;
5 |
6 | varying float height;
7 | varying vec2 vUv;
8 | varying float vCameraDistance;
9 |
10 | void main() {
11 |
12 | float hueX = abs(0.5 - fract(vUv.x * 2.0)) * 2.0;
13 | float hueY = abs(0.5 - fract(vUv.y * 2.0)) * 2.0;
14 |
15 | float waveSpeed = 0.0005;
16 | float waveLength = 0.0001;
17 | float wave = mod((vCameraDistance * waveLength + elapsed * waveSpeed), 1.0);
18 |
19 | gl_FragColor = vec4(
20 | hsv2rgb(
21 | vec3(
22 | // mod(xHue, 1.0),
23 | (hueX + hueY) * 0.1 + 0.25,
24 | mix(heightFactor, mix(height, 0.5, 0.8), 0.8),
25 | mix(heightFactor, mix(height, 1.2, 0.35), 0.35)
26 | )
27 | ),
28 | 1.0 - wave + 0.2
29 | );
30 |
31 | float fogFactor = smoothstep( 0.0, 1.0, vCameraDistance / width );
32 | vec3 fogColor = vec3( 0.14, 0.14, 0.14 );
33 |
34 | gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );
35 |
36 | }
--------------------------------------------------------------------------------
/js/demos/wire-terrain/terrain.vert:
--------------------------------------------------------------------------------
1 | uniform sampler2D terrain;
2 | uniform float heightFactor;
3 | uniform float width;
4 | uniform float elapsed;
5 |
6 | varying float height;
7 | varying vec2 vUv;
8 | varying float vCameraDistance;
9 |
10 | #pragma glslify: snoise3 = require(glsl-noise/simplex/3d)
11 |
12 | void main() {
13 |
14 | vec4 modelPosition = modelMatrix * vec4(position, 1.0);
15 |
16 | vUv = vec2( modelPosition.x, modelPosition.z + elapsed * 0.05 ) / width;
17 |
18 | float mainHeightShape = texture2D( terrain, vUv * 0.3 ).w;
19 | float smallNoiseySurface = texture2D( terrain, vUv * 5.0 ).w;
20 | float amountOfSmallNoise = snoise3(vec3(
21 | modelPosition.x * 0.001 * sin( elapsed * 0.001 ),
22 | modelPosition.z * 0.001 * sin( elapsed * 0.001 ),
23 | elapsed * 0.0001
24 | ));
25 |
26 | height = mainHeightShape + (
27 | smallNoiseySurface * smallNoiseySurface * amountOfSmallNoise
28 | );
29 |
30 | vCameraDistance = distance( modelPosition.xyz, cameraPosition );
31 |
32 | vec4 modifiedPosition = vec4(
33 | position.x,
34 | position.y + height * width / 20.0 * heightFactor,
35 | position.z,
36 | 1.0
37 | );
38 |
39 | gl_Position = projectionMatrix * modelViewMatrix * modifiedPosition;
40 |
41 | }
--------------------------------------------------------------------------------
/js/index.js:
--------------------------------------------------------------------------------
1 | require('./utils/ThreeConsole');
2 | require('es6-promise').polyfill();
3 |
4 | var manifests = require('../manifests');
5 |
6 | var routing = require('./core/routing');
7 | var ui = require('./core/ui')( manifests );
8 |
9 | routing.start(
10 | require('./core/poem'),
11 | manifests
12 | );
--------------------------------------------------------------------------------
/js/postprocessing/BokehPass.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Depth-of-field post-process with bokeh shader
3 | */
4 |
5 |
6 | THREE.BokehPass = function ( scene, camera, params ) {
7 |
8 | this.scene = scene;
9 | this.camera = camera;
10 |
11 | var focus = ( params.focus !== undefined ) ? params.focus : 1.0;
12 | var aspect = ( params.aspect !== undefined ) ? params.aspect : camera.aspect;
13 | var aperture = ( params.aperture !== undefined ) ? params.aperture : 0.025;
14 | var maxblur = ( params.maxblur !== undefined ) ? params.maxblur : 1.0;
15 |
16 | // render targets
17 |
18 | var width = params.width || window.innerWidth || 1;
19 | var height = params.height || window.innerHeight || 1;
20 |
21 | this.renderTargetColor = new THREE.WebGLRenderTarget( width, height, {
22 | minFilter: THREE.LinearFilter,
23 | magFilter: THREE.LinearFilter,
24 | format: THREE.RGBFormat
25 | } );
26 |
27 | this.renderTargetDepth = this.renderTargetColor.clone();
28 |
29 | // depth material
30 |
31 | this.materialDepth = new THREE.MeshDepthMaterial();
32 |
33 | // bokeh material
34 |
35 | if ( THREE.BokehShader === undefined ) {
36 | console.error( "THREE.BokehPass relies on THREE.BokehShader" );
37 | }
38 |
39 | var bokehShader = THREE.BokehShader;
40 | var bokehUniforms = THREE.UniformsUtils.clone( bokehShader.uniforms );
41 |
42 | bokehUniforms[ "tDepth" ].value = this.renderTargetDepth;
43 |
44 | bokehUniforms[ "focus" ].value = focus;
45 | bokehUniforms[ "aspect" ].value = aspect;
46 | bokehUniforms[ "aperture" ].value = aperture;
47 | bokehUniforms[ "maxblur" ].value = maxblur;
48 |
49 | this.materialBokeh = new THREE.ShaderMaterial({
50 | uniforms: bokehUniforms,
51 | vertexShader: bokehShader.vertexShader,
52 | fragmentShader: bokehShader.fragmentShader
53 | });
54 |
55 | this.uniforms = bokehUniforms;
56 | this.enabled = true;
57 | this.needsSwap = false;
58 | this.renderToScreen = false;
59 | this.clear = false;
60 |
61 | this.camera2 = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
62 | this.scene2 = new THREE.Scene();
63 |
64 | this.quad2 = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
65 | this.scene2.add( this.quad2 );
66 |
67 | };
68 |
69 | THREE.BokehPass.prototype = {
70 |
71 | render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
72 |
73 | this.quad2.material = this.materialBokeh;
74 |
75 | // Render depth into texture
76 |
77 | this.scene.overrideMaterial = this.materialDepth;
78 |
79 | renderer.render( this.scene, this.camera, this.renderTargetDepth, true );
80 |
81 | // Render bokeh composite
82 |
83 | this.uniforms[ "tColor" ].value = readBuffer;
84 |
85 | if ( this.renderToScreen ) {
86 |
87 | renderer.render( this.scene2, this.camera2 );
88 |
89 | } else {
90 |
91 | renderer.render( this.scene2, this.camera2, writeBuffer, this.clear );
92 |
93 | }
94 |
95 | this.scene.overrideMaterial = null;
96 |
97 | }
98 |
99 | };
100 |
101 |
--------------------------------------------------------------------------------
/js/postprocessing/ChromaticAberration/chromatic.frag:
--------------------------------------------------------------------------------
1 | #pragma glslify: random = require(glsl-random)
2 |
3 | uniform float opacity;
4 |
5 | uniform sampler2D tDiffuse;
6 |
7 | varying vec2 vUv;
8 |
9 | void main() {
10 |
11 | vec2 unitI_ToSide = (vUv * 2.0 - 1.0);
12 |
13 | unitI_ToSide = pow(unitI_ToSide, vec2(3.0, 5.0)) * random(vUv) * -0.01;
14 |
15 | vec4 texel = texture2D( tDiffuse, vUv );
16 | vec4 smallshift = texture2D( tDiffuse, vUv + unitI_ToSide * 0.5 );
17 | vec4 bigshift = texture2D( tDiffuse, vUv + unitI_ToSide );
18 |
19 | gl_FragColor = opacity * vec4( bigshift.x, texel.y, smallshift.z, texel.w );
20 |
21 | }
--------------------------------------------------------------------------------
/js/postprocessing/ChromaticAberration/chromatic.vert:
--------------------------------------------------------------------------------
1 | varying vec2 vUv;
2 |
3 | void main() {
4 |
5 | vUv = uv;
6 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
7 |
8 | }
--------------------------------------------------------------------------------
/js/postprocessing/ChromaticAberration/index.js:
--------------------------------------------------------------------------------
1 | var glslify = require('glslify');
2 |
3 | var chromaticAberrationShader = new THREE.ShaderMaterial({
4 | vertexShader: glslify('./chromatic.vert'),
5 | fragmentShader: glslify('./chromatic.frag'),
6 | uniforms: {
7 | opacity: { type: 'f', value: 1 },
8 | }
9 | })
10 |
11 | module.exports = chromaticAberrationShader;
12 |
--------------------------------------------------------------------------------
/js/postprocessing/DotScreenPass.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | */
4 |
5 | THREE.DotScreenPass = function ( center, angle, scale ) {
6 |
7 | if ( THREE.DotScreenShader === undefined )
8 | console.error( "THREE.DotScreenPass relies on THREE.DotScreenShader" );
9 |
10 | var shader = THREE.DotScreenShader;
11 |
12 | this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
13 |
14 | if ( center !== undefined ) this.uniforms[ "center" ].value.copy( center );
15 | if ( angle !== undefined ) this.uniforms[ "angle"].value = angle;
16 | if ( scale !== undefined ) this.uniforms[ "scale"].value = scale;
17 |
18 | this.material = new THREE.ShaderMaterial( {
19 |
20 | uniforms: this.uniforms,
21 | vertexShader: shader.vertexShader,
22 | fragmentShader: shader.fragmentShader
23 |
24 | } );
25 |
26 | this.enabled = true;
27 | this.renderToScreen = false;
28 | this.needsSwap = true;
29 |
30 |
31 | this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
32 | this.scene = new THREE.Scene();
33 |
34 | this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
35 | this.scene.add( this.quad );
36 |
37 | };
38 |
39 | THREE.DotScreenPass.prototype = {
40 |
41 | render: function ( renderer, writeBuffer, readBuffer, delta ) {
42 |
43 | this.uniforms[ "tDiffuse" ].value = readBuffer;
44 | this.uniforms[ "tSize" ].value.set( readBuffer.width, readBuffer.height );
45 |
46 | this.quad.material = this.material;
47 |
48 | if ( this.renderToScreen ) {
49 |
50 | renderer.render( this.scene, this.camera );
51 |
52 | } else {
53 |
54 | renderer.render( this.scene, this.camera, writeBuffer, false );
55 |
56 | }
57 |
58 | }
59 |
60 | };
61 |
--------------------------------------------------------------------------------
/js/postprocessing/EffectComposer.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | */
4 |
5 | THREE.EffectComposer = function ( renderer, renderTarget ) {
6 |
7 | this.renderer = renderer;
8 |
9 | if ( renderTarget === undefined ) {
10 |
11 | var width = window.innerWidth || 1;
12 | var height = window.innerHeight || 1;
13 | var parameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
14 |
15 | renderTarget = new THREE.WebGLRenderTarget( width, height, parameters );
16 |
17 | }
18 |
19 | this.renderTarget1 = renderTarget;
20 | this.renderTarget2 = renderTarget.clone();
21 |
22 | this.writeBuffer = this.renderTarget1;
23 | this.readBuffer = this.renderTarget2;
24 |
25 | this.passes = [];
26 |
27 | if ( THREE.CopyShader === undefined )
28 | console.error( "THREE.EffectComposer relies on THREE.CopyShader" );
29 |
30 | this.copyPass = new THREE.ShaderPass( THREE.CopyShader );
31 |
32 | };
33 |
34 | THREE.EffectComposer.prototype = {
35 |
36 | swapBuffers: function() {
37 |
38 | var tmp = this.readBuffer;
39 | this.readBuffer = this.writeBuffer;
40 | this.writeBuffer = tmp;
41 |
42 | },
43 |
44 | addPass: function ( pass ) {
45 |
46 | this.passes.push( pass );
47 |
48 | },
49 |
50 | insertPass: function ( pass, index ) {
51 |
52 | this.passes.splice( index, 0, pass );
53 |
54 | },
55 |
56 | render: function ( delta ) {
57 |
58 | this.writeBuffer = this.renderTarget1;
59 | this.readBuffer = this.renderTarget2;
60 |
61 | var maskActive = false;
62 |
63 | var pass, i, il = this.passes.length;
64 |
65 | for ( i = 0; i < il; i ++ ) {
66 |
67 | pass = this.passes[ i ];
68 |
69 | if ( !pass.enabled ) continue;
70 |
71 | pass.render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive );
72 |
73 | if ( pass.needsSwap ) {
74 |
75 | if ( maskActive ) {
76 |
77 | var context = this.renderer.context;
78 |
79 | context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );
80 |
81 | this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, delta );
82 |
83 | context.stencilFunc( context.EQUAL, 1, 0xffffffff );
84 |
85 | }
86 |
87 | this.swapBuffers();
88 |
89 | }
90 |
91 | if ( pass instanceof THREE.MaskPass ) {
92 |
93 | maskActive = true;
94 |
95 | } else if ( pass instanceof THREE.ClearMaskPass ) {
96 |
97 | maskActive = false;
98 |
99 | }
100 |
101 | }
102 |
103 | },
104 |
105 | reset: function ( renderTarget ) {
106 |
107 | if ( renderTarget === undefined ) {
108 |
109 | renderTarget = this.renderTarget1.clone();
110 |
111 | renderTarget.width = window.innerWidth;
112 | renderTarget.height = window.innerHeight;
113 |
114 | }
115 |
116 | this.renderTarget1 = renderTarget;
117 | this.renderTarget2 = renderTarget.clone();
118 |
119 | this.writeBuffer = this.renderTarget1;
120 | this.readBuffer = this.renderTarget2;
121 |
122 | },
123 |
124 | setSize: function ( width, height ) {
125 |
126 | var renderTarget = this.renderTarget1.clone();
127 |
128 | renderTarget.width = width;
129 | renderTarget.height = height;
130 |
131 | this.reset( renderTarget );
132 |
133 | }
134 |
135 | };
136 |
--------------------------------------------------------------------------------
/js/postprocessing/FilmPass.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | */
4 |
5 | THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) {
6 |
7 | if ( THREE.FilmShader === undefined )
8 | console.error( "THREE.FilmPass relies on THREE.FilmShader" );
9 |
10 | var shader = THREE.FilmShader;
11 |
12 | this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
13 |
14 | this.material = new THREE.ShaderMaterial( {
15 |
16 | uniforms: this.uniforms,
17 | vertexShader: shader.vertexShader,
18 | fragmentShader: shader.fragmentShader
19 |
20 | } );
21 |
22 | if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale;
23 | if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity;
24 | if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
25 | if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
26 |
27 | this.enabled = true;
28 | this.renderToScreen = false;
29 | this.needsSwap = true;
30 |
31 |
32 | this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
33 | this.scene = new THREE.Scene();
34 |
35 | this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
36 | this.scene.add( this.quad );
37 |
38 | };
39 |
40 | THREE.FilmPass.prototype = {
41 |
42 | render: function ( renderer, writeBuffer, readBuffer, delta ) {
43 |
44 | this.uniforms[ "tDiffuse" ].value = readBuffer;
45 | this.uniforms[ "time" ].value += delta;
46 |
47 | this.quad.material = this.material;
48 |
49 | if ( this.renderToScreen ) {
50 |
51 | renderer.render( this.scene, this.camera );
52 |
53 | } else {
54 |
55 | renderer.render( this.scene, this.camera, writeBuffer, false );
56 |
57 | }
58 |
59 | }
60 |
61 | };
62 |
--------------------------------------------------------------------------------
/js/postprocessing/GlitchPass.js:
--------------------------------------------------------------------------------
1 | /**
2 |
3 | */
4 |
5 | THREE.GlitchPass = function ( dt_size ) {
6 |
7 | if ( THREE.DigitalGlitch === undefined ) console.error( "THREE.GlitchPass relies on THREE.DigitalGlitch" );
8 |
9 | var shader = THREE.DigitalGlitch;
10 | this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
11 |
12 | if(dt_size===undefined) dt_size=64;
13 |
14 |
15 | this.uniforms[ "tDisp"].value=this.generateHeightmap(dt_size);
16 |
17 |
18 | this.material = new THREE.ShaderMaterial({
19 | uniforms: this.uniforms,
20 | vertexShader: shader.vertexShader,
21 | fragmentShader: shader.fragmentShader
22 | });
23 |
24 | this.enabled = true;
25 | this.renderToScreen = false;
26 | this.needsSwap = true;
27 |
28 |
29 | this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
30 | this.scene = new THREE.Scene();
31 |
32 | this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
33 | this.scene.add( this.quad );
34 |
35 | this.goWild=false;
36 | this.curF=0;
37 | this.generateTrigger();
38 |
39 | };
40 |
41 | THREE.GlitchPass.prototype = {
42 |
43 | render: function ( renderer, writeBuffer, readBuffer, delta )
44 | {
45 | this.uniforms[ "tDiffuse" ].value = readBuffer;
46 | this.uniforms[ 'seed' ].value=Math.random();//default seeding
47 | this.uniforms[ 'byp' ].value=0;
48 |
49 | if(this.curF % this.randX ===0 || this.goWild===true)
50 | {
51 | this.uniforms[ 'amount' ].value=Math.random()/30;
52 | this.uniforms[ 'angle' ].value=THREE.Math.randFloat(-Math.PI,Math.PI);
53 | this.uniforms[ 'seed_x' ].value=THREE.Math.randFloat(-1,1);
54 | this.uniforms[ 'seed_y' ].value=THREE.Math.randFloat(-1,1);
55 | this.uniforms[ 'distortion_x' ].value=THREE.Math.randFloat(0,1);
56 | this.uniforms[ 'distortion_y' ].value=THREE.Math.randFloat(0,1);
57 | this.curF=0;
58 | this.generateTrigger();
59 | }
60 | else if(this.curF % this.randX 0.0) {",
49 | "gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) / (1.0 - contrast) + 0.5;",
50 | "} else {",
51 | "gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5;",
52 | "}",
53 |
54 | "}"
55 |
56 | ].join("\n")
57 |
58 | };
59 |
--------------------------------------------------------------------------------
/js/shaders/ChromaticAberration.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gregtatum/sandbox/b5279bac41d2af3c681029b2aa544987db992102/js/shaders/ChromaticAberration.js
--------------------------------------------------------------------------------
/js/shaders/ColorCorrectionShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Color correction
5 | */
6 |
7 | THREE.ColorCorrectionShader = {
8 |
9 | uniforms: {
10 |
11 | "tDiffuse": { type: "t", value: null },
12 | "powRGB": { type: "v3", value: new THREE.Vector3( 2, 2, 2 ) },
13 | "mulRGB": { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
14 |
15 | },
16 |
17 | vertexShader: [
18 |
19 | "varying vec2 vUv;",
20 |
21 | "void main() {",
22 |
23 | "vUv = uv;",
24 |
25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
26 |
27 | "}"
28 |
29 | ].join("\n"),
30 |
31 | fragmentShader: [
32 |
33 | "uniform sampler2D tDiffuse;",
34 | "uniform vec3 powRGB;",
35 | "uniform vec3 mulRGB;",
36 |
37 | "varying vec2 vUv;",
38 |
39 | "void main() {",
40 |
41 | "gl_FragColor = texture2D( tDiffuse, vUv );",
42 | "gl_FragColor.rgb = mulRGB * pow( gl_FragColor.rgb, powRGB );",
43 |
44 | "}"
45 |
46 | ].join("\n")
47 |
48 | };
49 |
--------------------------------------------------------------------------------
/js/shaders/ColorifyShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Colorify shader
5 | */
6 |
7 | THREE.ColorifyShader = {
8 |
9 | uniforms: {
10 |
11 | "tDiffuse": { type: "t", value: null },
12 | "color": { type: "c", value: new THREE.Color( 0xffffff ) }
13 |
14 | },
15 |
16 | vertexShader: [
17 |
18 | "varying vec2 vUv;",
19 |
20 | "void main() {",
21 |
22 | "vUv = uv;",
23 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
24 |
25 | "}"
26 |
27 | ].join("\n"),
28 |
29 | fragmentShader: [
30 |
31 | "uniform vec3 color;",
32 | "uniform sampler2D tDiffuse;",
33 |
34 | "varying vec2 vUv;",
35 |
36 | "void main() {",
37 |
38 | "vec4 texel = texture2D( tDiffuse, vUv );",
39 |
40 | "vec3 luma = vec3( 0.299, 0.587, 0.114 );",
41 | "float v = dot( texel.xyz, luma );",
42 |
43 | "gl_FragColor = vec4( v * color, texel.w );",
44 |
45 | "}"
46 |
47 | ].join("\n")
48 |
49 | };
50 |
--------------------------------------------------------------------------------
/js/shaders/ConvolutionShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Convolution shader
5 | * ported from o3d sample to WebGL / GLSL
6 | * http://o3d.googlecode.com/svn/trunk/samples/convolution.html
7 | */
8 |
9 | THREE.ConvolutionShader = {
10 |
11 | defines: {
12 |
13 | "KERNEL_SIZE_FLOAT": "25.0",
14 | "KERNEL_SIZE_INT": "25",
15 |
16 | },
17 |
18 | uniforms: {
19 |
20 | "tDiffuse": { type: "t", value: null },
21 | "uImageIncrement": { type: "v2", value: new THREE.Vector2( 0.001953125, 0.0 ) },
22 | "cKernel": { type: "fv1", value: [] }
23 |
24 | },
25 |
26 | vertexShader: [
27 |
28 | "uniform vec2 uImageIncrement;",
29 |
30 | "varying vec2 vUv;",
31 |
32 | "void main() {",
33 |
34 | "vUv = uv - ( ( KERNEL_SIZE_FLOAT - 1.0 ) / 2.0 ) * uImageIncrement;",
35 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
36 |
37 | "}"
38 |
39 | ].join("\n"),
40 |
41 | fragmentShader: [
42 |
43 | "uniform float cKernel[ KERNEL_SIZE_INT ];",
44 |
45 | "uniform sampler2D tDiffuse;",
46 | "uniform vec2 uImageIncrement;",
47 |
48 | "varying vec2 vUv;",
49 |
50 | "void main() {",
51 |
52 | "vec2 imageCoord = vUv;",
53 | "vec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );",
54 |
55 | "for( int i = 0; i < KERNEL_SIZE_INT; i ++ ) {",
56 |
57 | "sum += texture2D( tDiffuse, imageCoord ) * cKernel[ i ];",
58 | "imageCoord += uImageIncrement;",
59 |
60 | "}",
61 |
62 | "gl_FragColor = sum;",
63 |
64 | "}"
65 |
66 |
67 | ].join("\n"),
68 |
69 | buildKernel: function ( sigma ) {
70 |
71 | // We lop off the sqrt(2 * pi) * sigma term, since we're going to normalize anyway.
72 |
73 | function gauss( x, sigma ) {
74 |
75 | return Math.exp( - ( x * x ) / ( 2.0 * sigma * sigma ) );
76 |
77 | }
78 |
79 | var i, values, sum, halfWidth, kMaxKernelSize = 25, kernelSize = 2 * Math.ceil( sigma * 3.0 ) + 1;
80 |
81 | if ( kernelSize > kMaxKernelSize ) kernelSize = kMaxKernelSize;
82 | halfWidth = ( kernelSize - 1 ) * 0.5;
83 |
84 | values = new Array( kernelSize );
85 | sum = 0.0;
86 | for ( i = 0; i < kernelSize; ++i ) {
87 |
88 | values[ i ] = gauss( i - halfWidth, sigma );
89 | sum += values[ i ];
90 |
91 | }
92 |
93 | // normalize the kernel
94 |
95 | for ( i = 0; i < kernelSize; ++i ) values[ i ] /= sum;
96 |
97 | return values;
98 |
99 | }
100 |
101 | };
102 |
--------------------------------------------------------------------------------
/js/shaders/CopyShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Full-screen textured quad shader
5 | */
6 |
7 | THREE.CopyShader = {
8 |
9 | uniforms: {
10 |
11 | "tDiffuse": { type: "t", value: null },
12 | "opacity": { type: "f", value: 1.0 }
13 |
14 | },
15 |
16 | vertexShader: [
17 |
18 | "varying vec2 vUv;",
19 |
20 | "void main() {",
21 |
22 | "vUv = uv;",
23 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
24 |
25 | "}"
26 |
27 | ].join("\n"),
28 |
29 | fragmentShader: [
30 |
31 | "uniform float opacity;",
32 |
33 | "uniform sampler2D tDiffuse;",
34 |
35 | "varying vec2 vUv;",
36 |
37 | "void main() {",
38 |
39 | "vec4 texel = texture2D( tDiffuse, vUv );",
40 | "gl_FragColor = opacity * texel;",
41 |
42 | "}"
43 |
44 | ].join("\n")
45 |
46 | };
47 |
--------------------------------------------------------------------------------
/js/shaders/DOFMipMapShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Depth-of-field shader using mipmaps
5 | * - from Matt Handley @applmak
6 | * - requires power-of-2 sized render target with enabled mipmaps
7 | */
8 |
9 | THREE.DOFMipMapShader = {
10 |
11 | uniforms: {
12 |
13 | "tColor": { type: "t", value: null },
14 | "tDepth": { type: "t", value: null },
15 | "focus": { type: "f", value: 1.0 },
16 | "maxblur": { type: "f", value: 1.0 }
17 |
18 | },
19 |
20 | vertexShader: [
21 |
22 | "varying vec2 vUv;",
23 |
24 | "void main() {",
25 |
26 | "vUv = uv;",
27 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
28 |
29 | "}"
30 |
31 | ].join("\n"),
32 |
33 | fragmentShader: [
34 |
35 | "uniform float focus;",
36 | "uniform float maxblur;",
37 |
38 | "uniform sampler2D tColor;",
39 | "uniform sampler2D tDepth;",
40 |
41 | "varying vec2 vUv;",
42 |
43 | "void main() {",
44 |
45 | "vec4 depth = texture2D( tDepth, vUv );",
46 |
47 | "float factor = depth.x - focus;",
48 |
49 | "vec4 col = texture2D( tColor, vUv, 2.0 * maxblur * abs( focus - depth.x ) );",
50 |
51 | "gl_FragColor = col;",
52 | "gl_FragColor.a = 1.0;",
53 |
54 | "}"
55 |
56 | ].join("\n")
57 |
58 | };
59 |
--------------------------------------------------------------------------------
/js/shaders/DigitalGlitch.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author felixturner / http://airtight.cc/
3 | *
4 | * RGB Shift Shader
5 | * Shifts red and blue channels from center in opposite directions
6 | * Ported from http://kriss.cx/tom/2009/05/rgb-shift/
7 | * by Tom Butterworth / http://kriss.cx/tom/
8 | *
9 | * amount: shift distance (1 is width of input)
10 | * angle: shift angle in radians
11 | */
12 |
13 | THREE.DigitalGlitch = {
14 |
15 | uniforms: {
16 |
17 | "tDiffuse": { type: "t", value: null },//diffuse texture
18 | "tDisp": { type: "t", value: null },//displacement texture for digital glitch squares
19 | "byp": { type: "i", value: 0 },//apply the glitch ?
20 | "amount": { type: "f", value: 0.08 },
21 | "angle": { type: "f", value: 0.02 },
22 | "seed": { type: "f", value: 0.02 },
23 | "seed_x": { type: "f", value: 0.02 },//-1,1
24 | "seed_y": { type: "f", value: 0.02 },//-1,1
25 | "distortion_x": { type: "f", value: 0.5 },
26 | "distortion_y": { type: "f", value: 0.6 },
27 | "col_s": { type: "f", value: 0.05 }
28 | },
29 |
30 | vertexShader: [
31 |
32 | "varying vec2 vUv;",
33 | "void main() {",
34 | "vUv = uv;",
35 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
36 | "}"
37 | ].join("\n"),
38 |
39 | fragmentShader: [
40 | "uniform int byp;",//should we apply the glitch ?
41 |
42 | "uniform sampler2D tDiffuse;",
43 | "uniform sampler2D tDisp;",
44 |
45 | "uniform float amount;",
46 | "uniform float angle;",
47 | "uniform float seed;",
48 | "uniform float seed_x;",
49 | "uniform float seed_y;",
50 | "uniform float distortion_x;",
51 | "uniform float distortion_y;",
52 | "uniform float col_s;",
53 |
54 | "varying vec2 vUv;",
55 |
56 |
57 | "float rand(vec2 co){",
58 | "return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);",
59 | "}",
60 |
61 | "void main() {",
62 | "if(byp<1) {",
63 | "vec2 p = vUv;",
64 | "float xs = floor(gl_FragCoord.x / 0.5);",
65 | "float ys = floor(gl_FragCoord.y / 0.5);",
66 | //based on staffantans glitch shader for unity https://github.com/staffantan/unityglitch
67 | "vec4 normal = texture2D (tDisp, p*seed*seed);",
68 | "if(p.ydistortion_x-col_s*seed) {",
69 | "if(seed_x>0.){",
70 | "p.y = 1. - (p.y + distortion_y);",
71 | "}",
72 | "else {",
73 | "p.y = distortion_y;",
74 | "}",
75 | "}",
76 | "if(p.xdistortion_y-col_s*seed) {",
77 | "if(seed_y>0.){",
78 | "p.x=distortion_x;",
79 | "}",
80 | "else {",
81 | "p.x = 1. - (p.x + distortion_x);",
82 | "}",
83 | "}",
84 | "p.x+=normal.x*seed_x*(seed/5.);",
85 | "p.y+=normal.y*seed_y*(seed/5.);",
86 | //base from RGB shift shader
87 | "vec2 offset = amount * vec2( cos(angle), sin(angle));",
88 | "vec4 cr = texture2D(tDiffuse, p + offset);",
89 | "vec4 cga = texture2D(tDiffuse, p);",
90 | "vec4 cb = texture2D(tDiffuse, p - offset);",
91 | "gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);",
92 | //add noise
93 | "vec4 snow = 200.*amount*vec4(rand(vec2(xs * seed,ys * seed*50.))*0.2);",
94 | "gl_FragColor = gl_FragColor+ snow;",
95 | "}",
96 | "else {",
97 | "gl_FragColor=texture2D (tDiffuse, vUv);",
98 | "}",
99 | "}"
100 |
101 | ].join("\n")
102 |
103 | };
104 |
--------------------------------------------------------------------------------
/js/shaders/DotScreenShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Dot screen shader
5 | * based on glfx.js sepia shader
6 | * https://github.com/evanw/glfx.js
7 | */
8 |
9 | THREE.DotScreenShader = {
10 |
11 | uniforms: {
12 |
13 | "tDiffuse": { type: "t", value: null },
14 | "tSize": { type: "v2", value: new THREE.Vector2( 256, 256 ) },
15 | "center": { type: "v2", value: new THREE.Vector2( 0.5, 0.5 ) },
16 | "angle": { type: "f", value: 1.57 },
17 | "scale": { type: "f", value: 1.0 }
18 |
19 | },
20 |
21 | vertexShader: [
22 |
23 | "varying vec2 vUv;",
24 |
25 | "void main() {",
26 |
27 | "vUv = uv;",
28 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
29 |
30 | "}"
31 |
32 | ].join("\n"),
33 |
34 | fragmentShader: [
35 |
36 | "uniform vec2 center;",
37 | "uniform float angle;",
38 | "uniform float scale;",
39 | "uniform vec2 tSize;",
40 |
41 | "uniform sampler2D tDiffuse;",
42 |
43 | "varying vec2 vUv;",
44 |
45 | "float pattern() {",
46 |
47 | "float s = sin( angle ), c = cos( angle );",
48 |
49 | "vec2 tex = vUv * tSize - center;",
50 | "vec2 point = vec2( c * tex.x - s * tex.y, s * tex.x + c * tex.y ) * scale;",
51 |
52 | "return ( sin( point.x ) * sin( point.y ) ) * 4.0;",
53 |
54 | "}",
55 |
56 | "void main() {",
57 |
58 | "vec4 color = texture2D( tDiffuse, vUv );",
59 |
60 | "float average = ( color.r + color.g + color.b ) / 3.0;",
61 |
62 | "gl_FragColor = vec4( vec3( average * 10.0 - 5.0 + pattern() ), color.a );",
63 |
64 | "}"
65 |
66 | ].join("\n")
67 |
68 | };
69 |
--------------------------------------------------------------------------------
/js/shaders/EdgeShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author zz85 / https://github.com/zz85 | https://www.lab4games.net/zz85/blog
3 | *
4 | * Edge Detection Shader using Frei-Chen filter
5 | * Based on http://rastergrid.com/blog/2011/01/frei-chen-edge-detector
6 | *
7 | * aspect: vec2 of (1/width, 1/height)
8 | */
9 |
10 | THREE.EdgeShader = {
11 |
12 | uniforms: {
13 |
14 | "tDiffuse": { type: "t", value: null },
15 | "aspect": { type: "v2", value: new THREE.Vector2( 512, 512 ) },
16 | },
17 |
18 | vertexShader: [
19 |
20 | "varying vec2 vUv;",
21 |
22 | "void main() {",
23 |
24 | "vUv = uv;",
25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
26 |
27 | "}"
28 |
29 | ].join("\n"),
30 |
31 | fragmentShader: [
32 |
33 | "uniform sampler2D tDiffuse;",
34 | "varying vec2 vUv;",
35 |
36 | "uniform vec2 aspect;",
37 |
38 | "vec2 texel = vec2(1.0 / aspect.x, 1.0 / aspect.y);",
39 |
40 |
41 | "mat3 G[9];",
42 |
43 | // hard coded matrix values!!!! as suggested in https://github.com/neilmendoza/ofxPostProcessing/blob/master/src/EdgePass.cpp#L45
44 |
45 | "const mat3 g0 = mat3( 0.3535533845424652, 0, -0.3535533845424652, 0.5, 0, -0.5, 0.3535533845424652, 0, -0.3535533845424652 );",
46 | "const mat3 g1 = mat3( 0.3535533845424652, 0.5, 0.3535533845424652, 0, 0, 0, -0.3535533845424652, -0.5, -0.3535533845424652 );",
47 | "const mat3 g2 = mat3( 0, 0.3535533845424652, -0.5, -0.3535533845424652, 0, 0.3535533845424652, 0.5, -0.3535533845424652, 0 );",
48 | "const mat3 g3 = mat3( 0.5, -0.3535533845424652, 0, -0.3535533845424652, 0, 0.3535533845424652, 0, 0.3535533845424652, -0.5 );",
49 | "const mat3 g4 = mat3( 0, -0.5, 0, 0.5, 0, 0.5, 0, -0.5, 0 );",
50 | "const mat3 g5 = mat3( -0.5, 0, 0.5, 0, 0, 0, 0.5, 0, -0.5 );",
51 | "const mat3 g6 = mat3( 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.6666666865348816, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204 );",
52 | "const mat3 g7 = mat3( -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, 0.6666666865348816, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408 );",
53 | "const mat3 g8 = mat3( 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408 );",
54 |
55 | "void main(void)",
56 | "{",
57 |
58 | "G[0] = g0,",
59 | "G[1] = g1,",
60 | "G[2] = g2,",
61 | "G[3] = g3,",
62 | "G[4] = g4,",
63 | "G[5] = g5,",
64 | "G[6] = g6,",
65 | "G[7] = g7,",
66 | "G[8] = g8;",
67 |
68 | "mat3 I;",
69 | "float cnv[9];",
70 | "vec3 sample;",
71 |
72 | /* fetch the 3x3 neighbourhood and use the RGB vector's length as intensity value */
73 | "for (float i=0.0; i<3.0; i++) {",
74 | "for (float j=0.0; j<3.0; j++) {",
75 | "sample = texture2D(tDiffuse, vUv + texel * vec2(i-1.0,j-1.0) ).rgb;",
76 | "I[int(i)][int(j)] = length(sample);",
77 | "}",
78 | "}",
79 |
80 | /* calculate the convolution values for all the masks */
81 | "for (int i=0; i<9; i++) {",
82 | "float dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);",
83 | "cnv[i] = dp3 * dp3;",
84 | "}",
85 |
86 | "float M = (cnv[0] + cnv[1]) + (cnv[2] + cnv[3]);",
87 | "float S = (cnv[4] + cnv[5]) + (cnv[6] + cnv[7]) + (cnv[8] + M);",
88 |
89 | "gl_FragColor = vec4(vec3(sqrt(M/S)), 1.0);",
90 | "}",
91 |
92 | ].join("\n")
93 | };
94 |
--------------------------------------------------------------------------------
/js/shaders/EdgeShader2.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author zz85 / https://github.com/zz85 | https://www.lab4games.net/zz85/blog
3 | *
4 | * Edge Detection Shader using Sobel filter
5 | * Based on http://rastergrid.com/blog/2011/01/frei-chen-edge-detector
6 | *
7 | * aspect: vec2 of (1/width, 1/height)
8 | */
9 |
10 | THREE.EdgeShader2 = {
11 |
12 | uniforms: {
13 |
14 | "tDiffuse": { type: "t", value: null },
15 | "aspect": { type: "v2", value: new THREE.Vector2( 512, 512 ) },
16 | },
17 |
18 | vertexShader: [
19 |
20 | "varying vec2 vUv;",
21 |
22 | "void main() {",
23 |
24 | "vUv = uv;",
25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
26 |
27 | "}"
28 |
29 | ].join("\n"),
30 |
31 | fragmentShader: [
32 |
33 | "uniform sampler2D tDiffuse;",
34 | "varying vec2 vUv;",
35 | "uniform vec2 aspect;",
36 |
37 |
38 | "vec2 texel = vec2(1.0 / aspect.x, 1.0 / aspect.y);",
39 |
40 | "mat3 G[2];",
41 |
42 | "const mat3 g0 = mat3( 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -1.0 );",
43 | "const mat3 g1 = mat3( 1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0 );",
44 |
45 |
46 | "void main(void)",
47 | "{",
48 | "mat3 I;",
49 | "float cnv[2];",
50 | "vec3 sample;",
51 |
52 | "G[0] = g0;",
53 | "G[1] = g1;",
54 |
55 | /* fetch the 3x3 neighbourhood and use the RGB vector's length as intensity value */
56 | "for (float i=0.0; i<3.0; i++)",
57 | "for (float j=0.0; j<3.0; j++) {",
58 | "sample = texture2D( tDiffuse, vUv + texel * vec2(i-1.0,j-1.0) ).rgb;",
59 | "I[int(i)][int(j)] = length(sample);",
60 | "}",
61 |
62 | /* calculate the convolution values for all the masks */
63 | "for (int i=0; i<2; i++) {",
64 | "float dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);",
65 | "cnv[i] = dp3 * dp3; ",
66 | "}",
67 |
68 | "gl_FragColor = vec4(0.5 * sqrt(cnv[0]*cnv[0]+cnv[1]*cnv[1]));",
69 | "} ",
70 |
71 | ].join("\n")
72 |
73 | };
74 |
--------------------------------------------------------------------------------
/js/shaders/FXAAShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | * @author davidedc / http://www.sketchpatch.net/
4 | *
5 | * NVIDIA FXAA by Timothy Lottes
6 | * http://timothylottes.blogspot.com/2011/06/fxaa3-source-released.html
7 | * - WebGL port by @supereggbert
8 | * http://www.glge.org/demos/fxaa/
9 | */
10 |
11 | THREE.FXAAShader = {
12 |
13 | uniforms: {
14 |
15 | "tDiffuse": { type: "t", value: null },
16 | "resolution": { type: "v2", value: new THREE.Vector2( 1 / 1024, 1 / 512 ) }
17 |
18 | },
19 |
20 | vertexShader: [
21 |
22 | "void main() {",
23 |
24 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
25 |
26 | "}"
27 |
28 | ].join("\n"),
29 |
30 | fragmentShader: [
31 |
32 | "uniform sampler2D tDiffuse;",
33 | "uniform vec2 resolution;",
34 |
35 | "#define FXAA_REDUCE_MIN (1.0/128.0)",
36 | "#define FXAA_REDUCE_MUL (1.0/8.0)",
37 | "#define FXAA_SPAN_MAX 8.0",
38 |
39 | "void main() {",
40 |
41 | "vec3 rgbNW = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ).xyz;",
42 | "vec3 rgbNE = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ).xyz;",
43 | "vec3 rgbSW = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ).xyz;",
44 | "vec3 rgbSE = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ).xyz;",
45 | "vec4 rgbaM = texture2D( tDiffuse, gl_FragCoord.xy * resolution );",
46 | "vec3 rgbM = rgbaM.xyz;",
47 | "vec3 luma = vec3( 0.299, 0.587, 0.114 );",
48 |
49 | "float lumaNW = dot( rgbNW, luma );",
50 | "float lumaNE = dot( rgbNE, luma );",
51 | "float lumaSW = dot( rgbSW, luma );",
52 | "float lumaSE = dot( rgbSE, luma );",
53 | "float lumaM = dot( rgbM, luma );",
54 | "float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) );",
55 | "float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) );",
56 |
57 | "vec2 dir;",
58 | "dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));",
59 | "dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));",
60 |
61 | "float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN );",
62 |
63 | "float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce );",
64 | "dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),",
65 | "max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),",
66 | "dir * rcpDirMin)) * resolution;",
67 | "vec4 rgbA = (1.0/2.0) * (",
68 | "texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (1.0/3.0 - 0.5)) +",
69 | "texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (2.0/3.0 - 0.5)));",
70 | "vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (",
71 | "texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (0.0/3.0 - 0.5)) +",
72 | "texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (3.0/3.0 - 0.5)));",
73 | "float lumaB = dot(rgbB, vec4(luma, 0.0));",
74 |
75 | "if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) ) {",
76 |
77 | "gl_FragColor = rgbA;",
78 |
79 | "} else {",
80 | "gl_FragColor = rgbB;",
81 |
82 | "}",
83 |
84 | "}"
85 |
86 | ].join("\n")
87 |
88 | };
89 |
--------------------------------------------------------------------------------
/js/shaders/FilmShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Film grain & scanlines shader
5 | *
6 | * - ported from HLSL to WebGL / GLSL
7 | * http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html
8 | *
9 | * Screen Space Static Postprocessor
10 | *
11 | * Produces an analogue noise overlay similar to a film grain / TV static
12 | *
13 | * Original implementation and noise algorithm
14 | * Pat 'Hawthorne' Shearon
15 | *
16 | * Optimized scanlines + noise version with intensity scaling
17 | * Georg 'Leviathan' Steinrohder
18 | *
19 | * This version is provided under a Creative Commons Attribution 3.0 License
20 | * http://creativecommons.org/licenses/by/3.0/
21 | */
22 |
23 | THREE.FilmShader = {
24 |
25 | uniforms: {
26 |
27 | "tDiffuse": { type: "t", value: null },
28 | "time": { type: "f", value: 0.0 },
29 | "nIntensity": { type: "f", value: 0.5 },
30 | "sIntensity": { type: "f", value: 0.05 },
31 | "sCount": { type: "f", value: 4096 },
32 | "grayscale": { type: "i", value: 1 }
33 |
34 | },
35 |
36 | vertexShader: [
37 |
38 | "varying vec2 vUv;",
39 |
40 | "void main() {",
41 |
42 | "vUv = uv;",
43 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
44 |
45 | "}"
46 |
47 | ].join("\n"),
48 |
49 | fragmentShader: [
50 |
51 | // control parameter
52 | "uniform float time;",
53 |
54 | "uniform bool grayscale;",
55 |
56 | // noise effect intensity value (0 = no effect, 1 = full effect)
57 | "uniform float nIntensity;",
58 |
59 | // scanlines effect intensity value (0 = no effect, 1 = full effect)
60 | "uniform float sIntensity;",
61 |
62 | // scanlines effect count value (0 = no effect, 4096 = full effect)
63 | "uniform float sCount;",
64 |
65 | "uniform sampler2D tDiffuse;",
66 |
67 | "varying vec2 vUv;",
68 |
69 | "void main() {",
70 |
71 | // sample the source
72 | "vec4 cTextureScreen = texture2D( tDiffuse, vUv );",
73 |
74 | // make some noise
75 | "float x = vUv.x * vUv.y * time * 1000.0;",
76 | "x = mod( x, 13.0 ) * mod( x, 123.0 );",
77 | "float dx = mod( x, 0.01 );",
78 |
79 | // add noise
80 | "vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx * 100.0, 0.0, 1.0 );",
81 |
82 | // get us a sine and cosine
83 | "vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );",
84 |
85 | // add scanlines
86 | "cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;",
87 |
88 | // interpolate between source and result by intensity
89 | "cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );",
90 |
91 | // convert to grayscale if desired
92 | "if( grayscale ) {",
93 |
94 | "cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );",
95 |
96 | "}",
97 |
98 | "gl_FragColor = vec4( cResult, cTextureScreen.a );",
99 |
100 | "}"
101 |
102 | ].join("\n")
103 |
104 | };
105 |
--------------------------------------------------------------------------------
/js/shaders/FocusShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Focus shader
5 | * based on PaintEffect postprocess from ro.me
6 | * http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js
7 | */
8 |
9 | THREE.FocusShader = {
10 |
11 | uniforms : {
12 |
13 | "tDiffuse": { type: "t", value: null },
14 | "screenWidth": { type: "f", value: 1024 },
15 | "screenHeight": { type: "f", value: 1024 },
16 | "sampleDistance": { type: "f", value: 0.94 },
17 | "waveFactor": { type: "f", value: 0.00125 }
18 |
19 | },
20 |
21 | vertexShader: [
22 |
23 | "varying vec2 vUv;",
24 |
25 | "void main() {",
26 |
27 | "vUv = uv;",
28 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
29 |
30 | "}"
31 |
32 | ].join("\n"),
33 |
34 | fragmentShader: [
35 |
36 | "uniform float screenWidth;",
37 | "uniform float screenHeight;",
38 | "uniform float sampleDistance;",
39 | "uniform float waveFactor;",
40 |
41 | "uniform sampler2D tDiffuse;",
42 |
43 | "varying vec2 vUv;",
44 |
45 | "void main() {",
46 |
47 | "vec4 color, org, tmp, add;",
48 | "float sample_dist, f;",
49 | "vec2 vin;",
50 | "vec2 uv = vUv;",
51 |
52 | "add = color = org = texture2D( tDiffuse, uv );",
53 |
54 | "vin = ( uv - vec2( 0.5 ) ) * vec2( 1.4 );",
55 | "sample_dist = dot( vin, vin ) * 2.0;",
56 |
57 | "f = ( waveFactor * 100.0 + sample_dist ) * sampleDistance * 4.0;",
58 |
59 | "vec2 sampleSize = vec2( 1.0 / screenWidth, 1.0 / screenHeight ) * vec2( f );",
60 |
61 | "add += tmp = texture2D( tDiffuse, uv + vec2( 0.111964, 0.993712 ) * sampleSize );",
62 | "if( tmp.b < color.b ) color = tmp;",
63 |
64 | "add += tmp = texture2D( tDiffuse, uv + vec2( 0.846724, 0.532032 ) * sampleSize );",
65 | "if( tmp.b < color.b ) color = tmp;",
66 |
67 | "add += tmp = texture2D( tDiffuse, uv + vec2( 0.943883, -0.330279 ) * sampleSize );",
68 | "if( tmp.b < color.b ) color = tmp;",
69 |
70 | "add += tmp = texture2D( tDiffuse, uv + vec2( 0.330279, -0.943883 ) * sampleSize );",
71 | "if( tmp.b < color.b ) color = tmp;",
72 |
73 | "add += tmp = texture2D( tDiffuse, uv + vec2( -0.532032, -0.846724 ) * sampleSize );",
74 | "if( tmp.b < color.b ) color = tmp;",
75 |
76 | "add += tmp = texture2D( tDiffuse, uv + vec2( -0.993712, -0.111964 ) * sampleSize );",
77 | "if( tmp.b < color.b ) color = tmp;",
78 |
79 | "add += tmp = texture2D( tDiffuse, uv + vec2( -0.707107, 0.707107 ) * sampleSize );",
80 | "if( tmp.b < color.b ) color = tmp;",
81 |
82 | "color = color * vec4( 2.0 ) - ( add / vec4( 8.0 ) );",
83 | "color = color + ( add / vec4( 8.0 ) - color ) * ( vec4( 1.0 ) - vec4( sample_dist * 0.5 ) );",
84 |
85 | "gl_FragColor = vec4( color.rgb * color.rgb * vec3( 0.95 ) + color.rgb, 1.0 );",
86 |
87 | "}"
88 |
89 |
90 | ].join("\n")
91 | };
92 |
--------------------------------------------------------------------------------
/js/shaders/FresnelShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Based on Nvidia Cg tutorial
5 | */
6 |
7 | THREE.FresnelShader = {
8 |
9 | uniforms: {
10 |
11 | "mRefractionRatio": { type: "f", value: 1.02 },
12 | "mFresnelBias": { type: "f", value: 0.1 },
13 | "mFresnelPower": { type: "f", value: 2.0 },
14 | "mFresnelScale": { type: "f", value: 1.0 },
15 | "tCube": { type: "t", value: null }
16 |
17 | },
18 |
19 | vertexShader: [
20 |
21 | "uniform float mRefractionRatio;",
22 | "uniform float mFresnelBias;",
23 | "uniform float mFresnelScale;",
24 | "uniform float mFresnelPower;",
25 |
26 | "varying vec3 vReflect;",
27 | "varying vec3 vRefract[3];",
28 | "varying float vReflectionFactor;",
29 |
30 | "void main() {",
31 |
32 | "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
33 | "vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
34 |
35 | "vec3 worldNormal = normalize( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
36 |
37 | "vec3 I = worldPosition.xyz - cameraPosition;",
38 |
39 | "vReflect = reflect( I, worldNormal );",
40 | "vRefract[0] = refract( normalize( I ), worldNormal, mRefractionRatio );",
41 | "vRefract[1] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.99 );",
42 | "vRefract[2] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.98 );",
43 | "vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), worldNormal ), mFresnelPower );",
44 |
45 | "gl_Position = projectionMatrix * mvPosition;",
46 |
47 | "}"
48 |
49 | ].join("\n"),
50 |
51 | fragmentShader: [
52 |
53 | "uniform samplerCube tCube;",
54 |
55 | "varying vec3 vReflect;",
56 | "varying vec3 vRefract[3];",
57 | "varying float vReflectionFactor;",
58 |
59 | "void main() {",
60 |
61 | "vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
62 | "vec4 refractedColor = vec4( 1.0 );",
63 |
64 | "refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;",
65 | "refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;",
66 | "refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;",
67 |
68 | "gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );",
69 |
70 | "}"
71 |
72 | ].join("\n")
73 |
74 | };
75 |
--------------------------------------------------------------------------------
/js/shaders/HorizontalBlurShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author zz85 / http://www.lab4games.net/zz85/blog
3 | *
4 | * Two pass Gaussian blur filter (horizontal and vertical blur shaders)
5 | * - described in http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/
6 | * and used in http://www.cake23.de/traveling-wavefronts-lit-up.html
7 | *
8 | * - 9 samples per pass
9 | * - standard deviation 2.7
10 | * - "h" and "v" parameters should be set to "1 / width" and "1 / height"
11 | */
12 |
13 | THREE.HorizontalBlurShader = {
14 |
15 | uniforms: {
16 |
17 | "tDiffuse": { type: "t", value: null },
18 | "h": { type: "f", value: 1.0 / 512.0 }
19 |
20 | },
21 |
22 | vertexShader: [
23 |
24 | "varying vec2 vUv;",
25 |
26 | "void main() {",
27 |
28 | "vUv = uv;",
29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
30 |
31 | "}"
32 |
33 | ].join("\n"),
34 |
35 | fragmentShader: [
36 |
37 | "uniform sampler2D tDiffuse;",
38 | "uniform float h;",
39 |
40 | "varying vec2 vUv;",
41 |
42 | "void main() {",
43 |
44 | "vec4 sum = vec4( 0.0 );",
45 |
46 | "sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * h, vUv.y ) ) * 0.051;",
47 | "sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * h, vUv.y ) ) * 0.0918;",
48 | "sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * h, vUv.y ) ) * 0.12245;",
49 | "sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * h, vUv.y ) ) * 0.1531;",
50 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
51 | "sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * h, vUv.y ) ) * 0.1531;",
52 | "sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * h, vUv.y ) ) * 0.12245;",
53 | "sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * h, vUv.y ) ) * 0.0918;",
54 | "sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * h, vUv.y ) ) * 0.051;",
55 |
56 | "gl_FragColor = sum;",
57 |
58 | "}"
59 |
60 | ].join("\n")
61 |
62 | };
63 |
--------------------------------------------------------------------------------
/js/shaders/HorizontalTiltShiftShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Simple fake tilt-shift effect, modulating two pass Gaussian blur (see above) by vertical position
5 | *
6 | * - 9 samples per pass
7 | * - standard deviation 2.7
8 | * - "h" and "v" parameters should be set to "1 / width" and "1 / height"
9 | * - "r" parameter control where "focused" horizontal line lies
10 | */
11 |
12 | THREE.HorizontalTiltShiftShader = {
13 |
14 | uniforms: {
15 |
16 | "tDiffuse": { type: "t", value: null },
17 | "h": { type: "f", value: 1.0 / 512.0 },
18 | "r": { type: "f", value: 0.35 }
19 |
20 | },
21 |
22 | vertexShader: [
23 |
24 | "varying vec2 vUv;",
25 |
26 | "void main() {",
27 |
28 | "vUv = uv;",
29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
30 |
31 | "}"
32 |
33 | ].join("\n"),
34 |
35 | fragmentShader: [
36 |
37 | "uniform sampler2D tDiffuse;",
38 | "uniform float h;",
39 | "uniform float r;",
40 |
41 | "varying vec2 vUv;",
42 |
43 | "void main() {",
44 |
45 | "vec4 sum = vec4( 0.0 );",
46 |
47 | "float hh = h * abs( r - vUv.y );",
48 |
49 | "sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * hh, vUv.y ) ) * 0.051;",
50 | "sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * hh, vUv.y ) ) * 0.0918;",
51 | "sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * hh, vUv.y ) ) * 0.12245;",
52 | "sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * hh, vUv.y ) ) * 0.1531;",
53 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
54 | "sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * hh, vUv.y ) ) * 0.1531;",
55 | "sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * hh, vUv.y ) ) * 0.12245;",
56 | "sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * hh, vUv.y ) ) * 0.0918;",
57 | "sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * hh, vUv.y ) ) * 0.051;",
58 |
59 | "gl_FragColor = sum;",
60 |
61 | "}"
62 |
63 | ].join("\n")
64 |
65 | };
66 |
--------------------------------------------------------------------------------
/js/shaders/HueSaturationShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author tapio / http://tapio.github.com/
3 | *
4 | * Hue and saturation adjustment
5 | * https://github.com/evanw/glfx.js
6 | * hue: -1 to 1 (-1 is 180 degrees in the negative direction, 0 is no change, etc.
7 | * saturation: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast)
8 | */
9 |
10 | THREE.HueSaturationShader = {
11 |
12 | uniforms: {
13 |
14 | "tDiffuse": { type: "t", value: null },
15 | "hue": { type: "f", value: 0 },
16 | "saturation": { type: "f", value: 0 }
17 |
18 | },
19 |
20 | vertexShader: [
21 |
22 | "varying vec2 vUv;",
23 |
24 | "void main() {",
25 |
26 | "vUv = uv;",
27 |
28 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
29 |
30 | "}"
31 |
32 | ].join("\n"),
33 |
34 | fragmentShader: [
35 |
36 | "uniform sampler2D tDiffuse;",
37 | "uniform float hue;",
38 | "uniform float saturation;",
39 |
40 | "varying vec2 vUv;",
41 |
42 | "void main() {",
43 |
44 | "gl_FragColor = texture2D( tDiffuse, vUv );",
45 |
46 | // hue
47 | "float angle = hue * 3.14159265;",
48 | "float s = sin(angle), c = cos(angle);",
49 | "vec3 weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + 1.0) / 3.0;",
50 | "float len = length(gl_FragColor.rgb);",
51 | "gl_FragColor.rgb = vec3(",
52 | "dot(gl_FragColor.rgb, weights.xyz),",
53 | "dot(gl_FragColor.rgb, weights.zxy),",
54 | "dot(gl_FragColor.rgb, weights.yzx)",
55 | ");",
56 |
57 | // saturation
58 | "float average = (gl_FragColor.r + gl_FragColor.g + gl_FragColor.b) / 3.0;",
59 | "if (saturation > 0.0) {",
60 | "gl_FragColor.rgb += (average - gl_FragColor.rgb) * (1.0 - 1.0 / (1.001 - saturation));",
61 | "} else {",
62 | "gl_FragColor.rgb += (average - gl_FragColor.rgb) * (-saturation);",
63 | "}",
64 |
65 | "}"
66 |
67 | ].join("\n")
68 |
69 | };
70 |
--------------------------------------------------------------------------------
/js/shaders/KaleidoShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author felixturner / http://airtight.cc/
3 | *
4 | * Kaleidoscope Shader
5 | * Radial reflection around center point
6 | * Ported from: http://pixelshaders.com/editor/
7 | * by Toby Schachman / http://tobyschachman.com/
8 | *
9 | * sides: number of reflections
10 | * angle: initial angle in radians
11 | */
12 |
13 | THREE.KaleidoShader = {
14 |
15 | uniforms: {
16 |
17 | "tDiffuse": { type: "t", value: null },
18 | "sides": { type: "f", value: 6.0 },
19 | "angle": { type: "f", value: 0.0 }
20 |
21 | },
22 |
23 | vertexShader: [
24 |
25 | "varying vec2 vUv;",
26 |
27 | "void main() {",
28 |
29 | "vUv = uv;",
30 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
31 |
32 | "}"
33 |
34 | ].join("\n"),
35 |
36 | fragmentShader: [
37 |
38 | "uniform sampler2D tDiffuse;",
39 | "uniform float sides;",
40 | "uniform float angle;",
41 |
42 | "varying vec2 vUv;",
43 |
44 | "void main() {",
45 |
46 | "vec2 p = vUv - 0.5;",
47 | "float r = length(p);",
48 | "float a = atan(p.y, p.x) + angle;",
49 | "float tau = 2. * 3.1416 ;",
50 | "a = mod(a, tau/sides);",
51 | "a = abs(a - tau/sides/2.) ;",
52 | "p = r * vec2(cos(a), sin(a));",
53 | "vec4 color = texture2D(tDiffuse, p + 0.5);",
54 | "gl_FragColor = color;",
55 |
56 | "}"
57 |
58 | ].join("\n")
59 |
60 | };
61 |
--------------------------------------------------------------------------------
/js/shaders/LuminosityShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Luminosity
5 | * http://en.wikipedia.org/wiki/Luminosity
6 | */
7 |
8 | THREE.LuminosityShader = {
9 |
10 | uniforms: {
11 |
12 | "tDiffuse": { type: "t", value: null }
13 |
14 | },
15 |
16 | vertexShader: [
17 |
18 | "varying vec2 vUv;",
19 |
20 | "void main() {",
21 |
22 | "vUv = uv;",
23 |
24 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
25 |
26 | "}"
27 |
28 | ].join("\n"),
29 |
30 | fragmentShader: [
31 |
32 | "uniform sampler2D tDiffuse;",
33 |
34 | "varying vec2 vUv;",
35 |
36 | "void main() {",
37 |
38 | "vec4 texel = texture2D( tDiffuse, vUv );",
39 |
40 | "vec3 luma = vec3( 0.299, 0.587, 0.114 );",
41 |
42 | "float v = dot( texel.xyz, luma );",
43 |
44 | "gl_FragColor = vec4( v, v, v, texel.w );",
45 |
46 | "}"
47 |
48 | ].join("\n")
49 |
50 | };
51 |
--------------------------------------------------------------------------------
/js/shaders/MirrorShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author felixturner / http://airtight.cc/
3 | *
4 | * Mirror Shader
5 | * Copies half the input to the other half
6 | *
7 | * side: side of input to mirror (0 = left, 1 = right, 2 = top, 3 = bottom)
8 | */
9 |
10 | THREE.MirrorShader = {
11 |
12 | uniforms: {
13 |
14 | "tDiffuse": { type: "t", value: null },
15 | "side": { type: "i", value: 1 }
16 |
17 | },
18 |
19 | vertexShader: [
20 |
21 | "varying vec2 vUv;",
22 |
23 | "void main() {",
24 |
25 | "vUv = uv;",
26 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
27 |
28 | "}"
29 |
30 | ].join("\n"),
31 |
32 | fragmentShader: [
33 |
34 | "uniform sampler2D tDiffuse;",
35 | "uniform int side;",
36 |
37 | "varying vec2 vUv;",
38 |
39 | "void main() {",
40 |
41 | "vec2 p = vUv;",
42 | "if (side == 0){",
43 | "if (p.x > 0.5) p.x = 1.0 - p.x;",
44 | "}else if (side == 1){",
45 | "if (p.x < 0.5) p.x = 1.0 - p.x;",
46 | "}else if (side == 2){",
47 | "if (p.y < 0.5) p.y = 1.0 - p.y;",
48 | "}else if (side == 3){",
49 | "if (p.y > 0.5) p.y = 1.0 - p.y;",
50 | "} ",
51 | "vec4 color = texture2D(tDiffuse, p);",
52 | "gl_FragColor = color;",
53 |
54 | "}"
55 |
56 | ].join("\n")
57 |
58 | };
59 |
--------------------------------------------------------------------------------
/js/shaders/NormalMapShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Normal map shader
5 | * - compute normals from heightmap
6 | */
7 |
8 | THREE.NormalMapShader = {
9 |
10 | uniforms: {
11 |
12 | "heightMap": { type: "t", value: null },
13 | "resolution": { type: "v2", value: new THREE.Vector2( 512, 512 ) },
14 | "scale": { type: "v2", value: new THREE.Vector2( 1, 1 ) },
15 | "height": { type: "f", value: 0.05 }
16 |
17 | },
18 |
19 | vertexShader: [
20 |
21 | "varying vec2 vUv;",
22 |
23 | "void main() {",
24 |
25 | "vUv = uv;",
26 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
27 |
28 | "}"
29 |
30 | ].join("\n"),
31 |
32 | fragmentShader: [
33 |
34 | "uniform float height;",
35 | "uniform vec2 resolution;",
36 | "uniform sampler2D heightMap;",
37 |
38 | "varying vec2 vUv;",
39 |
40 | "void main() {",
41 |
42 | "float val = texture2D( heightMap, vUv ).x;",
43 |
44 | "float valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;",
45 | "float valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;",
46 |
47 | "gl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height ) ) + 0.5 ), 1.0 );",
48 |
49 | "}"
50 |
51 | ].join("\n")
52 |
53 | };
54 |
--------------------------------------------------------------------------------
/js/shaders/RGBShiftShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author felixturner / http://airtight.cc/
3 | *
4 | * RGB Shift Shader
5 | * Shifts red and blue channels from center in opposite directions
6 | * Ported from http://kriss.cx/tom/2009/05/rgb-shift/
7 | * by Tom Butterworth / http://kriss.cx/tom/
8 | *
9 | * amount: shift distance (1 is width of input)
10 | * angle: shift angle in radians
11 | */
12 |
13 | THREE.RGBShiftShader = {
14 |
15 | uniforms: {
16 |
17 | "tDiffuse": { type: "t", value: null },
18 | "amount": { type: "f", value: 0.005 },
19 | "angle": { type: "f", value: 0.0 }
20 |
21 | },
22 |
23 | vertexShader: [
24 |
25 | "varying vec2 vUv;",
26 |
27 | "void main() {",
28 |
29 | "vUv = uv;",
30 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
31 |
32 | "}"
33 |
34 | ].join("\n"),
35 |
36 | fragmentShader: [
37 |
38 | "uniform sampler2D tDiffuse;",
39 | "uniform float amount;",
40 | "uniform float angle;",
41 |
42 | "varying vec2 vUv;",
43 |
44 | "void main() {",
45 |
46 | "vec2 offset = amount * vec2( cos(angle), sin(angle));",
47 | "vec4 cr = texture2D(tDiffuse, vUv + offset);",
48 | "vec4 cga = texture2D(tDiffuse, vUv);",
49 | "vec4 cb = texture2D(tDiffuse, vUv - offset);",
50 | "gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);",
51 |
52 | "}"
53 |
54 | ].join("\n")
55 |
56 | };
57 |
--------------------------------------------------------------------------------
/js/shaders/SepiaShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Sepia tone shader
5 | * based on glfx.js sepia shader
6 | * https://github.com/evanw/glfx.js
7 | */
8 |
9 | THREE.SepiaShader = {
10 |
11 | uniforms: {
12 |
13 | "tDiffuse": { type: "t", value: null },
14 | "amount": { type: "f", value: 1.0 }
15 |
16 | },
17 |
18 | vertexShader: [
19 |
20 | "varying vec2 vUv;",
21 |
22 | "void main() {",
23 |
24 | "vUv = uv;",
25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
26 |
27 | "}"
28 |
29 | ].join("\n"),
30 |
31 | fragmentShader: [
32 |
33 | "uniform float amount;",
34 |
35 | "uniform sampler2D tDiffuse;",
36 |
37 | "varying vec2 vUv;",
38 |
39 | "void main() {",
40 |
41 | "vec4 color = texture2D( tDiffuse, vUv );",
42 | "vec3 c = color.rgb;",
43 |
44 | "color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );",
45 | "color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );",
46 | "color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );",
47 |
48 | "gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );",
49 |
50 | "}"
51 |
52 | ].join("\n")
53 |
54 | };
55 |
--------------------------------------------------------------------------------
/js/shaders/TechnicolorShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author flimshaw / http://charliehoey.com
3 | *
4 | * Technicolor Shader
5 | * Simulates the look of the two-strip technicolor process popular in early 20th century films.
6 | * More historical info here: http://www.widescreenmuseum.com/oldcolor/technicolor1.htm
7 | * Demo here: http://charliehoey.com/technicolor_shader/shader_test.html
8 | */
9 |
10 | THREE.TechnicolorShader = {
11 |
12 | uniforms: {
13 |
14 | "tDiffuse": { type: "t", value: null },
15 |
16 | },
17 |
18 | vertexShader: [
19 |
20 | "varying vec2 vUv;",
21 |
22 | "void main() {",
23 |
24 | "vUv = uv;",
25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
26 |
27 | "}"
28 |
29 | ].join("\n"),
30 |
31 | fragmentShader: [
32 |
33 | "uniform sampler2D tDiffuse;",
34 | "varying vec2 vUv;",
35 |
36 | "void main() {",
37 |
38 | "vec4 tex = texture2D( tDiffuse, vec2( vUv.x, vUv.y ) );",
39 | "vec4 newTex = vec4(tex.r, (tex.g + tex.b) * .5, (tex.g + tex.b) * .5, 1.0);",
40 |
41 | "gl_FragColor = newTex;",
42 |
43 | "}"
44 |
45 | ].join("\n")
46 |
47 | };
48 |
--------------------------------------------------------------------------------
/js/shaders/TestShader.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 |
3 | uniforms: {
4 |
5 | "tDiffuse": { type: "t", value: null },
6 | "opacity": { type: "f", value: 1.0 }
7 |
8 | },
9 |
10 | vertexShader: [
11 |
12 | "varying vec2 vUv;",
13 |
14 | "void main() {",
15 |
16 | "vUv = uv;",
17 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
18 |
19 | "}"
20 |
21 | ].join("\n"),
22 |
23 | fragmentShader: [
24 |
25 | "uniform float opacity;",
26 |
27 | "uniform sampler2D tDiffuse;",
28 |
29 | "varying vec2 vUv;",
30 |
31 | "void main() {",
32 |
33 | "vec4 texel = texture2D( tDiffuse, vUv );",
34 | "gl_FragColor = opacity * texel * vec4(0.0, 1.0, 0.0, 1.0);",
35 |
36 | "}"
37 |
38 | ].join("\n")
39 |
40 | };
--------------------------------------------------------------------------------
/js/shaders/TriangleBlurShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author zz85 / http://www.lab4games.net/zz85/blog
3 | *
4 | * Triangle blur shader
5 | * based on glfx.js triangle blur shader
6 | * https://github.com/evanw/glfx.js
7 | *
8 | * A basic blur filter, which convolves the image with a
9 | * pyramid filter. The pyramid filter is separable and is applied as two
10 | * perpendicular triangle filters.
11 | */
12 |
13 | THREE.TriangleBlurShader = {
14 |
15 | uniforms : {
16 |
17 | "texture": { type: "t", value: null },
18 | "delta": { type: "v2", value:new THREE.Vector2( 1, 1 ) }
19 |
20 | },
21 |
22 | vertexShader: [
23 |
24 | "varying vec2 vUv;",
25 |
26 | "void main() {",
27 |
28 | "vUv = uv;",
29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
30 |
31 | "}"
32 |
33 | ].join("\n"),
34 |
35 | fragmentShader: [
36 |
37 | "#define ITERATIONS 10.0",
38 |
39 | "uniform sampler2D texture;",
40 | "uniform vec2 delta;",
41 |
42 | "varying vec2 vUv;",
43 |
44 | "float random( vec3 scale, float seed ) {",
45 |
46 | // use the fragment position for a different seed per-pixel
47 |
48 | "return fract( sin( dot( gl_FragCoord.xyz + seed, scale ) ) * 43758.5453 + seed );",
49 |
50 | "}",
51 |
52 | "void main() {",
53 |
54 | "vec4 color = vec4( 0.0 );",
55 |
56 | "float total = 0.0;",
57 |
58 | // randomize the lookup values to hide the fixed number of samples
59 |
60 | "float offset = random( vec3( 12.9898, 78.233, 151.7182 ), 0.0 );",
61 |
62 | "for ( float t = -ITERATIONS; t <= ITERATIONS; t ++ ) {",
63 |
64 | "float percent = ( t + offset - 0.5 ) / ITERATIONS;",
65 | "float weight = 1.0 - abs( percent );",
66 |
67 | "color += texture2D( texture, vUv + delta * percent ) * weight;",
68 | "total += weight;",
69 |
70 | "}",
71 |
72 | "gl_FragColor = color / total;",
73 |
74 | "}"
75 |
76 | ].join("\n")
77 |
78 | };
79 |
--------------------------------------------------------------------------------
/js/shaders/UnpackDepthRGBAShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Unpack RGBA depth shader
5 | * - show RGBA encoded depth as monochrome color
6 | */
7 |
8 | THREE.UnpackDepthRGBAShader = {
9 |
10 | uniforms: {
11 |
12 | "tDiffuse": { type: "t", value: null },
13 | "opacity": { type: "f", value: 1.0 }
14 |
15 | },
16 |
17 | vertexShader: [
18 |
19 | "varying vec2 vUv;",
20 |
21 | "void main() {",
22 |
23 | "vUv = uv;",
24 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
25 |
26 | "}"
27 |
28 | ].join("\n"),
29 |
30 | fragmentShader: [
31 |
32 | "uniform float opacity;",
33 |
34 | "uniform sampler2D tDiffuse;",
35 |
36 | "varying vec2 vUv;",
37 |
38 | // RGBA depth
39 |
40 | "float unpackDepth( const in vec4 rgba_depth ) {",
41 |
42 | "const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
43 | "float depth = dot( rgba_depth, bit_shift );",
44 | "return depth;",
45 |
46 | "}",
47 |
48 | "void main() {",
49 |
50 | "float depth = 1.0 - unpackDepth( texture2D( tDiffuse, vUv ) );",
51 | "gl_FragColor = opacity * vec4( vec3( depth ), 1.0 );",
52 |
53 | "}"
54 |
55 | ].join("\n")
56 |
57 | };
58 |
--------------------------------------------------------------------------------
/js/shaders/VerticalBlurShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author zz85 / http://www.lab4games.net/zz85/blog
3 | *
4 | * Two pass Gaussian blur filter (horizontal and vertical blur shaders)
5 | * - described in http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/
6 | * and used in http://www.cake23.de/traveling-wavefronts-lit-up.html
7 | *
8 | * - 9 samples per pass
9 | * - standard deviation 2.7
10 | * - "h" and "v" parameters should be set to "1 / width" and "1 / height"
11 | */
12 |
13 | THREE.VerticalBlurShader = {
14 |
15 | uniforms: {
16 |
17 | "tDiffuse": { type: "t", value: null },
18 | "v": { type: "f", value: 1.0 / 512.0 }
19 |
20 | },
21 |
22 | vertexShader: [
23 |
24 | "varying vec2 vUv;",
25 |
26 | "void main() {",
27 |
28 | "vUv = uv;",
29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
30 |
31 | "}"
32 |
33 | ].join("\n"),
34 |
35 | fragmentShader: [
36 |
37 | "uniform sampler2D tDiffuse;",
38 | "uniform float v;",
39 |
40 | "varying vec2 vUv;",
41 |
42 | "void main() {",
43 |
44 | "vec4 sum = vec4( 0.0 );",
45 |
46 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;",
47 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;",
48 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;",
49 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;",
50 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
51 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;",
52 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;",
53 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;",
54 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;",
55 |
56 | "gl_FragColor = sum;",
57 |
58 | "}"
59 |
60 | ].join("\n")
61 |
62 | };
63 |
--------------------------------------------------------------------------------
/js/shaders/VerticalTiltShiftShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Simple fake tilt-shift effect, modulating two pass Gaussian blur (see above) by vertical position
5 | *
6 | * - 9 samples per pass
7 | * - standard deviation 2.7
8 | * - "h" and "v" parameters should be set to "1 / width" and "1 / height"
9 | * - "r" parameter control where "focused" horizontal line lies
10 | */
11 |
12 | THREE.VerticalTiltShiftShader = {
13 |
14 | uniforms: {
15 |
16 | "tDiffuse": { type: "t", value: null },
17 | "v": { type: "f", value: 1.0 / 512.0 },
18 | "r": { type: "f", value: 0.35 }
19 |
20 | },
21 |
22 | vertexShader: [
23 |
24 | "varying vec2 vUv;",
25 |
26 | "void main() {",
27 |
28 | "vUv = uv;",
29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
30 |
31 | "}"
32 |
33 | ].join("\n"),
34 |
35 | fragmentShader: [
36 |
37 | "uniform sampler2D tDiffuse;",
38 | "uniform float v;",
39 | "uniform float r;",
40 |
41 | "varying vec2 vUv;",
42 |
43 | "void main() {",
44 |
45 | "vec4 sum = vec4( 0.0 );",
46 |
47 | "float vv = v * abs( r - vUv.y );",
48 |
49 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * vv ) ) * 0.051;",
50 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * vv ) ) * 0.0918;",
51 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * vv ) ) * 0.12245;",
52 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * vv ) ) * 0.1531;",
53 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
54 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * vv ) ) * 0.1531;",
55 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * vv ) ) * 0.12245;",
56 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * vv ) ) * 0.0918;",
57 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * vv ) ) * 0.051;",
58 |
59 | "gl_FragColor = sum;",
60 |
61 | "}"
62 |
63 | ].join("\n")
64 |
65 | };
66 |
--------------------------------------------------------------------------------
/js/shaders/VignetteShader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | *
4 | * Vignette shader
5 | * based on PaintEffect postprocess from ro.me
6 | * http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js
7 | */
8 |
9 | THREE.VignetteShader = {
10 |
11 | uniforms: {
12 |
13 | "tDiffuse": { type: "t", value: null },
14 | "offset": { type: "f", value: 1.0 },
15 | "darkness": { type: "f", value: 1.0 }
16 |
17 | },
18 |
19 | vertexShader: [
20 |
21 | "varying vec2 vUv;",
22 |
23 | "void main() {",
24 |
25 | "vUv = uv;",
26 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
27 |
28 | "}"
29 |
30 | ].join("\n"),
31 |
32 | fragmentShader: [
33 |
34 | "uniform float offset;",
35 | "uniform float darkness;",
36 |
37 | "uniform sampler2D tDiffuse;",
38 |
39 | "varying vec2 vUv;",
40 |
41 | "void main() {",
42 |
43 | // Eskil's vignette
44 |
45 | "vec4 texel = texture2D( tDiffuse, vUv );",
46 | "vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );",
47 | "gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );",
48 |
49 | /*
50 | // alternative version from glfx.js
51 | // this one makes more "dusty" look (as opposed to "burned")
52 |
53 | "vec4 color = texture2D( tDiffuse, vUv );",
54 | "float dist = distance( vUv, vec2( 0.5 ) );",
55 | "color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) );",
56 | "gl_FragColor = color;",
57 | */
58 |
59 | "}"
60 |
61 | ].join("\n")
62 |
63 | };
64 |
--------------------------------------------------------------------------------
/js/sound/Music.js:
--------------------------------------------------------------------------------
1 | var soundcloud = require('soundcloud-badge');
2 | var mute = require('./mute');
3 |
4 | var soundOff = false;
5 |
6 | var audio = null;
7 | var fetchAndPlaySong = null;
8 | var timesCalledSoundcloud = 0;
9 |
10 | var Music = function( poem, properties ) {
11 |
12 | fetchAndPlaySong = function() {
13 |
14 | var currentTime = ++timesCalledSoundcloud;
15 |
16 | soundcloud({
17 |
18 | client_id: '6057c9af862bf245d4c402179e317f52',
19 | song: properties.url,
20 | dark: false,
21 | getFonts: false
22 |
23 | }, function( err, src, data, div ) {
24 |
25 | //Nullify callbacks that are out of order
26 | if( currentTime !== timesCalledSoundcloud ) return;
27 | if( mute.muted() ) {
28 | $('.npm-scb-white').hide();
29 | return;
30 | } else {
31 | $('.npm-scb-white').show();
32 | }
33 |
34 | if( err ) throw err;
35 |
36 | audio = new Audio();
37 | audio.src = src;
38 | audio.play();
39 | audio.loop = true;
40 | audio.volume = properties.volume || 0.6;
41 |
42 | $(audio).on('loadedmetadata', function() {
43 | if( audio ) audio.currentTime = properties.startTime || 0;
44 | });
45 |
46 |
47 | });
48 |
49 | poem.emitter.on('destroy', function() {
50 |
51 | if( audio ) {
52 | audio.pause();
53 | audio = null;
54 | }
55 |
56 | $('.npm-scb-white').remove();
57 |
58 | });
59 |
60 | };
61 |
62 | if( !mute.muted() ) {
63 | fetchAndPlaySong();
64 | fetchAndPlaySong = null;
65 | }
66 |
67 | };
68 |
69 | Music.prototype.muted = false;
70 |
71 | mute.emitter.on('mute', function muteMusic( e ) {
72 |
73 | if( audio ) audio.pause();
74 |
75 | $('.npm-scb-white').hide();
76 |
77 | });
78 |
79 | mute.emitter.on('unmute', function unmuteMusic( e ) {
80 |
81 | if( audio ) audio.play();
82 |
83 | if( fetchAndPlaySong ) {
84 | fetchAndPlaySong();
85 | fetchAndPlaySong = null;
86 | }
87 |
88 | $('.npm-scb-white').show();
89 |
90 |
91 | });
92 |
93 | module.exports = Music;
--------------------------------------------------------------------------------
/js/sound/mute.js:
--------------------------------------------------------------------------------
1 | var poemMute = require('poem-mute');
2 | var mute = poemMute();
3 | window.mutePrime = mute;
4 | window.mutePrimeEmitter = mute.emitter;
5 |
6 | //Turn on a poem muter
7 | module.exports = mute;
--------------------------------------------------------------------------------
/js/utils/Clock.js:
--------------------------------------------------------------------------------
1 | var Clock = function( autostart ) {
2 |
3 | this.maxDt = 60;
4 | this.minDt = 16;
5 | this.pTime = 0;
6 | this.time = 0;
7 |
8 | if(autostart !== false) {
9 | this.start();
10 | }
11 |
12 | };
13 |
14 | module.exports = Clock;
15 |
16 | Clock.prototype = {
17 |
18 | start : function() {
19 | this.pTime = Date.now();
20 | },
21 |
22 | getDelta : function() {
23 | var now, dt;
24 |
25 | now = Date.now();
26 | dt = now - this.pTime;
27 |
28 | dt = Math.min( dt, this.maxDt );
29 | dt = Math.max( dt, this.minDt );
30 |
31 | this.time += dt;
32 | this.pTime = now;
33 |
34 | return dt;
35 | }
36 |
37 | };
--------------------------------------------------------------------------------
/js/utils/ClosedSplineCurve3.js:
--------------------------------------------------------------------------------
1 | module.exports = THREE.Curve.create(
2 |
3 | function ( points /* array of Vector3 */) {
4 |
5 | this.points = ( points === undefined ) ? [] : points;
6 |
7 | },
8 |
9 | function ( t, vector ) {
10 |
11 | var points = this.points;
12 | var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
13 |
14 | var intPoint = Math.floor( point );
15 | var weight = point - intPoint;
16 |
17 | intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
18 |
19 | var point0 = points[ ( intPoint - 1 ) % points.length ];
20 | var point1 = points[ ( intPoint ) % points.length ];
21 | var point2 = points[ ( intPoint + 1 ) % points.length ];
22 | var point3 = points[ ( intPoint + 2 ) % points.length ];
23 |
24 | if( !vector ) {
25 | vector = new THREE.Vector3();
26 | }
27 |
28 | vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
29 | vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
30 | vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
31 |
32 | return vector;
33 |
34 | }
35 |
36 | );
--------------------------------------------------------------------------------
/js/utils/EventDispatcher.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author mrdoob / http://mrdoob.com/
3 | *
4 | * Modifications: Greg Tatum
5 | *
6 | * usage:
7 | *
8 | * EventDispatcher.prototype.apply( MyObject.prototype );
9 | *
10 | * MyObject.dispatch({
11 | * type: "click",
12 | * datum1: "foo",
13 | * datum2: "bar"
14 | * });
15 | *
16 | * MyObject.on( "click", function( event ) {
17 | * event.datum1; //Foo
18 | * event.target; //MyObject
19 | * });
20 | *
21 | *
22 | */
23 |
24 | var EventDispatcher = function () {};
25 |
26 | EventDispatcher.prototype = {
27 |
28 | constructor: EventDispatcher,
29 |
30 | apply: function ( object ) {
31 |
32 | object.on = EventDispatcher.prototype.on;
33 | object.hasEventListener = EventDispatcher.prototype.hasEventListener;
34 | object.off = EventDispatcher.prototype.off;
35 | object.dispatch = EventDispatcher.prototype.dispatch;
36 |
37 | },
38 |
39 | on: function ( type, listener ) {
40 |
41 | if ( this._listeners === undefined ) this._listeners = {};
42 |
43 | var listeners = this._listeners;
44 |
45 | if ( listeners[ type ] === undefined ) {
46 |
47 | listeners[ type ] = [];
48 |
49 | }
50 |
51 | if ( listeners[ type ].indexOf( listener ) === - 1 ) {
52 |
53 | listeners[ type ].push( listener );
54 |
55 | }
56 |
57 | return listener;
58 |
59 | },
60 |
61 | hasEventListener: function ( type, listener ) {
62 |
63 | if ( this._listeners === undefined ) return false;
64 |
65 | var listeners = this._listeners;
66 |
67 | if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
68 |
69 | return true;
70 |
71 | }
72 |
73 | return false;
74 |
75 | },
76 |
77 | off: function ( type, listener ) {
78 |
79 | if ( this._listeners === undefined ) return;
80 |
81 | var listeners = this._listeners;
82 | var listenerArray = listeners[ type ];
83 |
84 | if ( listenerArray !== undefined ) {
85 |
86 | var index = listenerArray.indexOf( listener );
87 |
88 | if ( index !== - 1 ) {
89 |
90 | listenerArray.splice( index, 1 );
91 |
92 | }
93 |
94 | }
95 |
96 | },
97 |
98 | dispatch: function ( event ) {
99 |
100 | if ( this._listeners === undefined ) return;
101 |
102 | var listeners = this._listeners;
103 | var listenerArray = listeners[ event.type ];
104 |
105 | if ( listenerArray !== undefined ) {
106 |
107 | event.target = this;
108 |
109 | var array = [];
110 | var length = listenerArray.length;
111 | var i;
112 |
113 | for ( i = 0; i < length; i ++ ) {
114 |
115 | array[ i ] = listenerArray[ i ];
116 |
117 | }
118 |
119 | for ( i = 0; i < length; i ++ ) {
120 |
121 | array[ i ].call( this, event );
122 |
123 | }
124 |
125 | }
126 |
127 | }
128 |
129 | };
130 |
131 | if ( typeof module === 'object' ) {
132 |
133 | module.exports = EventDispatcher;
134 |
135 | }
--------------------------------------------------------------------------------
/js/utils/WebGLDetector.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | * @author mr.doob / http://mrdoob.com/
4 | */
5 |
6 | var Detector = {
7 |
8 | canvas: !! window.CanvasRenderingContext2D,
9 | webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )(),
10 | workers: !! window.Worker,
11 | fileapi: window.File && window.FileReader && window.FileList && window.Blob,
12 |
13 | getWebGLErrorMessage: function () {
14 |
15 | var element = document.createElement( 'div' );
16 | element.id = 'webgl-error-message';
17 | element.style.fontFamily = 'monospace';
18 | element.style.fontSize = '13px';
19 | element.style.fontWeight = 'normal';
20 | element.style.textAlign = 'center';
21 | element.style.background = '#fff';
22 | element.style.color = '#000';
23 | element.style.padding = '1.5em';
24 | element.style.width = '400px';
25 | element.style.margin = '5em auto 0';
26 |
27 | if ( ! this.webgl ) {
28 |
29 | element.innerHTML = window.WebGLRenderingContext ? [
30 | 'Your graphics card does not seem to support WebGL.
',
31 | 'Find out how to get it here.'
32 | ].join( '\n' ) : [
33 | 'Your browser does not seem to support WebGL.
',
34 | 'Find out how to get it here.'
35 | ].join( '\n' );
36 |
37 | }
38 |
39 | return element;
40 |
41 | },
42 |
43 | addGetWebGLMessage: function ( parameters ) {
44 |
45 | var parent, id, element;
46 |
47 | parameters = parameters || {};
48 |
49 | parent = parameters.parent !== undefined ? parameters.parent : document.body;
50 | id = parameters.id !== undefined ? parameters.id : 'oldie';
51 |
52 | element = Detector.getWebGLErrorMessage();
53 | element.id = id;
54 |
55 | parent.appendChild( element );
56 |
57 | }
58 |
59 | };
60 |
61 | // browserify support
62 | if ( typeof module === 'object' ) {
63 |
64 | module.exports = Detector;
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/js/utils/calculateSquaredTextureWidth.js:
--------------------------------------------------------------------------------
1 | var calculateSquaredTextureWidth = function( count ) {
2 | var width = 1;
3 | var i = 0;
4 |
5 | while( width * width < (count / 4) ) {
6 |
7 | i++;
8 | width = Math.pow( 2, i );
9 |
10 | }
11 |
12 | return width;
13 | };
14 |
15 | module.exports = calculateSquaredTextureWidth;
16 |
--------------------------------------------------------------------------------
/js/utils/destroyMesh.js:
--------------------------------------------------------------------------------
1 | module.exports = function destroyMesh( obj ) {
2 | return function() {
3 | if( obj.geometry ) obj.geometry.dispose();
4 | if( obj.material ) obj.material.dispose();
5 | };
6 | };
--------------------------------------------------------------------------------
/js/utils/duplicate-buffer-geometry.js:
--------------------------------------------------------------------------------
1 | function _newBuffer( finalVertCount, itemSize ) {
2 |
3 | var arrayBuffer = new Float32Array( finalVertCount * itemSize )
4 | return new THREE.BufferAttribute( arrayBuffer, itemSize )
5 | }
6 |
7 | function _duplicateBuffer( bufferA, bufferB, vertsPerInstance, n ) {
8 |
9 | var offsetSize = vertsPerInstance * bufferA.itemSize
10 |
11 | for( var i=0; i < n; i++ ) {
12 |
13 | var offset = i * offsetSize
14 |
15 | for( var j = 0 ; j < offsetSize; j++ ) {
16 |
17 | bufferB.array[ offset + j ] = bufferA.array[ j ]
18 | }
19 | }
20 | }
21 |
22 | function _addIndices( geometry, vertsPerInstance, n ) {
23 |
24 | var arrayBuffer = new Float32Array( n * vertsPerInstance )
25 |
26 | for( var i=0; i < n; i++ ) {
27 |
28 | var offset = i * vertsPerInstance
29 |
30 | for( var j=0; j < vertsPerInstance; j++ ) {
31 |
32 | arrayBuffer[ offset + j ] = i
33 | }
34 | }
35 |
36 | var bufferAttribute = new THREE.BufferAttribute( arrayBuffer, 1 )
37 |
38 | geometry.addAttribute( 'attributeIndex', bufferAttribute )
39 | geometry.attributes.attributeIndex.needsUpdate = true
40 | }
41 |
42 | module.exports = function duplicateBufferGeometry( geometry, n ) {
43 |
44 | var positionA = geometry.attributes.position
45 | var normalA = geometry.attributes.normal
46 | var uvA = geometry.attributes.uv
47 |
48 | var vertsPerInstance = positionA.array.length / 3
49 | var finalVertCount = vertsPerInstance * n
50 |
51 | var positionB = _newBuffer( finalVertCount, 3 )
52 | var normalB = _newBuffer( finalVertCount, 3 )
53 | var uvB = _newBuffer( finalVertCount, 2 )
54 |
55 | _duplicateBuffer( positionA, positionB, vertsPerInstance, n )
56 | _duplicateBuffer( normalA, normalB, vertsPerInstance, n )
57 | _duplicateBuffer( uvA, uvB, vertsPerInstance, n )
58 |
59 | geometry.attributes.position = positionB
60 | geometry.attributes.normal = normalB
61 | geometry.attributes.uv = uvB
62 |
63 | _addIndices( geometry, vertsPerInstance, n )
64 |
65 | return geometry
66 | }
--------------------------------------------------------------------------------
/js/utils/gpu-processor/copy-texture.js:
--------------------------------------------------------------------------------
1 | module.exports = function copyTextureFn( renderer ) {
2 |
3 | var camera = new THREE.Camera()
4 | camera.position.z = 1
5 |
6 | var scene = new THREE.Scene()
7 |
8 | var mesh = new THREE.Mesh(
9 | new THREE.PlaneBufferGeometry( 2, 2 ),
10 | new THREE.ShaderMaterial( {
11 |
12 | uniforms: {
13 | resolution: { type: "v2", value: new THREE.Vector2() },
14 | texture: { type: "t", value: null }
15 | },
16 |
17 | vertexShader: `
18 | void main() {
19 | gl_Position = vec4( position, 1.0 );
20 | }
21 | `,
22 |
23 | fragmentShader: `
24 | uniform vec2 resolution;
25 | uniform sampler2D texture;
26 |
27 | void main() {
28 |
29 | vec2 uv = gl_FragCoord.xy / resolution.xy;
30 |
31 | vec4 color = texture2D( texture, uv );
32 |
33 | gl_FragColor = vec4( color.xyz, 1.0 );
34 |
35 | }
36 | `
37 | })
38 | )
39 |
40 | scene.add( mesh )
41 |
42 | var uniforms = mesh.material.uniforms
43 |
44 | return function copyTexture( input, output, textureSideLength ) {
45 |
46 | uniforms.resolution.value.set( textureSideLength, textureSideLength )
47 | uniforms.texture.value = input
48 | renderer.render( scene, camera, output )
49 | }
50 | }
--------------------------------------------------------------------------------
/js/utils/loadImage.js:
--------------------------------------------------------------------------------
1 | var loadImage = function( url, object, key ) {
2 |
3 | return new Promise(function(resolve, reject) {
4 |
5 | var deferred = $.Deferred();
6 | var $img = $("
");
7 | var img = $img[0];
8 |
9 | $img.load(function() {
10 |
11 | if( _.isObject( object ) ) {
12 | object[key] = img;
13 | }
14 |
15 | resolve( img );
16 |
17 | });
18 |
19 | $img.error(function() {
20 | reject( "Could not load image: " + url );
21 | });
22 |
23 | img.src = url;
24 |
25 | });
26 |
27 | };
28 |
29 | module.exports = loadImage;
--------------------------------------------------------------------------------
/js/utils/loadText.js:
--------------------------------------------------------------------------------
1 | var loadText = function( url, object, key ) {
2 |
3 | var promise = new Promise(function(resolve, reject){
4 |
5 | $.ajax(url, {
6 | dataType: "text"
7 | }).then(
8 | function( data ) {
9 |
10 | if( _.isObject( object ) ) {
11 | object[key] = data;
12 | }
13 |
14 | resolve( data );
15 | },
16 | function( error ) {
17 | reject( error );
18 | }
19 | );
20 |
21 | });
22 |
23 | return promise;
24 | };
25 |
26 | module.exports = loadText;
--------------------------------------------------------------------------------
/js/utils/loadTexture.js:
--------------------------------------------------------------------------------
1 | var loadTexture = function( url, object, key ) {
2 |
3 | return new Promise(function(resolve, reject) {
4 |
5 | THREE.ImageUtils.loadTexture( url, undefined, function( texture ) {
6 |
7 | if( _.isObject( object ) ) {
8 | object[key] = texture;
9 | }
10 |
11 | resolve( texture );
12 |
13 | }, reject );
14 |
15 | });
16 |
17 | };
18 |
19 | module.exports = loadTexture;
--------------------------------------------------------------------------------
/js/utils/random.js:
--------------------------------------------------------------------------------
1 | var random = {
2 |
3 | flip : function() {
4 | return Math.random() > 0.5 ? true: false;
5 | },
6 |
7 | range : function(min, max) {
8 | return Math.random() * (max - min) + min;
9 | },
10 |
11 | rangeInt : function(min, max) {
12 | return Math.floor( this.range(min, max + 1) );
13 | },
14 |
15 | rangeLow : function(min, max) {
16 | //More likely to return a low value
17 | return Math.random() * Math.random() * (max - min) + min;
18 | },
19 |
20 | rangeHigh : function(min, max) {
21 | //More likely to return a high value
22 | return (1 - Math.random() * Math.random()) * (max - min) + min;
23 | }
24 |
25 | };
26 |
27 | module.exports = random;
28 |
--------------------------------------------------------------------------------
/js/utils/selectors.js:
--------------------------------------------------------------------------------
1 | var selectors = function( scopeOrSelector, selectors, allowEmptySelections ) {
2 |
3 | var $scope = $( scopeOrSelector );
4 |
5 | return _.reduce( selectors, function( memo, selector, key ) {
6 |
7 | memo[key] = $( selector, $scope );
8 |
9 | if( !allowEmptySelections ) {
10 | if( memo[key].length === 0 ) {
11 | throw new Error("Empty selections are not allowed");
12 | }
13 | }
14 |
15 | return memo;
16 |
17 | }, { "scope" : $scope } );
18 |
19 | };
20 |
21 | module.exports = selectors;
22 |
--------------------------------------------------------------------------------
/js/utils/simplex2.js:
--------------------------------------------------------------------------------
1 | var perlinSimplex = require('perlin-simplex');
2 | var generator = new perlinSimplex();
3 | // generator.noise(x, y)
4 | // generator.noise3d(x, y, z)
5 |
6 | function unitSimplex( x, y ) {
7 | return (generator.noise(x,y) + 1) / 2;
8 | }
9 |
10 | var simplex2 = {
11 |
12 | flip : function( x, y ) {
13 | return generator.noise(x,y) > 0 ? true: false;
14 | },
15 |
16 | range : function( x, y, min, max ) {
17 | return unitSimplex(x,y) * (max - min) + min;
18 | },
19 |
20 | rangeInt : function( x, y, min, max ) {
21 | return Math.floor( this.range(min, max + 1) );
22 | },
23 |
24 | rangeLow : function( x, y, min, max) {
25 | //More likely to return a low value
26 | var r = unitSimplex(x,y);
27 | return r * r * (max - min) + min;
28 | },
29 |
30 | rangeHigh : function( x, y, min, max) {
31 | //More likely to return a high value
32 | var r = unitSimplex(x,y);
33 | return (1 - r * r) * (max - min) + min;
34 | }
35 |
36 | };
37 |
38 | module.exports = simplex2;
39 |
--------------------------------------------------------------------------------
/js/utils/simplex3.js:
--------------------------------------------------------------------------------
1 | var perlinSimplex = require('perlin-simplex');
2 | var generator = new perlinSimplex();
3 |
4 | function unitSimplex( x, y, z ) {
5 | return (generator.noise(x,y,z) + 1) / 2;
6 | }
7 |
8 | var simplex3 = {
9 |
10 | flip : function( x, y, z ) {
11 | return generator.noise3d(x,y,z) > 0 ? true: false;
12 | },
13 |
14 | range : function( x, y, z, min, max ) {
15 | return unitSimplex(x,y,z) * (max - min) + min;
16 | },
17 |
18 | rangeInt : function( x, y, z, min, max ) {
19 | return Math.floor( this.range(min, max + 1) );
20 | },
21 |
22 | rangeLow : function( x, y, z, min, max) {
23 | //More likely to return a low value
24 | var r = unitSimplex(x,y,z);
25 | return r * r * (max - min) + min;
26 | },
27 |
28 | rangeHigh : function( x, y, z, min, max) {
29 | //More likely to return a high value
30 | var r = unitSimplex(x,y,z);
31 | return (1 - r * r) * (max - min) + min;
32 | }
33 |
34 | };
35 |
36 | module.exports = simplex3;
37 |
--------------------------------------------------------------------------------
/js/vendor/StereoEffect.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | * @authod mrdoob / http://mrdoob.com/
4 | * @authod arodic / http://aleksandarrodic.com/
5 | */
6 |
7 | THREE.StereoEffect = function ( renderer ) {
8 |
9 | // API
10 |
11 | this.separation = 3;
12 |
13 | // internals
14 |
15 | var _width, _height;
16 |
17 | var _position = new THREE.Vector3();
18 | var _quaternion = new THREE.Quaternion();
19 | var _scale = new THREE.Vector3();
20 |
21 | var _cameraL = new THREE.PerspectiveCamera();
22 | var _cameraR = new THREE.PerspectiveCamera();
23 |
24 | // initialization
25 |
26 | renderer.autoClear = false;
27 |
28 | this.setSize = function ( width, height ) {
29 |
30 | _width = width / 2;
31 | _height = height;
32 |
33 | renderer.setSize( width, height );
34 |
35 | };
36 |
37 | this.render = function ( scene, camera ) {
38 |
39 | scene.updateMatrixWorld();
40 |
41 | if ( camera.parent === undefined ) camera.updateMatrixWorld();
42 |
43 | camera.matrixWorld.decompose( _position, _quaternion, _scale );
44 |
45 | // left
46 |
47 | _cameraL.fov = camera.fov;
48 | _cameraL.aspect = 0.5 * camera.aspect;
49 | _cameraL.near = camera.near;
50 | _cameraL.far = camera.far;
51 | _cameraL.updateProjectionMatrix();
52 |
53 | _cameraL.position.copy( _position );
54 | _cameraL.quaternion.copy( _quaternion );
55 | _cameraL.translateX( - this.separation );
56 |
57 | // right
58 |
59 | _cameraR.near = camera.near;
60 | _cameraR.far = camera.far;
61 | _cameraR.projectionMatrix = _cameraL.projectionMatrix;
62 |
63 | _cameraR.position.copy( _position );
64 | _cameraR.quaternion.copy( _quaternion );
65 | _cameraR.translateX( this.separation );
66 |
67 | //
68 |
69 | renderer.setViewport( 0, 0, _width * 2, _height );
70 | renderer.clear();
71 |
72 | renderer.setViewport( 0, 0, _width, _height );
73 | renderer.render( scene, _cameraL );
74 |
75 | renderer.setViewport( _width, 0, _width, _height );
76 | renderer.render( scene, _cameraR );
77 |
78 | };
79 |
80 | };
81 |
82 | module.exports = THREE.StereoEffect;
--------------------------------------------------------------------------------
/js/vendor/WebGLDetector.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @author alteredq / http://alteredqualia.com/
3 | * @author mr.doob / http://mrdoob.com/
4 | */
5 |
6 | var Detector = {
7 |
8 | canvas: !! window.CanvasRenderingContext2D,
9 | webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )(),
10 | workers: !! window.Worker,
11 | fileapi: window.File && window.FileReader && window.FileList && window.Blob,
12 |
13 | getWebGLErrorMessage: function () {
14 |
15 | var element = document.createElement( 'div' );
16 | element.id = 'webgl-error-message';
17 | element.style.fontFamily = 'monospace';
18 | element.style.fontSize = '13px';
19 | element.style.fontWeight = 'normal';
20 | element.style.textAlign = 'center';
21 | element.style.background = '#fff';
22 | element.style.color = '#000';
23 | element.style.padding = '1.5em';
24 | element.style.width = '400px';
25 | element.style.margin = '5em auto 0';
26 |
27 | if ( ! this.webgl ) {
28 |
29 | element.innerHTML = window.WebGLRenderingContext ? [
30 | 'Your graphics card does not seem to support WebGL.
',
31 | 'Find out how to get it here.'
32 | ].join( '\n' ) : [
33 | 'Your browser does not seem to support WebGL.
',
34 | 'Find out how to get it here.'
35 | ].join( '\n' );
36 |
37 | }
38 |
39 | return element;
40 |
41 | },
42 |
43 | addGetWebGLMessage: function ( parameters ) {
44 |
45 | var parent, id, element;
46 |
47 | parameters = parameters || {};
48 |
49 | parent = parameters.parent !== undefined ? parameters.parent : document.body;
50 | id = parameters.id !== undefined ? parameters.id : 'oldie';
51 |
52 | element = Detector.getWebGLErrorMessage();
53 | element.id = id;
54 |
55 | parent.appendChild( element );
56 |
57 | }
58 |
59 | };
60 |
61 | // browserify support
62 | if ( typeof module === 'object' ) {
63 |
64 | module.exports = Detector;
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/manifests/blobs.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "Blobs",
3 | description : "Raycasting",
4 | order : 3,
5 | config : {
6 | camera : {},
7 | },
8 | components : {
9 | renderer : { function : require('../js/renderers/basic-renderer') },
10 | controls : {
11 | construct: require("../js/components/cameras/Controls"),
12 | },
13 | mouse : {
14 | function: require('../js/components/hids/mouse-tracker')
15 | },
16 | grid : {
17 | construct: require("../js/demos/Grid"),
18 | },
19 | blobs : {
20 | function: require('../js/components/ambiance/blobs/blobs')
21 | }
22 | }
23 | };
--------------------------------------------------------------------------------
/manifests/carbonDioxideEarth.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "Carbon Dioxide Earth",
3 | description : "Mapping NASA Data",
4 | order : 0,
5 | config : {
6 | camera : {
7 | x : -400,
8 | far : 3000
9 | }
10 | },
11 | components : {
12 | renderer : { function : require('../js/renderers/basic-renderer') },
13 | sphere : {
14 | construct: require("../js/demos/Earth"),
15 | properties: {}
16 | },
17 | controls : {
18 | construct: require("../js/components/cameras/Controls"),
19 | properties: {
20 | minDistance : 500,
21 | maxDistance : 1000,
22 | zoomSpeed : 0.1,
23 | autoRotate : true,
24 | autoRotateSpeed : 0.2
25 | }
26 | },
27 | info : {
28 | construct: require("../js/components/Info"),
29 | properties : {
30 | documentTitle : "Earth's CO2 – a Three.js Visualization adapted by Greg Tatum",
31 | title : "Earth's CO2",
32 | subtitle : "3d Visualisation of a map from NASA",
33 | appendCredits : "
Map visualization by NASA's Goddard Space Flight Center",
34 | titleCss : { "font-size": "3.35em" },
35 | subtitleCss : { "font-size": "0.7em" },
36 | showArrowNext : true
37 | }
38 | },
39 | stars : {
40 | construct: require("../js/components/Stars"),
41 | },
42 | // stats : {
43 | // construct: require("../js/components/utils/Stats")
44 | // },
45 | lights : {
46 | construct: require("../js/components/lights/TrackCameraLights")
47 | }
48 | }
49 | };
--------------------------------------------------------------------------------
/manifests/cubic.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "Cubic",
3 | description : "An Cubican Experiment",
4 | order : 0,
5 | config : {
6 | camera : {
7 | x : 0,
8 | z: 500,
9 | near : 0.1,
10 | fov : 40
11 | }
12 | },
13 | components : {
14 | renderer : { function : require('../js/renderers/effects-renderer') },
15 | restrictedCamera : {
16 | construct: require("../js/components/cameras/RestrictedCamera"),
17 | },
18 | wireTerrain : {
19 | construct: require("../js/demos/wire-terrain/terrain"),
20 | properties: {
21 | positionY: -250
22 | }
23 | },
24 | particles : {
25 | function: require('../js/components/ambiance/particles/particles'),
26 | },
27 | music : {
28 | construct: require("../js/sound/Music"),
29 | properties: {
30 | url: "https://soundcloud.com/cabbibo/that-was-just-stupidly"
31 | }
32 | },
33 | dragScroll : {
34 | function: require('../js/components/utils/drag-scroll')
35 | },
36 | sky: {
37 | function: require('../js/components/ambiance/Sky'),
38 | properties : {
39 | width : 50
40 | }
41 | },
42 | }
43 | };
--------------------------------------------------------------------------------
/manifests/endlessTerrain.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "Endless Terrain",
3 | description : "An ever-repeating environment",
4 | order : 0,
5 | config : {
6 | camera : {
7 | x : 0,
8 | z: 500,
9 | near : 0.1,
10 | fov : 40
11 | }
12 | },
13 | components : {
14 | renderer : { function : require('../js/renderers/effects-renderer') },
15 | restrictedCamera : {
16 | construct: require("../js/components/cameras/RestrictedCamera"),
17 | },
18 | endlessTerrain : {
19 | construct: require("../js/demos/EndlessTerrain/endless"),
20 | properties: {
21 | positionY: -250
22 | }
23 | },
24 | credits : {
25 | function : require('../js/demos/EndlessTerrain/credits')
26 | },
27 | particles : {
28 | function: require('../js/components/ambiance/particles/particles'),
29 | },
30 | cloudsTop : {
31 | construct: require("../js/components/ambiance/Clouds"),
32 | properties: {
33 | height: 200,
34 | rotation: Math.PI / 2
35 | }
36 | },
37 | // music : {
38 | // construct: require("../js/sound/Music"),
39 | // properties: {
40 | // url: "https://soundcloud.com/synaptyx/mech-attack"
41 | // }
42 | // },
43 | animator : {
44 | function: require('../js/components/animator'),
45 | properties: require('../js/demos/EndlessTerrain/keyframes.js')
46 | },
47 | // stats : {
48 | // construct: require("../js/components/utils/Stats")
49 | // }
50 | }
51 | };
--------------------------------------------------------------------------------
/manifests/fbo-positioning.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "Gpu Processor Example",
3 | description : "Positioning stored in a frame buffer",
4 | order : 0,
5 | config : {
6 | camera : {
7 | x : -300,
8 | near : 0.1,
9 | far : 5000,
10 | fov : 40
11 | }
12 | },
13 | components : {
14 | renderer : { function : require('../js/renderers/basic-renderer') },
15 | controls : { construct: require("../js/components/cameras/Controls") },
16 | // grid : { construct: require("../js/demos/Grid") },
17 | fboPositioning : { function: require('../js/components/fbo-positioning/fbo') },
18 | }
19 | };
--------------------------------------------------------------------------------
/manifests/index.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "light-beams" : require("./light-beams"),
3 | cubic : require("./cubic"),
4 | postprocessing : require("./postprocessing"),
5 | blobs : require("./blobs"),
6 | meshGroupBoxDemo : require("./meshGroupBoxDemo"),
7 | carbonDioxideEarth : require("./carbonDioxideEarth"),
8 | endlessTerrain : require("./endlessTerrain"),
9 | tetrahedra : require("./tetrahedra"),
10 | sineGravityCloud : require("./sineGravityCloud"),
11 | vr : require("./vr"),
12 | "fbo-positioning" : require("./fbo-positioning"),
13 | }
14 |
15 | // Legacy:
16 | // uniformPositionalMatrices : require("./uniformPositionalMatrices"),
17 | // texturePositionalMatrices : require("./texturePositionalMatrices"),
18 |
--------------------------------------------------------------------------------
/manifests/light-beams.js:
--------------------------------------------------------------------------------
1 | var LightBeam = require('../js/components/ambiance/light-beam/light-beam')
2 |
3 | module.exports = {
4 | name : "Light Beams",
5 | description : "Atmospheric Lighting",
6 | order : 0,
7 | config : {
8 | camera : {
9 | x : 0,
10 | z: 500,
11 | near : 0.1,
12 | fov : 40
13 | }
14 | },
15 | components : {
16 | renderer : { function : require('../js/renderers/basic-renderer') },
17 | // renderer : { function : require('../js/renderers/effects-renderer') },
18 | controls : { construct: require("../js/components/cameras/Controls") },
19 | // restrictedCamera : {
20 | // construct: require("../js/components/cameras/RestrictedCamera"),
21 | // },
22 | lightBeam1 : {
23 | function : LightBeam,
24 | properties: {
25 | position: [100,-150,0],
26 | color: 0xaa6611,
27 | lightLength: 200,
28 | }
29 | },
30 | lightBeam2 : {
31 | function : LightBeam,
32 | properties: {
33 | position: [100,-150,0],
34 | color: 0xcc4411,
35 | lightLength: 300,
36 | }
37 | },
38 | lightBeam4 : {
39 | function : LightBeam,
40 | properties: {
41 | position: [100,-150,0],
42 | color: 0xff1111,
43 | lightLength: 250,
44 | }
45 | },
46 | lightBeam3 : {
47 | function : LightBeam,
48 | properties: {
49 | position: [100,-150,0],
50 | color: 0xee2211,
51 | lightLength: 200,
52 | }
53 | },
54 |
55 |
56 | lightLeftBeam1 : {
57 | function : LightBeam,
58 | properties: {
59 | position: [-100,-150,0],
60 | color: 0x11aa66,
61 | lightLength: 200,
62 | }
63 | },
64 | lightLeftBeam2 : {
65 | function : LightBeam,
66 | properties: {
67 | position: [-100,-150,0],
68 | color: 0x11cc44,
69 | lightLength: 300,
70 | }
71 | },
72 | lightLeftBeam4 : {
73 | function : LightBeam,
74 | properties: {
75 | position: [-100,-150,0],
76 | color: 0x11ff11,
77 | lightLength: 250,
78 | }
79 | },
80 | lightLeftBeam3 : {
81 | function : LightBeam,
82 | properties: {
83 | position: [-100,-150,0],
84 | color: 0x11ee22,
85 | lightLength: 200,
86 | }
87 | },
88 |
89 | sky: {
90 | function: require('../js/components/ambiance/Sky'),
91 | properties : {
92 | width : 50
93 | }
94 | }
95 | },
96 | };
--------------------------------------------------------------------------------
/manifests/meshGroupBoxDemo.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "MeshGroup() Proof of Concept",
3 | description : "Batching multiple Three.js meshes into one draw call",
4 | order : 50,
5 | config : {
6 | camera : {
7 | x : -400
8 | }
9 | },
10 | components : {
11 | renderer : { function : require('../js/renderers/basic-renderer') },
12 | demo : {
13 | construct: require("../js/demos/MeshGroupBoxDemo"),
14 | properties: {}
15 | },
16 | controls : {
17 | construct: require("../js/components/cameras/Controls"),
18 | },
19 | grid : {
20 | construct: require("../js/demos/Grid"),
21 | },
22 | stats : {
23 | construct: require("../js/components/utils/Stats")
24 | }
25 | }
26 | };
--------------------------------------------------------------------------------
/manifests/postprocessing.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "Post Processing",
3 | description : "",
4 | order : 0,
5 | config : {
6 | camera : {
7 | x : -400
8 | },
9 | },
10 | components : {
11 | renderer : { function : require('../js/renderers/postprocess-renderer') },
12 | controls : {
13 | construct: require("../js/components/cameras/Controls"),
14 | },
15 | grid : {
16 | construct: require("../js/demos/Grid"),
17 | },
18 | tree : {
19 | function: require('../js/components/models/tree'),
20 | properties: {
21 | position: [0,-50, 0],
22 | scale: [20,20,20],
23 | }
24 | },
25 | lights : {
26 | construct: require("../js/components/lights/TrackCameraLights")
27 | },
28 | // stats : {
29 | // construct: require("../js/components/utils/Stats")
30 | // }
31 | }
32 | };
--------------------------------------------------------------------------------
/manifests/sineGravityCloud.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "Sine Gravity Cloud",
3 | description : "An evolving cloud of movement",
4 | order : 0,
5 | config : {
6 | camera : {
7 | x : -400
8 | },
9 | },
10 | components : {
11 | renderer : { function : require('../js/renderers/basic-renderer') },
12 | controls : {
13 | construct: require("../js/components/cameras/Controls"),
14 | },
15 | pointcloud : {
16 | construct: require("../js/demos/sine-gravity-cloud/sine"),
17 | },
18 | grid : {
19 | construct: require("../js/demos/Grid"),
20 | },
21 | // stats : {
22 | // construct: require("../js/components/utils/Stats")
23 | // }
24 | }
25 | };
--------------------------------------------------------------------------------
/manifests/tetrahedra.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "Tetrahedra",
3 | description : "Live coding demo",
4 | order : 0,
5 | config : {
6 | camera : {
7 | x : -300,
8 | near : 0.1,
9 | far : 10000,
10 | fov : 40
11 | }
12 | },
13 | components : {
14 | renderer : { function : require('../js/renderers/effects-renderer') },
15 | controls : { construct: require("../js/components/cameras/Controls") },
16 | mouse : { function: require('../js/components/hids/mouse-tracker') },
17 | // grid : {
18 | // construct: require("../js/demos/Grid"),
19 | // },
20 | tetrahedra : {
21 | function: require('../js/demos/tetrahedra'),
22 | properties: {
23 | dispersion: 150,
24 | radius: 10,
25 | count: 100,
26 | mouseRef: "mouse"
27 | }
28 | },
29 | lights : {
30 | construct: require("../js/components/lights/TrackCameraLights")
31 | },
32 |
33 | cloudsTop : {
34 | construct: require("../js/components/ambiance/Clouds"),
35 | properties: {
36 | width: 2000,
37 | height: 1000,
38 | rotation: -Math.PI / 2
39 | }
40 | },
41 |
42 | cloudsBottom : {
43 | construct: require("../js/components/ambiance/Clouds"),
44 | properties: {
45 | width: 2000,
46 | height: -1000,
47 | rotation: -Math.PI / 2,
48 | offset : new THREE.Vector2(-0.3,0.8),
49 | }
50 | }
51 | // music : {
52 | // construct: require("../js/sound/Music"),
53 | // properties: {
54 | // url: "https://soundcloud.com/synaptyx/mech-attack"
55 | // }
56 | // }
57 | // stats : {
58 | // construct: require("../js/components/utils/Stats")
59 | // }
60 | }
61 | };
--------------------------------------------------------------------------------
/manifests/texturePositionalMatrices.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "MeshGroup() Pre-Cursor 2",
3 | description : "Position matrices packed into a texture",
4 | order : 52,
5 | config : {
6 | camera : {
7 | x : -400
8 | }
9 | },
10 | components : {
11 | renderer : { function : require('../js/renderers/basic-renderer') },
12 | controls : {
13 | construct: require("../js/components/cameras/Controls"),
14 | },
15 | texturePositionalMatrices : {
16 | construct: require("../js/demos/texturePositionalMatrices"),
17 | },
18 | grid : {
19 | construct: require("../js/demos/Grid"),
20 | },
21 | stats : {
22 | construct: require("../js/components/utils/Stats")
23 | }
24 | }
25 | };
--------------------------------------------------------------------------------
/manifests/uniformPositionalMatrices.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "MeshGroup() Pre-Cursor 1",
3 | description : "Position matrices set in uniforms",
4 | order : 51,
5 | config : {
6 | camera : {
7 | x : -400
8 | }
9 | },
10 | components : {
11 | renderer : { function : require('../js/renderers/basic-renderer') },
12 | controls : {
13 | construct: require("../js/components/cameras/Controls"),
14 | },
15 | uniformPositionalMatrices : {
16 | construct: require("../js/demos/uniformPositionalMatrices"),
17 | },
18 | grid : {
19 | construct: require("../js/demos/Grid"),
20 | },
21 | stats : {
22 | construct: require("../js/components/utils/Stats")
23 | }
24 | }
25 | };
--------------------------------------------------------------------------------
/manifests/vr.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | name : "VR Demo",
3 | description : "The Sine Gravity wave as a VR demo",
4 | order : 0,
5 | config : {
6 | camera : {
7 | x : -300,
8 | fov : 70
9 | },
10 | },
11 | components : {
12 |
13 | renderer : { function : require('../js/renderers/cardboard-renderer') },
14 | controls : { construct: require("../js/components/cameras/Orientation") },
15 | cameraRotation : { construct: require("../js/components/cameras/RotateAroundOrigin") },
16 | grid : { construct: require("../js/demos/Grid") },
17 |
18 | pointcloud : {
19 | construct: require("../js/demos/sine-gravity-cloud/sine"),
20 | properties: {
21 | count: 50 * 1000,
22 | pointSize : 4
23 | }
24 | },
25 | }
26 | };
--------------------------------------------------------------------------------
/menu.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | A Three.js Sandbox of Experiments | Greg Tatum
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sandbox",
3 | "version": "0.0.1",
4 | "scripts": {
5 | "build": "browserify ./js/index.js -d -g [uglifyify -x .js] | exorcist assets/build/bundle.js.map > assets/build/bundle.js",
6 | "start": "budo js/index.js:assets/build/bundle.js --live --verbose | garnish"
7 | },
8 | "devDependencies": {
9 | "babelify": "^6.0.2",
10 | "crossroads": "^0.12.0",
11 | "cubic-bezier": "^0.1.2",
12 | "eases": "^1.0.6",
13 | "es6-promise": "^2.3.0",
14 | "events": "^1.0.2",
15 | "exorcist": "^0.1.6",
16 | "glsl-camera-ray": "^1.0.0",
17 | "glsl-hsl2rgb": "^1.1.0",
18 | "glsl-hsv2rgb": "^1.0.0",
19 | "glsl-noise": "0.0.0",
20 | "glsl-random": "0.0.4",
21 | "glsl-raytrace": "^1.0.0",
22 | "glsl-sdf-normal": "^1.0.0",
23 | "glsl-turntable-camera": "^1.0.0",
24 | "glslify": "^2.1.2",
25 | "hasher": "^1.2.0",
26 | "lerp": "^1.0.3",
27 | "localforage": "^1.2.0",
28 | "perlin-simplex": "0.0.2",
29 | "poem-loop": "^1.0.4",
30 | "poem-manifests": "^1.2.2",
31 | "poem-menu": "^1.0.2",
32 | "poem-mute": "^1.0.2",
33 | "rsvp": "^3.0.14",
34 | "soundcloud-badge": "0.0.0",
35 | "three-glslify": "^2.0.1",
36 | "touches": "^1.1.1",
37 | "uglifyify": "^3.0.1"
38 | },
39 | "dependencies": {
40 | "underscore": "^1.7.0"
41 | },
42 | "browserify": {
43 | "transform": [
44 | "glslify",
45 | "babelify"
46 | ]
47 | }
48 | }
49 |
--------------------------------------------------------------------------------