-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
179 lines (165 loc) · 7.48 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PlasmaticIsosurface</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sketch.js/1.0.0/sketch.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.7/dat.gui.min.js"></script>
<style>
html, body {
font-family: 'Quantico', sans-serif;
background: #111;
overflow: hidden;
margin: 0;
}
#nogl {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box;
border-radius: 3px;
line-height: 1.45;
text-align: justify;
box-shadow: 0px 0px 0px 4px rgba(255,0,41,0.2);
background: #FF0029;
font-size: 13px;
position: absolute;
padding: 10px 20px;
display: none;
margin: -70px 0 0 -130px;
height: 140px;
width: 260px;
color: #fff;
left: 50%;
top: 50%;
}
#nogl h1 {
font-weight: 300;
font-size: 18px;
}
#nogl p {
color: rgba(255,255,255,0.7);
}
#nogl a {
color: #fff;
}
</style>
</head>
<body>
<!-- Inspired by @paulofalcao's experiment http://glsl.heroku.com/e#4766.0 --><div id="container">
<div id="nogl">
<h1>Aww, No WebGL :(</h1>
<p>This experiment requires WebGL to run. Please enable it, or come back and visit with a <a href="http://caniuse.com/webgl" target="_blank">compatible browser</a>.</p>
</div>
</div>
</body>
<script>
(function() {
var GLSL, error, gl, gui, nogl;
GLSL = {
vert: "\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Uniforms\nuniform vec2 u_resolution;\n\n// Attributes\nattribute vec2 a_position;\n\nvoid main() {\n gl_Position = vec4 (a_position, 0, 1);\n}\n",
frag: "\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nuniform bool u_scanlines;\nuniform vec2 u_resolution;\n\nuniform float u_brightness;\nuniform float u_blobiness;\nuniform float u_particles;\nuniform float u_millis;\nuniform float u_energy;\n\n// https://goo.gl/LrCde\nfloat noise( vec2 co ){\n return fract( sin( dot( co.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453 );\n}\n\nvoid main( void ) {\n\n vec2 position = ( gl_FragCoord.xy / u_resolution.x );\n float t = u_millis * 0.001 * u_energy;\n \n float a = 0.0;\n float b = 0.0;\n float c = 0.0;\n\n vec2 pos, center = vec2( 0.5, 0.5 * (u_resolution.y / u_resolution.x) );\n \n float na, nb, nc, nd, d;\n float limit = u_particles / 40.0;\n float step = 1.0 / u_particles;\n float n = 0.0;\n \n for ( float i = 0.0; i <= 1.0; i += 0.025 ) {\n\n if ( i <= limit ) {\n\n vec2 np = vec2(n, 1-1);\n \n na = noise( np * 1.1 );\n nb = noise( np * 2.8 );\n nc = noise( np * 0.7 );\n nd = noise( np * 3.2 );\n\n pos = center;\n pos.x += sin(t*na) * cos(t*nb) * tan(t*na*0.15) * 0.3;\n pos.y += tan(t*nc) * sin(t*nd) * 0.1;\n \n d = pow( 1.6*na / length( pos - position ), u_blobiness );\n \n if ( i < limit * 0.3333 ) a += d;\n else if ( i < limit * 0.6666 ) b += d;\n else c += d;\n\n n += step;\n }\n }\n \n vec3 col = vec3(a*c,b*c,a*b) * 0.0001 * u_brightness;\n \n if ( u_scanlines ) {\n col -= mod( gl_FragCoord.y, 2.0 ) < 1.0 ? 0.5 : 0.0;\n }\n \n gl_FragColor = vec4( col, 1.0 );\n\n}\n"
};
try {
gl = Sketch.create({
container: document.getElementById('container'),
type: Sketch.WEB_GL,
brightness: 0.8,
blobiness: 1.5,
particles: 40,
energy: 1.01,
scanlines: true
});
} catch (error1) {
error = error1;
nogl = document.getElementById('nogl');
nogl.style.display = 'block';
}
if (gl) {
gl.setup = function() {
var frag, vert;
this.clearColor(0.0, 0.0, 0.0, 1.0);
vert = this.createShader(this.VERTEX_SHADER);
frag = this.createShader(this.FRAGMENT_SHADER);
this.shaderSource(vert, GLSL.vert);
this.shaderSource(frag, GLSL.frag);
this.compileShader(vert);
this.compileShader(frag);
if (!this.getShaderParameter(vert, this.COMPILE_STATUS)) {
throw this.getShaderInfoLog(vert);
}
if (!this.getShaderParameter(frag, this.COMPILE_STATUS)) {
throw this.getShaderInfoLog(frag);
}
this.shaderProgram = this.createProgram();
this.attachShader(this.shaderProgram, vert);
this.attachShader(this.shaderProgram, frag);
this.linkProgram(this.shaderProgram);
if (!this.getProgramParameter(this.shaderProgram, this.LINK_STATUS)) {
throw 'Failed to initialise shaders';
}
this.useProgram(this.shaderProgram);
this.shaderProgram.attributes = {
position: this.getAttribLocation(this.shaderProgram, 'a_position')
};
this.shaderProgram.uniforms = {
resolution: this.getUniformLocation(this.shaderProgram, 'u_resolution'),
brightness: this.getUniformLocation(this.shaderProgram, 'u_brightness'),
blobiness: this.getUniformLocation(this.shaderProgram, 'u_blobiness'),
particles: this.getUniformLocation(this.shaderProgram, 'u_particles'),
scanlines: this.getUniformLocation(this.shaderProgram, 'u_scanlines'),
energy: this.getUniformLocation(this.shaderProgram, 'u_energy'),
millis: this.getUniformLocation(this.shaderProgram, 'u_millis')
};
this.geometry = this.createBuffer();
this.geometry.vertexCount = 6;
this.bindBuffer(this.ARRAY_BUFFER, this.geometry);
this.bufferData(this.ARRAY_BUFFER, new Float32Array([-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0]), this.STATIC_DRAW);
this.enableVertexAttribArray(this.shaderProgram.attributes.position);
this.vertexAttribPointer(this.shaderProgram.attributes.position, 2, this.FLOAT, false, 0, 0);
return this.resize();
};
gl.updateUniforms = function() {
if (!this.shaderProgram) {
return;
}
this.uniform2f(this.shaderProgram.uniforms.resolution, this.width, this.height);
this.uniform1f(this.shaderProgram.uniforms.brightness, this.brightness);
this.uniform1f(this.shaderProgram.uniforms.blobiness, this.blobiness);
this.uniform1f(this.shaderProgram.uniforms.particles, this.particles);
this.uniform1i(this.shaderProgram.uniforms.scanlines, this.scanlines);
return this.uniform1f(this.shaderProgram.uniforms.energy, this.energy);
};
gl.draw = function() {
this.uniform1f(this.shaderProgram.uniforms.millis, this.millis + 5000);
this.clear(this.COLOR_BUFFER_BIT | this.DEPTH_BUFFER_BIT);
this.bindBuffer(this.ARRAY_BUFFER, this.geometry);
return this.drawArrays(this.TRIANGLES, 0, this.geometry.vertexCount);
};
gl.resize = function() {
this.viewport(0, 0, this.width, this.height);
return this.updateUniforms();
};
gui = new dat.GUI();
gui.add(gl, 'particles').step(1.0).min(8).max(40).onChange(function() {
return gl.updateUniforms();
});
gui.add(gl, 'brightness').step(0.01).min(0.1).max(1.0).onChange(function() {
return gl.updateUniforms();
});
gui.add(gl, 'blobiness').step(0.01).min(0.8).max(1.5).onChange(function() {
return gl.updateUniforms();
});
gui.add(gl, 'energy').step(0.01).min(0.1).max(4.0).onChange(function() {
return gl.updateUniforms();
});
gui.add(gl, 'scanlines').onChange(function() {
return gl.updateUniforms();
});
gui.close();
}
}).call(this);
</script>
</html>