├── .gitignore ├── shaders ├── logic.vert ├── render.frag ├── render.vert ├── index.js └── logic.frag ├── index.html ├── README.md ├── package.json ├── LICENSE.md └── demo.js /.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | node_modules 3 | -------------------------------------------------------------------------------- /shaders/logic.vert: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | attribute vec2 aPosition; 6 | 7 | void main() { 8 | gl_Position = vec4(aPosition.xy, 1.0, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /shaders/render.frag: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | uniform sampler2D uTexture; 6 | varying vec2 vIndex; 7 | 8 | void main() { 9 | gl_FragColor = vec4( 10 | sin(vIndex.x * 10.0) 11 | , 0.5 12 | , 1.0 - vIndex.y 13 | , 1.0 14 | ) * 0.165; 15 | } 16 | -------------------------------------------------------------------------------- /shaders/render.vert: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | attribute vec2 aIndex; 6 | 7 | uniform vec2 uScreen; 8 | uniform sampler2D uState; 9 | 10 | varying vec2 vIndex; 11 | 12 | void main() { 13 | vIndex = aIndex; 14 | gl_PointSize = 1.0; 15 | gl_Position = vec4(texture2D(uState, aIndex).xy / uScreen, 1.0, 1.0); 16 | } 17 | -------------------------------------------------------------------------------- /shaders/index.js: -------------------------------------------------------------------------------- 1 | var createShader = require('gl-shader') 2 | 3 | module.exports = init 4 | 5 | function init(gl) { 6 | var shaders = {} 7 | 8 | shaders.logic = createShader(gl 9 | , require('./logic.vert') 10 | , require('./logic.frag') 11 | ) 12 | 13 | shaders.render = createShader(gl 14 | , require('./render.vert') 15 | , require('./render.frag') 16 | ) 17 | 18 | return shaders 19 | } 20 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # particle-excess-demo [](https://flattr.com/submit/auto?user_id=hughskennedy&url=http://github.com/hughsk/particle-excess-demo&title=particle-excess-demo&description=hughsk/particle-excess-demo%20on%20GitHub&language=en_GB&tags=flattr,github,javascript&category=software) #
2 |
3 | Simulating and rendering 262,144 particles with GLSL.
4 |
5 | 
6 |
7 | **[view demo](http://hughsk.github.io/particle-excess-demo)**
8 |
9 | ## License ##
10 |
11 | MIT. See [LICENSE.md](http://github.com/hughsk/particle-excess-demo/blob/master/LICENSE.md) for details.
12 |
--------------------------------------------------------------------------------
/shaders/logic.frag:
--------------------------------------------------------------------------------
1 | #ifdef GL_ES
2 | precision mediump float;
3 | #endif
4 |
5 | #pragma glslify: simplex = require(../node_modules/glsl-noise/simplex/3d)
6 |
7 | uniform sampler2D uState;
8 | uniform float uTime;
9 |
10 | const vec3 OFFSET = vec3(2399.24849823098, 3299.9028381, 389.09338327);
11 | const float SPEED = 2.0;
12 |
13 | void main() {
14 | vec3 sampled = texture2D(uState, gl_FragCoord.xy / vec2(512.0)).rgb;
15 | vec2 nextPosition = sampled.xy;
16 |
17 | float t = uTime * 0.013849829389;
18 |
19 | nextPosition += vec2(
20 | simplex(vec3(nextPosition * 0.005, 9280.03992092039 + t + gl_FragCoord.x / 110.0) + OFFSET)
21 | , simplex(vec3(nextPosition * 0.005, 3870.73392092039 - t - gl_FragCoord.y / 110.0) + OFFSET)
22 | ) * SPEED;
23 |
24 | float radius = length(nextPosition);
25 | float rad = 0.00002 * radius;
26 | nextPosition = vec2(
27 | nextPosition.x * cos(rad) - nextPosition.y * sin(rad)
28 | , nextPosition.y * cos(rad) + nextPosition.x * sin(rad)
29 | );
30 |
31 | nextPosition *= 0.9999;
32 |
33 | gl_FragColor = vec4(vec3(nextPosition, 1.0), 1.0);
34 | }
35 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "particle-excess-demo",
3 | "description": "Simulating and rendering 262,144 particles with GLSL",
4 | "version": "0.0.0",
5 | "main": "demo.js",
6 | "browser": "demo.js",
7 | "scripts": {
8 | "start": "beefy demo.js:bundle.js --live -- -t glslifyify",
9 | "prepublish": "browserify demo.js -t glslifyify > bundle.js"
10 | },
11 | "dependencies": {
12 | "gl-vao": "0.0.3",
13 | "gl-shader": "0.0.6",
14 | "gl-now": "0.0.4",
15 | "gl-fbo": "~0.1.1",
16 | "gl-buffer": "~0.1.1",
17 | "gl-texture2d": "~0.1.5",
18 | "glsl-noise": "0.0.0",
19 | "zeros": "0.0.0",
20 | "ndarray-fill": "~0.1.0",
21 | "ndarray": "~1.0.9"
22 | },
23 | "devDependencies": {
24 | "glslifyify": "~0.1.1",
25 | "beefy": "~0.7.1",
26 | "browserify": "~3.14.1"
27 | },
28 | "author": "Hugh Kennedy