20
20
const numColumns = 60
21
21
const glyphTextureColumns = 8
22
22
const glyphSequenceLength = 57
23
- const msdfURL = " assets/matrix_glyphs_msdf.png"
24
- const paletteURL = " assets/matrix_palette.png"
23
+ const msdfURL = ' assets/matrix_glyphs_msdf.png'
24
+ const paletteURL = ' assets/matrix_palette.png'
25
25
26
- document . body . style = " background-color: black;"
26
+ document . body . style = ' background-color: black;'
27
27
document . addEventListener ( 'touchmove' , e => e . preventDefault ( ) , { passive : false } )
28
28
const canvas = document . body . appendChild ( document . createElement ( 'canvas' ) )
29
29
const fit = require ( 'canvas-fit' )
@@ -33,14 +33,14 @@ const regl = require('../regl')({
33
33
canvas,
34
34
extensions : [
35
35
'OES_texture_half_float' ,
36
- 'OES_texture_half_float_linear' ,
36
+ 'OES_texture_half_float_linear'
37
37
] ,
38
38
optionalExtensions : [
39
39
// These extensions are also needed, but Safari misreports that they are missing
40
40
'EXT_color_buffer_half_float' ,
41
41
'WEBGL_color_buffer_float' ,
42
42
'OES_standard_derivatives'
43
- ] ,
43
+ ]
44
44
} )
45
45
46
46
// These two framebuffers are used to compute the raining code.
@@ -152,13 +152,12 @@ const updateRain = regl({
152
152
153
153
uniforms : {
154
154
glyphSequenceLength,
155
- time : regl . context ( 'time' ) ,
155
+ time : regl . context ( 'time' )
156
156
} ,
157
157
158
- framebuffer : ( { tick} ) => state [ ( tick + 1 ) % 2 ] // The crucial state FBO alternator
158
+ framebuffer : ( { tick } ) => state [ ( tick + 1 ) % 2 ] // The crucial state FBO alternator
159
159
} )
160
160
161
-
162
161
// We render the code into an FBO using MSDFs: https://github.com/Chlumsky/msdfgen
163
162
const renderRain = regl ( {
164
163
vert : `
@@ -173,7 +172,7 @@ const renderRain = regl({
173
172
}
174
173
` ,
175
174
176
- frag :`
175
+ frag : `
177
176
#ifdef GL_OES_standard_derivatives
178
177
#extension GL_OES_standard_derivatives: enable
179
178
#endif
@@ -211,9 +210,9 @@ const renderRain = regl({
211
210
` ,
212
211
213
212
uniforms : {
214
- glyphMSDF : regl . prop ( " glyphMSDF" ) ,
213
+ glyphMSDF : regl . prop ( ' glyphMSDF' ) ,
215
214
width : regl . context ( 'viewportHeight' ) ,
216
- height : regl . context ( 'viewportWidth' ) ,
215
+ height : regl . context ( 'viewportWidth' )
217
216
} ,
218
217
219
218
framebuffer : renderedFBO
@@ -237,10 +236,10 @@ const highPass = regl({
237
236
}
238
237
` ,
239
238
uniforms : {
240
- tex : regl . prop ( " tex" ) ,
239
+ tex : regl . prop ( ' tex' ) ,
241
240
threshold : 0.3
242
241
} ,
243
- framebuffer : regl . prop ( " fbo" )
242
+ framebuffer : regl . prop ( ' fbo' )
244
243
} )
245
244
246
245
// A 2D gaussian blur is just a 1D blur done horizontally, then done vertically.
@@ -264,29 +263,29 @@ const blur = regl({
264
263
}
265
264
` ,
266
265
uniforms : {
267
- tex : regl . prop ( " tex" ) ,
268
- direction : regl . prop ( " direction" ) ,
266
+ tex : regl . prop ( ' tex' ) ,
267
+ direction : regl . prop ( ' direction' ) ,
269
268
height : regl . context ( 'viewportWidth' ) ,
270
- width : regl . context ( 'viewportHeight' ) ,
269
+ width : regl . context ( 'viewportHeight' )
271
270
} ,
272
- framebuffer : regl . prop ( " fbo" )
271
+ framebuffer : regl . prop ( ' fbo' )
273
272
} )
274
273
275
274
// The pyramid of textures gets flattened onto the source texture.
276
275
const combineBloom = regl ( {
277
276
frag : `
278
277
precision mediump float;
279
278
varying vec2 vUV;
280
- ${ verticalBlurPyramid . map ( ( _ , index ) => `uniform sampler2D tex_${ index } ;` ) . join ( "\n" ) }
279
+ ${ verticalBlurPyramid . map ( ( _ , index ) => `uniform sampler2D tex_${ index } ;` ) . join ( '\n' ) }
281
280
uniform sampler2D tex;
282
281
void main() {
283
282
vec4 total = vec4(0.);
284
- ${ verticalBlurPyramid . map ( ( _ , index ) => `total += texture2D(tex_${ index } , vUV);` ) . join ( "\n" ) }
283
+ ${ verticalBlurPyramid . map ( ( _ , index ) => `total += texture2D(tex_${ index } , vUV);` ) . join ( '\n' ) }
285
284
gl_FragColor = total + texture2D(tex, vUV);
286
285
}
287
286
` ,
288
- uniforms : Object . assign ( { tex : regl . prop ( " tex" ) } , pyramidUniforms ( verticalBlurPyramid ) ) ,
289
- framebuffer : regl . prop ( " fbo" )
287
+ uniforms : Object . assign ( { tex : regl . prop ( ' tex' ) } , pyramidUniforms ( verticalBlurPyramid ) ) ,
288
+ framebuffer : regl . prop ( ' fbo' )
290
289
} )
291
290
292
291
// Finally, the values are mapped to colors in a palette texture.
@@ -320,7 +319,7 @@ const colorizeByPalette = regl({
320
319
321
320
uniforms : {
322
321
ditherMagnitude : 0.05 ,
323
- palette : regl . prop ( " palette" ) ,
322
+ palette : regl . prop ( ' palette' ) ,
324
323
tex : bloomedFBO ,
325
324
time : regl . context ( 'time' )
326
325
}
@@ -342,9 +341,9 @@ const setupQuad = regl({
342
341
} ,
343
342
344
343
uniforms : {
345
- lastState : ( { tick} ) => state [ tick % 2 ] ,
344
+ lastState : ( { tick } ) => state [ tick % 2 ] ,
346
345
numColumns,
347
- glyphTextureColumns,
346
+ glyphTextureColumns
348
347
} ,
349
348
350
349
depth : { enable : false } ,
@@ -375,7 +374,7 @@ require('resl')({
375
374
} ,
376
375
onDone : resources => {
377
376
setupQuad ( { } , updateRain )
378
- regl . frame ( ( { viewportWidth, viewportHeight} ) => {
377
+ regl . frame ( ( { viewportWidth, viewportHeight } ) => {
379
378
// All the FBOs except the compute FBOs need to be sized to the window.
380
379
renderedFBO . resize ( viewportWidth , viewportHeight )
381
380
bloomedFBO . resize ( viewportWidth , viewportHeight )
@@ -389,10 +388,10 @@ require('resl')({
389
388
setupQuad ( ( ) => {
390
389
updateRain ( )
391
390
renderRain ( resources )
392
- highPassPyramid . forEach ( fbo => highPass ( { fbo, tex : renderedFBO } ) )
393
- horizontalBlurPyramid . forEach ( ( fbo , index ) => blur ( { fbo, tex : highPassPyramid [ index ] , direction : [ 1 , 0 ] } ) )
394
- verticalBlurPyramid . forEach ( ( fbo , index ) => blur ( { fbo, tex : horizontalBlurPyramid [ index ] , direction : [ 0 , 1 ] } ) )
395
- combineBloom ( { tex : renderedFBO , fbo : bloomedFBO } )
391
+ highPassPyramid . forEach ( fbo => highPass ( { fbo, tex : renderedFBO } ) )
392
+ horizontalBlurPyramid . forEach ( ( fbo , index ) => blur ( { fbo, tex : highPassPyramid [ index ] , direction : [ 1 , 0 ] } ) )
393
+ verticalBlurPyramid . forEach ( ( fbo , index ) => blur ( { fbo, tex : horizontalBlurPyramid [ index ] , direction : [ 0 , 1 ] } ) )
394
+ combineBloom ( { tex : renderedFBO , fbo : bloomedFBO } )
396
395
colorizeByPalette ( resources )
397
396
} )
398
397
} )
0 commit comments