@@ -7,8 +7,11 @@ import {
7
7
RepeatWrapping ,
8
8
HalfFloatType ,
9
9
RGBAFormat ,
10
+ UnsignedByteType ,
11
+ Vector2 ,
10
12
} from "../third_party/three.module.js" ;
11
13
import { ShaderPass } from "../js/ShaderPass.js" ;
14
+ import { ShaderPingPongPass } from "../js/ShaderPingPongPass.js" ;
12
15
import { getFBO } from "../js/FBO.js" ;
13
16
import { shader as orthoVs } from "../shaders/ortho-vs.js" ;
14
17
import { shader as sobel } from "../shaders/sobel.js" ;
@@ -17,6 +20,7 @@ import { shader as luma } from "../shaders/luma.js";
17
20
import { generateParams as generatePaperParams } from "../js/paper.js" ;
18
21
import { shader as darken } from "../shaders/blend-darken.js" ;
19
22
import { shader as screen } from "../shaders/blend-screen.js" ;
23
+ import { blur5 } from "../shaders/fast-separable-gaussian-blur.js" ;
20
24
21
25
import {
22
26
Material as ColorMaterial ,
@@ -30,6 +34,23 @@ const loader = new TextureLoader();
30
34
const noiseTexture = loader . load ( "../assets/noise1.png" ) ;
31
35
noiseTexture . wrapS = noiseTexture . wrapT = RepeatWrapping ;
32
36
37
+ const blurFragmentShader = `#version 300 es
38
+ precision highp float;
39
+
40
+ uniform sampler2D inputTexture;
41
+ uniform vec2 direction;
42
+
43
+ ${ blur5 }
44
+
45
+ in vec2 vUv;
46
+ out vec4 fragColor;
47
+
48
+ void main() {
49
+ vec2 size = vec2(textureSize(inputTexture, 0));
50
+ fragColor = blur5(inputTexture, vUv, size, direction);
51
+ }
52
+ ` ;
53
+
33
54
const componentFragmentShader = `#version 300 es
34
55
precision highp float;
35
56
@@ -288,7 +309,7 @@ void main() {
288
309
fragColor.rgb = blendDarken(fragColor.rgb, darkInk/255., border*.25 * shade);
289
310
fragColor.rgb = blendDarken(fragColor.rgb, darkInk/255., darkIntensity * (1.-shadeHatch));
290
311
fragColor.rgb = blendScreen(fragColor.rgb, brightInk/255., brightIntensity * whiteHatch);
291
-
312
+
292
313
fragColor.a = 1.;
293
314
}
294
315
` ;
@@ -302,14 +323,15 @@ class Post {
302
323
this . params = {
303
324
roughness : 0.2 ,
304
325
metalness : 0.1 ,
305
- colorScale : 0.25 ,
326
+ colorScale : 0.07 ,
306
327
colorOffset : 0.25 ,
307
328
colorWidth : 0.5 ,
308
329
scale : 0.32 ,
309
330
angle : 0 ,
310
331
thickness : 0.7 ,
311
332
noisiness : 0.003 ,
312
333
contour : 2 ,
334
+ blur : 2 ,
313
335
border : 0.5 ,
314
336
fill : 1 ,
315
337
stroke : 1 ,
@@ -318,7 +340,7 @@ class Post {
318
340
yellow : 0.6 ,
319
341
black : 0.1 ,
320
342
darkIntensity : 0.75 ,
321
- brightIntensity : 0.25 ,
343
+ brightIntensity : 1 ,
322
344
darkInk : new Color ( 30 , 30 , 30 ) ,
323
345
brightInk : new Color ( 230 , 230 , 230 ) ,
324
346
} ;
@@ -336,6 +358,7 @@ class Post {
336
358
thickness : { value : this . params . thickness } ,
337
359
contour : { value : this . params . contour } ,
338
360
border : { value : this . params . border } ,
361
+ blur : { value : this . params . blur } ,
339
362
stroke : { value : this . params . stroke } ,
340
363
fill : { value : this . params . fill } ,
341
364
darkIntensity : { value : this . params . darkIntensity } ,
@@ -346,10 +369,26 @@ class Post {
346
369
vertexShader : orthoVs ,
347
370
fragmentShader,
348
371
} ) ;
372
+ const blurShader = new RawShaderMaterial ( {
373
+ uniforms : {
374
+ inputTexture : { value : this . colorFBO . texture } ,
375
+ direction : { value : new Vector2 ( ) } ,
376
+ } ,
377
+ vertexShader : orthoVs ,
378
+ fragmentShader : blurFragmentShader ,
379
+ } ) ;
380
+ this . blurPass = new ShaderPingPongPass ( renderer , blurShader , {
381
+ format : RGBAFormat ,
382
+ type : UnsignedByteType ,
383
+ } ) ;
384
+ this . blurShadePass = new ShaderPingPongPass ( renderer , blurShader , {
385
+ format : RGBAFormat ,
386
+ type : UnsignedByteType ,
387
+ } ) ;
349
388
this . renderPass = new ShaderPass ( renderer , shader ) ;
350
389
const componentShader = new RawShaderMaterial ( {
351
390
uniforms : {
352
- colorTexture : { value : this . colorFBO . texture } ,
391
+ colorTexture : { value : null } ,
353
392
cyan : { value : this . params . cyan } ,
354
393
magenta : { value : this . params . magenta } ,
355
394
yellow : { value : this . params . yellow } ,
@@ -371,6 +410,8 @@ class Post {
371
410
this . shadeFBO . setSize ( w , h ) ;
372
411
this . renderPass . setSize ( w , h ) ;
373
412
this . componentPass . setSize ( w , h ) ;
413
+ this . blurPass . setSize ( w , h ) ;
414
+ this . blurShadePass . setSize ( w , h ) ;
374
415
}
375
416
376
417
render ( scene , camera ) {
@@ -390,6 +431,46 @@ class Post {
390
431
this . renderer . setRenderTarget ( null ) ;
391
432
scene . overrideMaterial = null ;
392
433
434
+ this . blurPass . shader . uniforms . inputTexture . value = this . colorFBO . texture ;
435
+ for ( let i = 0 ; i < 6 ; i ++ ) {
436
+ if ( i < this . params . blur ) {
437
+ var d = ( i + 1 ) * 2 ;
438
+ this . blurPass . shader . uniforms . direction . value . set ( d , 0 ) ;
439
+ this . blurPass . render ( ) ;
440
+ this . blurPass . shader . uniforms . inputTexture . value = this . blurPass . fbos [
441
+ this . blurPass . currentFBO
442
+ ] . texture ;
443
+ this . blurPass . shader . uniforms . direction . value . set ( 0 , d ) ;
444
+ this . blurPass . render ( ) ;
445
+ this . blurPass . shader . uniforms . inputTexture . value = this . blurPass . fbos [
446
+ this . blurPass . currentFBO
447
+ ] . texture ;
448
+ }
449
+ }
450
+ this . componentPass . shader . uniforms . colorTexture . value = this . blurPass . shader . uniforms . inputTexture . value = this . blurPass . fbos [
451
+ this . blurPass . currentFBO
452
+ ] . texture ;
453
+
454
+ this . blurShadePass . shader . uniforms . inputTexture . value = this . shadeFBO . texture ;
455
+ for ( let i = 0 ; i < 6 ; i ++ ) {
456
+ if ( i < this . params . blur ) {
457
+ var d = ( i + 1 ) * 2 ;
458
+ this . blurShadePass . shader . uniforms . direction . value . set ( d , 0 ) ;
459
+ this . blurShadePass . render ( ) ;
460
+ this . blurShadePass . shader . uniforms . inputTexture . value = this . blurShadePass . fbos [
461
+ this . blurShadePass . currentFBO
462
+ ] . texture ;
463
+ this . blurShadePass . shader . uniforms . direction . value . set ( 0 , d ) ;
464
+ this . blurShadePass . render ( ) ;
465
+ this . blurShadePass . shader . uniforms . inputTexture . value = this . blurShadePass . fbos [
466
+ this . blurShadePass . currentFBO
467
+ ] . texture ;
468
+ }
469
+ }
470
+ this . renderPass . shader . uniforms . shadeTexture . value = this . blurShadePass . shader . uniforms . inputTexture . value = this . blurShadePass . fbos [
471
+ this . blurShadePass . currentFBO
472
+ ] . texture ;
473
+
393
474
this . componentPass . render ( ) ;
394
475
this . renderPass . render ( true ) ;
395
476
}
@@ -411,11 +492,7 @@ class Post {
411
492
. onChange ( async ( v ) => {
412
493
colorMat . uniforms . width . value = v ;
413
494
} ) ;
414
- // controllers["metalness"] = gui
415
- // .add(this.params, "metalness", 0., 1)
416
- // .onChange(async (v) => {
417
- // this.renderPass.shader.uniforms.metalness.value = v;
418
- // });
495
+
419
496
controllers [ "scale" ] = gui
420
497
. add ( this . params , "scale" , 0.1 , 1 )
421
498
. onChange ( async ( v ) => {
@@ -426,6 +503,7 @@ class Post {
426
503
. onChange ( async ( v ) => {
427
504
this . renderPass . shader . uniforms . thickness . value = v ;
428
505
} ) ;
506
+ controllers [ "blur" ] = gui . add ( this . params , "blur" , 0 , 7 ) ;
429
507
controllers [ "contour" ] = gui
430
508
. add ( this . params , "contour" , 0 , 5 )
431
509
. onChange ( async ( v ) => {
0 commit comments