-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1499 lines (1154 loc) · 63.8 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!-- saved from url=(0052)http://webgl3d.info/ex/ch03_eg01_SingleTriangle.html -->
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="fileOther/stylesheet.css">
<script src="fileOther/commonFunctions.js">
</script>
<script src="fileOther/gl-matrix-min.js">
</script>
<script src="fileOther/webglTools.js">
</script>
<script>
/***************************************************************************************************************
* shader for the first rendering *
**************************************************************************************************************/
</script>
<script id="shader-vs-0" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 textCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = textCoord;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs-0" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
varying vec2 vTexCoord;
uniform sampler2D uSampler;
void main(void) {
vec4 color = texture2D(uSampler, vTexCoord);
gl_FragColor = color;
}
</script>
<script>
/***************************************************************************************************************
* shader for the second rendering BLUR *
**************************************************************************************************************/
</script>
<script id="shader-vs-1" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 textCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = textCoord;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs-1" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D uSampler;
uniform float blur_alpha;
varying vec2 vTexCoord;
uniform float tex_width;
uniform float tex_height;
void main(void) {
float dx = 1.0/tex_width;
float dy = 1.0/tex_height;
vec2 coordinateTex = vec2(vTexCoord.s, vTexCoord.t);
vec2 coordinateTex_x = vec2(vTexCoord.s, vTexCoord.t-dx);
vec2 coordinateTex_X = vec2(vTexCoord.s, vTexCoord.t+dx);
vec2 coordinateTex_y = vec2(vTexCoord.s-dy, vTexCoord.t);
vec2 coordinateTex_Y = vec2(vTexCoord.s+dy, vTexCoord.t);
vec4 tex = texture2D(uSampler, coordinateTex);
vec4 tex_x = texture2D(uSampler, coordinateTex_x);
vec4 tex_X = texture2D(uSampler, coordinateTex_X);
vec4 tex_y = texture2D(uSampler, coordinateTex_y);
vec4 tex_Y = texture2D(uSampler, coordinateTex_Y);
float neigh_alpha = blur_alpha/4.0;
vec4 current_color = tex*(1.0-blur_alpha) + tex_x*neigh_alpha + tex_X*neigh_alpha + tex_y*neigh_alpha + tex_Y*neigh_alpha;
gl_FragColor = current_color;
}
</script>
<script>
/***************************************************************************************************************
* shader for the 3 : GRADIENT *
**************************************************************************************************************/
</script>
<script id="shader-vs-2" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 textCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = textCoord;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs-2" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D uSampler;
varying vec2 vTexCoord;
uniform float tex_width;
uniform float tex_height;
uniform float orient_tolerence; // between 0.01 to 0.25
void main(void) {
float dx = 1.0 / tex_width;
float dy = 1.0 / tex_height;
//--- Neighborhood "states": ---
vec2 coordinateTex = vec2(vTexCoord.s, vTexCoord.t);
vec2 coordinateTex_x = vec2(vTexCoord.s, vTexCoord.t-dx);
vec2 coordinateTex_X = vec2(vTexCoord.s, vTexCoord.t+dx);
vec2 coordinateTex_y = vec2(vTexCoord.s-dy, vTexCoord.t);
vec2 coordinateTex_Y = vec2(vTexCoord.s+dy, vTexCoord.t);
vec4 tex = texture2D(uSampler, coordinateTex);
vec4 tex_x = texture2D(uSampler, coordinateTex_x);
vec4 tex_X = texture2D(uSampler, coordinateTex_X);
vec4 tex_y = texture2D(uSampler, coordinateTex_y);
vec4 tex_Y = texture2D(uSampler, coordinateTex_Y);
//--- Shader core: ---
float Gx = 0.0;
float Gy = 0.0;
// 1. Luminance at (x, X, y, and Y) from -1 to 1:
float lum_x = (tex_x.r+tex_x.g+tex_x.b)/1.5 -1.;
float lum_X = (tex_X.r+tex_X.g+tex_X.b)/1.5 -1.;
float lum_y = (tex_y.r+tex_y.g+tex_y.b)/1.5 -1.;
float lum_Y = (tex_Y.r+tex_Y.g+tex_Y.b)/1.5 -1.;
// 2. Gradient over (x) and (y) axes:
if( ((lum_X > orient_tolerence) && (lum_x < -orient_tolerence)) ||
((lum_X < -orient_tolerence) && (lum_x > orient_tolerence)) )
Gx = lum_X-lum_x;
if( ((lum_Y > orient_tolerence) && (lum_y < -orient_tolerence)) ||
((lum_Y < -orient_tolerence) && (lum_y > orient_tolerence)) )
Gy = lum_Y-lum_y;
// 3. pertinent angle cells:
gl_FragColor.rgba = vec4(0.0,1.0,0.0,1.0);
if( abs( Gx ) > orient_tolerence )
{
gl_FragColor.g = 0.0;
gl_FragColor.r += 1.;
if( Gx*Gy < 0. ) gl_FragColor.r -= 0.5;
}
if( abs( Gy ) > orient_tolerence )
{
gl_FragColor.g = 0.0;
gl_FragColor.b += 1.;
if( Gx*Gy < 0. ) gl_FragColor.b -= 0.5;
}
// 4. if green (and therefore no gradiant) => plug webcam input image
if( gl_FragColor.g > 0.99 ){
gl_FragColor = tex;
}else{
// write in green the diagonals
if( (gl_FragColor.b == 0.5) && (gl_FragColor.r == .5) )
{
gl_FragColor.g = 1.0;
gl_FragColor.r = 1.0;
gl_FragColor.b = 0.0;
}
else if( (gl_FragColor.b == 1.0) && (gl_FragColor.r == 1.0) )
{
gl_FragColor.g = 1.0;
gl_FragColor.r = 0.0;
gl_FragColor.b = 1.0;
}
}
}
</script>
<script>
/***************************************************************************************************************
* shader for the PERSISTENT *
**************************************************************************************************************/
</script>
<script id="shader-vs-3" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 textCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = textCoord;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs-3" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D uSamplerA;
uniform sampler2D uSamplerB;
uniform float persistence; // entre 1 et 0
varying vec2 vTexCoord;
void main( void )
{
vec3 old_texture = texture2D(uSamplerA, vTexCoord.xy).rgb;
vec3 new_texture = texture2D(uSamplerB, vTexCoord.xy).rgb;
gl_FragColor.xyz = (1.0-persistence)*new_texture.xyz + persistence*old_texture.xyz;
gl_FragColor.a = 1.0;
}
</script>
<script>
/***************************************************************************************************************
* shader for the SOUSTRACTION TEXT *
**************************************************************************************************************/
</script>
<script id="shader-vs-4" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 textCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = textCoord;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs-4" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D uSamplerA;
uniform sampler2D uSamplerB;
uniform float contrast_coef;
varying vec2 vTexCoord;
void main( void )
{
vec3 TexCone = texture2D(uSamplerA, vTexCoord.xy).rgb;
vec3 TexHorizontal = texture2D(uSamplerB, vTexCoord.xy).rgb;
//TexCone.r = 0.3;
//--- texture substraction;
vec3 current_color = TexHorizontal - TexCone;
// Pour afficher au moin une soustraction
//gl_FragColor.rgb = current_color;
gl_FragColor.rgb = 0.5 + current_color*contrast_coef;
gl_FragColor.a = 1.0;
}
</script>
<script>
/***************************************************************************************************************
* shader for the SOUSTRACTION TEXT BOOLEAN *
**************************************************************************************************************/
</script>
<script id="shader-vs-5" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 textCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = textCoord;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs-5" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D uSamplerA;
uniform sampler2D uSamplerB;
uniform float contrast_coef;
varying vec2 vTexCoord;
void main( void )
{
vec3 TexCone = texture2D(uSamplerA, vTexCoord.xy).rgb;
vec3 TexHorizontal = texture2D(uSamplerB, vTexCoord.xy).rgb;
vec3 current_color = TexHorizontal - TexCone;
gl_FragColor.rgb = 0.5 + current_color * contrast_coef;
if( gl_FragColor.r<0.0 ) gl_FragColor.r = 0.0;
if( gl_FragColor.g<0.0 ) gl_FragColor.g = 0.0;
if( gl_FragColor.b<0.0 ) gl_FragColor.b = 0.0;
if( gl_FragColor.r>1.0 ) gl_FragColor.r = 1.0;
if( gl_FragColor.g>1.0 ) gl_FragColor.g = 1.0;
if( gl_FragColor.b>1.0 ) gl_FragColor.b = 1.0;
if( (gl_FragColor.r<0.45)&&(gl_FragColor.g<0.45)&&(gl_FragColor.b<0.45) )
{
gl_FragColor.rgb = vec3( 0.0, 0.0, 0.0 );
}
else if( (gl_FragColor.r>0.55)&&(gl_FragColor.g>0.55)&&(gl_FragColor.b>0.55) )
{
gl_FragColor.rgb = vec3( 1.0, 1.0, 1.0 );
}
else
{
gl_FragColor.rgb = vec3( 0.5, 0.5, 0.5 );
}
gl_FragColor.a = 1.0;
}
</script>
<script>
/***************************************************************************************************************
* shader for the ACTIVE CELL *
**************************************************************************************************************/
</script>
<script id="shader-vs-6" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 textCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = textCoord;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs-6" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D uSamplerA;
uniform sampler2D uSamplerB;
varying vec2 vTexCoord;
uniform float fill_area_threshold;
uniform float tex_width;
uniform float tex_height;
void main( void )
{
float dx = 1.0/tex_width;
float dy = 1.0/tex_height;
vec2 coordinateTex = vec2(vTexCoord.s, vTexCoord.t);
vec2 coordinateTex_x = vec2(vTexCoord.s, vTexCoord.t-dx);
vec2 coordinateTex_X = vec2(vTexCoord.s, vTexCoord.t+dx);
vec2 coordinateTex_y = vec2(vTexCoord.s-dy, vTexCoord.t);
vec2 coordinateTex_Y = vec2(vTexCoord.s+dy, vTexCoord.t);
vec2 coordinateTex_xy = vec2(vTexCoord.s-dy, vTexCoord.t-dx);
vec2 coordinateTex_Xy = vec2(vTexCoord.s-dy, vTexCoord.t+dx);
vec2 coordinateTex_xY = vec2(vTexCoord.s+dy, vTexCoord.t-dx);
vec2 coordinateTex_XY = vec2(vTexCoord.s+dy, vTexCoord.t+dx);
vec3 tex_INF = texture2D( uSamplerB, coordinateTex ).xyz;
vec3 tex = texture2D( uSamplerA, coordinateTex ).xyz;
vec3 tex_x = texture2D( uSamplerA, coordinateTex_x ).xyz;
vec3 tex_X = texture2D( uSamplerA, coordinateTex_X ).xyz;
vec3 tex_y = texture2D( uSamplerA, coordinateTex_y ).xyz;
vec3 tex_Y = texture2D( uSamplerA, coordinateTex_Y ).xyz;
vec3 tex_xy = texture2D( uSamplerA, coordinateTex_xy ).xyz;
vec3 tex_Xy = texture2D( uSamplerA, coordinateTex_Xy ).xyz;
vec3 tex_xY = texture2D( uSamplerA, coordinateTex_xY ).xyz;
vec3 tex_XY = texture2D( uSamplerA, coordinateTex_XY ).xyz;
//---
// 0. Init
float intensity = tex.r-tex.b;
float max_grey_intensity = 0.4;
float texture_influence_lumin = (tex_INF.r+tex_INF.g+tex_INF.b)/ 3.0;
// 1. influence of the new_data:
if( texture_influence_lumin > .5+fill_area_threshold )
intensity = 1.0;
else if( texture_influence_lumin < .5-fill_area_threshold )
intensity = -1.0;
else
{
// 2. Current surrounding influence:
// 2.1 Counting neighbor white/black majority:
float max_red = 0.0;
float max_blue = 0.0;
if( (tex_x.r > max_red) ) max_red = tex_x.r;
else if( tex_x.b > max_blue ) max_blue = tex_x.b;
if( (tex_y.r > max_red) ) max_red = tex_y.r;
else if( tex_y.b > max_blue ) max_blue = tex_y.b;
if( (tex_X.r > max_red) ) max_red = tex_X.r;
else if( tex_X.b > max_blue ) max_blue = tex_X.b;
if( (tex_Y.r > max_red) ) max_red = tex_Y.r;
else if( tex_Y.b > max_blue ) max_blue = tex_Y.b;
// 2.2 current influence:
if( max_red+max_blue > 0.0 )
{
if( max_red > max_blue )
intensity = max_red*.95;
else
intensity = -max_blue*.95;
}
}
// 3. final color:
if( intensity > 0.0 )
gl_FragColor.rgb = vec3( intensity, 0.0, 0.0);
else if (intensity < 0.0)
gl_FragColor.rgb = vec3( 0.0, 0.0, -intensity);
else
gl_FragColor.rgb = vec3( 0.0, 0.0, 0.0);
gl_FragColor.a = 1.0;
}
</script>
<script>
/***************************************************************************************************************
* shader for the RenderTexture *
**************************************************************************************************************/
</script>
<script id="shader-vs-Render" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 textCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = textCoord;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs-Render" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D uSampler;
varying vec2 vTexCoord;
void main(void) {
vec4 color = texture2D(uSampler, vTexCoord);
gl_FragColor = color;
}
</script>
<script>
/*
parametre gobron retina
blur_alpha = 0.50; // 50%
cone_blur_factor = 3;
horizontal_blur_factor = 7;
persistence_horiCell = 0.85; // 80%
persistence_anacCell = 0.85; // 80%
contrast_coef = 1.0;
orient_tolerence = 0.01; // between 0.001 and 0.499
fill_area_threshold = .011; // between 0.001 and 0.499
*/
var nbIterationBlurCell = 3;
var nbIterationBlurHorizontal = 6;
var nbIterationGradient = 3;
var alphaBlur = 1.0;
var persistanceHoriz = 0.85;
var toleranceGradient = 0.20;
var coefSubsTex = 0.5;
// parametre indiquant quelle buffer contient la derniere texture correct ( cas des multipasse)
var shaderfinalWebcam = 0;
var shaderfinalBlurCone = 0;
var shaderfinalBlurHoriz = 0;
var shaderFinalPersistence = 0;
var shaderfinalGradient = 0;
var shaderfinalSubsText = 7;
// dessin du carré pour le rendu. carré qui prend le canevas (rendu final)
var squareVertexBuffer = null;
var squareIndexBuffer = null;
var indicesSquareCanevas = [];
var verticesSquareCanevas = [];
var textCoords = new Array();
var textureBuffersArray = [];
var mvMatrix = mat4.create();
var pMatrix = mat4.create();
// parametre des Frames Buffers
var rttFrameBufferTab = [];
var rttTextureTab = [];
var nombreFrameBuffer = 12;
// parametre pour la gestion des multi programme contenant les shader
var progList = [];
var ptr = new Object();
// parametre pour la webcam
var textureWebcam = null;
var video = null;
function initShaders() {
/*******************************************
* Inits the shader for the first rendering
*******************************************/
//Selection of the 2 shader texts for the first rendering (webcam)
var vertexShader0 = getTextContent("shader-vs-0");
var fragmentShader0 = getTextContent("shader-fs-0");
//Create the program for the shader
progList[0] = createProgram(glContext, vertexShader0, fragmentShader0);
/*******************************************
* Inits the shader for the BLUR
*******************************************/
var vertexShaderScene1 = getTextContent("shader-vs-1");
var fragmentShaderScene1 = getTextContent("shader-fs-1");
progList[1] = createProgram(glContext, vertexShaderScene1, fragmentShaderScene1);
/*******************************************
* Inits the shader for the GRADIENT
*******************************************/
var vertexShaderScene2 = getTextContent("shader-vs-2");
var fragmentShaderScene2 = getTextContent("shader-fs-2");
progList[2] = createProgram(glContext, vertexShaderScene2, fragmentShaderScene2);
/*******************************************
* Inits the shader for the PERSISTENT
*******************************************/
var vertexShaderScene3 = getTextContent("shader-vs-3");
var fragmentShaderScene3 = getTextContent("shader-fs-3");
progList[3] = createProgram(glContext, vertexShaderScene3, fragmentShaderScene3);
/*******************************************
* Inits the shader for the SOUSTRACTION TEXTURE
*******************************************/
var vertexShaderScene4 = getTextContent("shader-vs-4");
var fragmentShaderScene4 = getTextContent("shader-fs-4");
progList[4] = createProgram(glContext, vertexShaderScene4, fragmentShaderScene4);
/*******************************************
* Inits the shader for the SOUSTRACTION TEXTURE BOOLEAN
*******************************************/
var vertexShaderScene5 = getTextContent("shader-vs-5");
var fragmentShaderScene5 = getTextContent("shader-fs-5");
progList[5] = createProgram(glContext, vertexShaderScene5, fragmentShaderScene5);
/*******************************************
* Inits the shader for the SOUSTRACTION TEXTURE BOOLEAN
*******************************************/
var vertexShaderScene6 = getTextContent("shader-vs-6");
var fragmentShaderScene6 = getTextContent("shader-fs-6");
progList[6] = createProgram(glContext, vertexShaderScene6, fragmentShaderScene6);
/*******************************************
* Inits the shader for the rendering
*******************************************/
var vertexShaderSceneRender = getTextContent("shader-vs-Render");
var fragmentShaderSceneRender = getTextContent("shader-fs-Render");
progList[10] = createProgram(glContext, vertexShaderSceneRender, fragmentShaderSceneRender);
initShaderParameters();
//We define the planet progam as the current program
glContext.useProgram(progList[0]);
}
function initShaderParameters() {
/*******************************************
* Inits the pointers for the first rendering drawForm
*******************************************/
ptr.vertexPositionAttribute0 = glContext.getAttribLocation(progList[0], "aVertexPosition");
glContext.enableVertexAttribArray(ptr.vertexPositionAttribute0);
ptr.pMatrixUniform0 = glContext.getUniformLocation(progList[0], 'uPMatrix');
ptr.mvMatrixUniform0 = glContext.getUniformLocation(progList[0], 'uMVMatrix');
ptr.textureCoordsAttribute0 = glContext.getAttribLocation(progList[0], "textCoord");
glContext.enableVertexAttribArray(ptr.textureCoordsAttribute0);
ptr.samplerUniform0 = glContext.getUniformLocation(progList[0], "uSampler");
/*******************************************
* Inits the pointers for the second rendering BLUR
*******************************************/
ptr.vertexPositionAttribute1 = glContext.getAttribLocation(progList[1], "aVertexPosition");
glContext.enableVertexAttribArray(ptr.vertexPositionAttribute1);
ptr.textureCoordsAttribute1 = glContext.getAttribLocation(progList[1], "textCoord");
glContext.enableVertexAttribArray(ptr.textureCoordsAttribute1);
ptr.pMatrixUniform1 = glContext.getUniformLocation(progList[1], 'uPMatrix');
ptr.mvMatrixUniform1 = glContext.getUniformLocation(progList[1], 'uMVMatrix');
ptr.samplerUniform1 = glContext.getUniformLocation(progList[1], "uSampler");
ptr.tex_width1 = glContext.getUniformLocation(progList[1], "tex_width");
ptr.tex_height1 = glContext.getUniformLocation(progList[1], "tex_height");
ptr.blur_alpha = glContext.getUniformLocation(progList[1], "blur_alpha");
/*******************************************
* Inits the pointers for the GRADIENT
*******************************************/
ptr.vertexPositionAttribute2 = glContext.getAttribLocation(progList[2], "aVertexPosition");
glContext.enableVertexAttribArray(ptr.vertexPositionAttribute2);
ptr.textureCoordsAttribute2 = glContext.getAttribLocation(progList[2], "textCoord");
glContext.enableVertexAttribArray(ptr.textureCoordsAttribute2);
ptr.pMatrixUniform2 = glContext.getUniformLocation(progList[2], 'uPMatrix');
ptr.mvMatrixUniform2 = glContext.getUniformLocation(progList[2], 'uMVMatrix');
ptr.samplerUniform2 = glContext.getUniformLocation(progList[2], "uSampler");
ptr.tex_width2 = glContext.getUniformLocation(progList[2], "tex_width");
ptr.tex_height2 = glContext.getUniformLocation(progList[2], "tex_height");
ptr.orient_tolerence = glContext.getUniformLocation(progList[2], "orient_tolerence");
/*******************************************
* Inits the pointers for the PERSISTENT
*******************************************/
ptr.vertexPositionAttribute3 = glContext.getAttribLocation(progList[3], "aVertexPosition");
glContext.enableVertexAttribArray(ptr.vertexPositionAttribute3);
ptr.textureCoordsAttribute3 = glContext.getAttribLocation(progList[3], "textCoord");
glContext.enableVertexAttribArray(ptr.textureCoordsAttribute3);
ptr.pMatrixUniform3 = glContext.getUniformLocation(progList[3], 'uPMatrix');
ptr.mvMatrixUniform3 = glContext.getUniformLocation(progList[3], 'uMVMatrix');
ptr.samplerUniformA3 = glContext.getUniformLocation(progList[3], "uSamplerA");
ptr.samplerUniformB3 = glContext.getUniformLocation(progList[3], "uSamplerB");
ptr.persistence = glContext.getUniformLocation(progList[3], "persistence");
/*******************************************
* Inits the pointers for the SOUSTRACTION TEXTURE
*******************************************/
ptr.vertexPositionAttribute4 = glContext.getAttribLocation(progList[4], "aVertexPosition");
glContext.enableVertexAttribArray(ptr.vertexPositionAttribute4);
ptr.textureCoordsAttribute4 = glContext.getAttribLocation(progList[4], "textCoord");
glContext.enableVertexAttribArray(ptr.textureCoordsAttribute4);
ptr.pMatrixUniform4 = glContext.getUniformLocation(progList[4], 'uPMatrix');
ptr.mvMatrixUniform4 = glContext.getUniformLocation(progList[4], 'uMVMatrix');
ptr.samplerUniformA4 = glContext.getUniformLocation(progList[4], "uSamplerA");
ptr.samplerUniformB4 = glContext.getUniformLocation(progList[4], "uSamplerB");
ptr.contrast_coef = glContext.getUniformLocation(progList[4], "contrast_coef");
/*******************************************
* Inits the pointers for the SOUSTRACTION TEXTURE BOOLEAN
*******************************************/
ptr.vertexPositionAttribute5 = glContext.getAttribLocation(progList[5], "aVertexPosition");
glContext.enableVertexAttribArray(ptr.vertexPositionAttribute5);
ptr.textureCoordsAttribute5 = glContext.getAttribLocation(progList[5], "textCoord");
glContext.enableVertexAttribArray(ptr.textureCoordsAttribute5);
ptr.pMatrixUniform5 = glContext.getUniformLocation(progList[5], 'uPMatrix');
ptr.mvMatrixUniform5 = glContext.getUniformLocation(progList[5], 'uMVMatrix');
ptr.samplerUniformA5 = glContext.getUniformLocation(progList[5], "uSamplerA");
ptr.samplerUniformB5 = glContext.getUniformLocation(progList[5], "uSamplerB");
ptr.contrast_coef5 = glContext.getUniformLocation(progList[5], "contrast_coef");
/*******************************************
* Inits the pointers for the ACTIVE CELL FILTER
*******************************************/
ptr.vertexPositionAttribute6 = glContext.getAttribLocation(progList[6], "aVertexPosition");
glContext.enableVertexAttribArray(ptr.vertexPositionAttribute6);
ptr.textureCoordsAttribute6 = glContext.getAttribLocation(progList[6], "textCoord");
glContext.enableVertexAttribArray(ptr.textureCoordsAttribute6);
ptr.pMatrixUniform6 = glContext.getUniformLocation(progList[6], 'uPMatrix');
ptr.mvMatrixUniform6 = glContext.getUniformLocation(progList[6], 'uMVMatrix');
ptr.samplerUniformA6 = glContext.getUniformLocation(progList[6], "uSamplerA");
ptr.samplerUniformB6 = glContext.getUniformLocation(progList[6], "uSamplerB");
ptr.tex_width6 = glContext.getUniformLocation(progList[6], "tex_width");
ptr.tex_height6 = glContext.getUniformLocation(progList[6], "tex_height");
ptr.fill_area_threshold = glContext.getUniformLocation(progList[6], "fill_area_threshold");
/*******************************************
* Inits the pointers for the rendering programme
*******************************************/
ptr.vertexPositionAttributeRender = glContext.getAttribLocation(progList[10], "aVertexPosition");
glContext.enableVertexAttribArray(ptr.vertexPositionAttributeRender);
ptr.textureCoordsAttributeRender = glContext.getAttribLocation(progList[10], "textCoord");
glContext.enableVertexAttribArray(ptr.textureCoordsAttributeRender);
ptr.pMatrixUniformRender = glContext.getUniformLocation(progList[10], 'uPMatrix');
ptr.mvMatrixUniformRender = glContext.getUniformLocation(progList[10], 'uMVMatrix');
ptr.samplerUniformRender = glContext.getUniformLocation(progList[10], "uSampler");
}
function initTextureFramebufferTab() {
for (i = 0; i < nombreFrameBuffer; i++) {
rttFrameBufferTab[i] = glContext.createFramebuffer();
glContext.bindFramebuffer(glContext.FRAMEBUFFER, rttFrameBufferTab[i]);
rttFrameBufferTab[i].width = 512;
rttFrameBufferTab[i].height = 512;
// espace pour la texture sur la cg (WEBTOOL textureWithImage)
rttTextureTab[i] = glContext.createTexture();
glContext.bindTexture(glContext.TEXTURE_2D, rttTextureTab[i]);
glContext.texParameteri(glContext.TEXTURE_2D, glContext.TEXTURE_MAG_FILTER, glContext.LINEAR);
glContext.texParameteri(glContext.TEXTURE_2D, glContext.TEXTURE_MIN_FILTER, glContext.LINEAR_MIPMAP_NEAREST);
glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, rttFrameBufferTab[i].width, rttFrameBufferTab[i].height, 0, glContext.RGBA, glContext.UNSIGNED_BYTE, null);
// mtn on a préparer un espace pour la texture qui est vide et de taille du rttFramebuffer. contiendra pour les couleurs, le canevas.
// on va définir le buffer de rendu
var renderbuffer = glContext.createRenderbuffer();
glContext.bindRenderbuffer(glContext.RENDERBUFFER, renderbuffer);
glContext.renderbufferStorage(glContext.RENDERBUFFER, glContext.DEPTH_COMPONENT16, rttFrameBufferTab[i].width, rttFrameBufferTab[i].height);
/*
* Nous attachons tout à la framebuffer actuelle (rappelez-vous, nous avons lié notre nouveau pour être le courant juste après sa création en haut de la fonction).
* Nous lui disons que l'espace du framebuffer pour les couleurs de rendu ( gl.COLOR_ATTACHMENT0 ) est notre texture, et que la mémoire qu'il doit utiliser pour
* obtenir des informations de profondeur ( gl.DEPTH_ATTACHMENT ) est le tampon de profondeur que nous venons de créer.
* */
glContext.framebufferTexture2D(glContext.FRAMEBUFFER, glContext.COLOR_ATTACHMENT0, glContext.TEXTURE_2D, rttTextureTab[i], 0);
glContext.framebufferRenderbuffer(glContext.FRAMEBUFFER, glContext.DEPTH_ATTACHMENT, glContext.RENDERBUFFER, renderbuffer);
/*
* maintenant que tout est correctement créer est binder, on les remets a 0
* */
glContext.bindTexture(glContext.TEXTURE_2D, null);
glContext.bindRenderbuffer(glContext.RENDERBUFFER, null);
glContext.bindFramebuffer(glContext.FRAMEBUFFER, null);
}
}
function initBuffers() {
// POS X Y Z
verticesSquareCanevas.push(-1.0, 1.0, 0.1);
verticesSquareCanevas.push(-1.0, -1.0, 0.1);
verticesSquareCanevas.push(1.0, 1.0, 0.1);
verticesSquareCanevas.push(1.0, -1.0, 0.1);
indicesSquareCanevas.push(0, 1, 2, 3);
squareVertexBuffer = getVertexBufferWithVertices(verticesSquareCanevas);
squareIndexBuffer = getIndexBufferWithIndices(indicesSquareCanevas);
// POS X Y pour la texture
textCoords = [
0, 1,
0, 0,
1, 1,
1, 0,
];
textureBuffersArray = getArrayBufferWithArray(textCoords);
}
function drawScene() {
// initialise la webcam
initTextureWebcam();
glContext.useProgram(progList[0]);
// ******************************************************************************************
// ***** *****
// ***** DESSINE SUR LE PREMIER FRAME BUFFER LA WEBCAM *****
// ***** *****
// ******************************************************************************************
// etablie le frameBUFFER
glContext.bindFramebuffer(glContext.FRAMEBUFFER, rttFrameBufferTab[shaderfinalWebcam]);
// clear le buffer
glContext.viewport(0, 0, rttFrameBufferTab[shaderfinalWebcam].width, rttFrameBufferTab[shaderfinalWebcam].height);
glContext.enable(glContext.DEPTH_TEST);
glContext.clear(glContext.COLOR_BUFFER_BIT | glContext.DEPTH_BUFFER_BIT);
mat4.identity(pMatrix);
mat4.identity(mvMatrix);
glContext.activeTexture(glContext.TEXTURE0);
glContext.bindTexture(glContext.TEXTURE_2D, textureWebcam);
glContext.uniform1i(ptr.samplerUniform0, 0);
glContext.uniformMatrix4fv(ptr.pMatrixUniform0, false, pMatrix);
glContext.uniformMatrix4fv(ptr.mvMatrixUniform0, false, mvMatrix);
glContext.bindBuffer(glContext.ARRAY_BUFFER, squareVertexBuffer);
glContext.vertexAttribPointer(ptr.vertexPositionAttribute0, 3, glContext.FLOAT, false, 0, 0);
glContext.bindBuffer(glContext.ARRAY_BUFFER, textureBuffersArray);
glContext.vertexAttribPointer(ptr.textureCoordsAttribute0, 2, glContext.FLOAT, false, 0, 0);
glContext.bindBuffer(glContext.ELEMENT_ARRAY_BUFFER, squareIndexBuffer);
// type du graphique
glContext.drawElements(glContext.TRIANGLE_STRIP, indicesSquareCanevas.length, glContext.UNSIGNED_SHORT, 0);
glContext.bindTexture(glContext.TEXTURE_2D, rttTextureTab[shaderfinalWebcam]);
glContext.generateMipmap(glContext.TEXTURE_2D);
glContext.bindTexture(glContext.TEXTURE_2D, null);
// mis en place du buffer frame
glContext.bindFramebuffer(glContext.FRAMEBUFFER, null);
// affichage de la texture de base dans le canvas0
createImageFromTexture(glContext, "canvas0", rttTextureTab[0], 512, 512);
// ******************************************************************************************
// ***** *****
// ***** DESSINE SUR LE cone FRAME BUFFER ( BLUR ) *****
// ***** *****
// ******************************************************************************************
glContext.useProgram(progList[1]);
var numTextureEntrer = 0;
var numTextureSortie = 0;
for (i = 0; i < nbIterationBlurCell; i++) {
if (i == 0) {
numTextureSortie = 1;
numTextureEntrer = shaderfinalWebcam;
} else if (i % 2 == 0) {
numTextureSortie = 1;
numTextureEntrer = 2;
}
else {
numTextureSortie = 2;
numTextureEntrer = 1;
}
glContext.bindFramebuffer(glContext.FRAMEBUFFER, rttFrameBufferTab[numTextureSortie]);
// clear le buffer
glContext.viewport(0, 0, rttFrameBufferTab[numTextureSortie].width, rttFrameBufferTab[numTextureSortie].height);
glContext.enable(glContext.DEPTH_TEST);
glContext.clear(glContext.COLOR_BUFFER_BIT | glContext.DEPTH_BUFFER_BIT);
mat4.identity(pMatrix);
mat4.identity(mvMatrix);
glContext.activeTexture(glContext.TEXTURE0);
glContext.bindTexture(glContext.TEXTURE_2D, rttTextureTab[numTextureEntrer]);
glContext.uniform1i(ptr.samplerUniform1, 0);
glContext.uniformMatrix4fv(ptr.pMatrixUniform1, false, pMatrix);
glContext.uniformMatrix4fv(ptr.mvMatrixUniform1, false, mvMatrix);
glContext.bindBuffer(glContext.ARRAY_BUFFER, squareVertexBuffer);
glContext.vertexAttribPointer(ptr.vertexPositionAttribute1, 3, glContext.FLOAT, false, 0, 0);
glContext.bindBuffer(glContext.ARRAY_BUFFER, textureBuffersArray);
glContext.vertexAttribPointer(ptr.textureCoordsAttribute1, 2, glContext.FLOAT, false, 0, 0);
glContext.uniform1f(ptr.blur_alpha, alphaBlur);
glContext.uniform1f(ptr.tex_height1, rttFrameBufferTab[numTextureSortie].height);
glContext.uniform1f(ptr.tex_width1, rttFrameBufferTab[numTextureSortie].width);
glContext.bindBuffer(glContext.ELEMENT_ARRAY_BUFFER, squareIndexBuffer);
glContext.drawElements(glContext.TRIANGLE_STRIP, indicesSquareCanevas.length, glContext.UNSIGNED_SHORT, 0);
glContext.bindTexture(glContext.TEXTURE_2D, rttTextureTab[numTextureSortie]);
shaderfinalBlurCone = numTextureSortie;
glContext.generateMipmap(glContext.TEXTURE_2D);
glContext.bindTexture(glContext.TEXTURE_2D, null);
// mis en place du buffer frame
glContext.bindFramebuffer(glContext.FRAMEBUFFER, null);
}
// affiche le resultat après blur par les cones
createImageFromTexture(glContext, "canvas1", rttTextureTab[shaderfinalBlurCone], 512, 512);
// ******************************************************************************************
// ***** *****
// ***** DESSINE SUR LE FRAME BUFFER (BLUR HORIZONTAL ET Persistante ) *****
// ***** *****
// ******************************************************************************************
var numTextureEntrer1 = shaderfinalBlurCone;
var numTextureEntrer2 = 0;