-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
2702 lines (2097 loc) · 96.3 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
<html>
<head>
<title>Road Generator</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="handlers/Mouse.js"></script>
<script type="text/javascript" src="handlers/OrbitCamera.js"></script>
<script type="text/javascript" src="handlers/FreeCamera.js"></script>
<script type="text/javascript" src="handlers/CameraHandler.js"></script>
<script type="text/javascript" src="handlers/ShaderHandler.js"></script>
<script type="text/javascript" src="objetos/AutosAnimados.js"></script>
<script type="text/javascript" src="objetos/ObjetosFactory.js"></script>
<script type="text/javascript" src="primitivas/FigurasPrimitivas.js"></script>
<script type="text/javascript" src="primitivas/CuadraticBSpline.js"></script>
<script type="text/javascript" src="primitivas/CuadraticBezier.js"></script>
<script type="text/javascript" src="Container3d/BufferCalculator.js"></script>
<script type="text/javascript" src="Container3d/Container3D.js"></script>
<script type="text/javascript" src="Container3d/Objeto3D.js"></script>
<script type="text/javascript" src="gl-matrix.js"></script>
<script type="text/javascript" src="webgl-utils.js"></script>
<script id="shader-fs-colored-obj" type="x-shader/x-fragment">
precision highp float;
uniform vec3 uAmbientColor;
uniform vec3 uDirectionalColor;
varying vec3 vVertexColor;
varying vec3 vLightWeighting;
varying vec3 vNormal;
varying vec3 vViewDir;
varying vec3 vLightDir;
uniform sampler2D uSampler;
void main(void) {
float shininess = 10.0;
// Attenuation constants
const float constantAtt = 1.0;
const float linearAtt = 0.0001;
const float quadraticAtt = 0.01;
vec3 normal = vNormal;
vec3 lightDir = normalize(vLightDir);
vec3 viewDir = vViewDir;
float lambertian = max(dot(lightDir, normal), 0.0);
float specular = 0.2;
if(lambertian > 0.0) {
vec3 reflectDir = reflect(-lightDir, normal);
float specAngle = max(dot(reflectDir, viewDir), 0.0);
specular = pow(specAngle, shininess);
}
vec3 lightIntensity = uAmbientColor + lambertian*uDirectionalColor*10.0 + specular*uDirectionalColor ;
gl_FragColor = vec4(vVertexColor.rgb * lightIntensity, 1.0);
}
</script>
<script id="shader-vs-colored-obj" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec3 aVertexColor;
// attribute vec3 aVertexTangent;
uniform mat4 uViewMatrix;
uniform mat4 uModelMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
uniform vec3 uLightPosition;
uniform bool uUseLighting;
uniform bool uUsingNormalMap;
varying vec3 vVertexColor;
varying vec3 vLightWeighting;
varying vec3 vNormal;
varying vec3 vViewDir;
varying vec3 vLightDir;
void main(void) {
// Transformamos al v�rtice al espacio de la c�mara
vec4 pos_camera_view = uViewMatrix * uModelMatrix * vec4(aVertexPosition, 1.0);
vec4 pos_view = uModelMatrix * vec4(aVertexPosition, 1.0);
// Transformamos al v�rtice al espacio de la proyecci�n
gl_Position = uPMatrix * pos_camera_view;
// Coordenada de textura sin modifiaciones
vVertexColor = aVertexColor;
vec3 pos = vec3(pos_view) / pos_view.w;
vNormal = normalize(uNMatrix * aVertexNormal);
vLightDir = uLightPosition - pos;
vViewDir = normalize(-pos);
}
</script>
<script id="shader-fs-skySphere" type="x-shader/x-fragment">
precision highp float;
uniform vec3 uAmbientColor;
varying vec2 vTextureCoord;
varying float vID;
uniform sampler2D sky;
void main(void) {
vec4 textureColor;
vec2 auxUv = vTextureCoord;
//invierto la textura
auxUv.y = auxUv.y * -1.0;
textureColor = texture2D(sky, vec2(auxUv.s, auxUv.t));
gl_FragColor = vec4(textureColor.rgb * (uAmbientColor + 0.4), textureColor.a);
}
</script>
<script id="shader-vs-skySphere" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
//attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;
attribute float aID;
// attribute vec3 aVertexTangent;
uniform mat4 uViewMatrix;
uniform mat4 uModelMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
varying vec2 vTextureCoord;
varying float vID;
void main(void) {
// Transformamos al v�rtice al espacio de la c�mara
vec4 pos_camera_view = uViewMatrix * uModelMatrix * vec4(aVertexPosition, 1.0);
// Transformamos al v�rtice al espacio de la proyecci�n
gl_Position = uPMatrix * pos_camera_view;
// Coordenada de textura sin modifiaciones
vTextureCoord = aTextureCoord;
//se pasa el id
vID = aID;
}
</script>
<script id="vs-general" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;
attribute vec3 aVertexTangent;
attribute float aID;
uniform mat4 uViewMatrix;
uniform mat4 uModelMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
uniform float attID;
uniform vec3 uAmbientColor;
uniform vec3 uLightPosition;
uniform vec3 uDirectionalColor;
uniform vec3 uFarol1Position;
uniform vec3 uFarol2Position;
uniform vec3 uFarol3Position;
uniform vec3 uFarol4Position;
uniform vec3 uFarol5Position;
uniform vec3 uFarol6Position;
uniform vec3 uFarol7Position;
uniform vec3 uFarol8Position;
uniform vec3 uFarol9Position;
uniform vec3 uFarol10Position;
uniform vec3 uFarol11Position;
uniform bool uUseLighting;
uniform bool uUsingNormalMap;
varying vec2 vTextureCoord;
varying vec3 vLightWeighting;
varying float vID;
varying vec3 reflectDir;
varying vec3 vNormal;
varying vec3 vLightDir;
varying vec3 vViewDir;
varying vec3 vSpotLightDir1;
varying vec3 vSpotLight1;
varying vec3 vSpotLight2;
varying vec3 vSpotLight3;
varying vec3 vSpotLight4;
varying vec3 vSpotLight5;
varying vec3 vSpotLight6;
varying vec3 vSpotLight7;
varying vec3 vSpotLight8;
varying vec3 vSpotLight9;
varying vec3 vSpotLight10;
varying vec3 vSpotLight11;
void main(void) {
// Transformamos al v�rtice al espacio de la c�mara
vec4 pos_camera_view = uViewMatrix * uModelMatrix * vec4(aVertexPosition, 1.0);
vec4 pos_view = uModelMatrix * vec4(aVertexPosition, 1.0);
// Transformamos al v�rtice al espacio de la proyecci�n
gl_Position = uPMatrix * pos_camera_view;
//se pasa el id
vID = attID;
// Coordenada de textura sin modifiaciones
vTextureCoord = aTextureCoord;
vec3 pos = vec3(pos_view) / pos_view.w;
vNormal = normalize(uNMatrix * aVertexNormal);
vLightDir = uLightPosition - pos;
vViewDir = normalize(-pos);
vSpotLight1 = uFarol1Position - pos;
vSpotLight2 = uFarol2Position - pos;
vSpotLight3 = uFarol3Position - pos;
vSpotLight4 = uFarol4Position - pos;
vSpotLight5 = uFarol5Position - pos;
vSpotLight6 = uFarol6Position - pos;
vSpotLight7 = uFarol7Position - pos;
vSpotLight8 = uFarol8Position - pos;
vSpotLight9 = uFarol9Position - pos;
vSpotLight10 = uFarol10Position - pos;
vSpotLight11 = uFarol11Position - pos;
vSpotLightDir1 = vec3(0.0, -1.0, 0.0);
// Transform normal and tangent to eye space
vec3 norm = vNormal;
vec3 tang = normalize(uNMatrix * aVertexTangent);
vec3 binormal = normalize(cross(norm, tang));
if(vID >18.5 && vID <21.5) {
//por ahora solo la autopista y el concreto usan normales
// Matrix for transformation to tangent space
mat3 toObjectLocal = mat3(
tang.x, binormal.x, norm.x,
tang.y, binormal.y, norm.y,
tang.z, binormal.z, norm.z
);
// Transform vectors to tangent space
vLightDir = toObjectLocal * vLightDir;
vViewDir = toObjectLocal * vViewDir;
vSpotLightDir1 = toObjectLocal * vSpotLightDir1;
vSpotLight1 = toObjectLocal * vSpotLight1;
vSpotLight2 = toObjectLocal * vSpotLight2;
vSpotLight3 = toObjectLocal * vSpotLight3;
vSpotLight4 = toObjectLocal * vSpotLight4;
vSpotLight5 = toObjectLocal * vSpotLight5;
vSpotLight6 = toObjectLocal * vSpotLight6;
vSpotLight7 = toObjectLocal * vSpotLight7;
vSpotLight8 = toObjectLocal * vSpotLight8;
vSpotLight9 = toObjectLocal * vSpotLight9;
vSpotLight10 = toObjectLocal * vSpotLight10;
vSpotLight11 = toObjectLocal * vSpotLight11;
}
}
</script>
<script id="fs-street" type="x-shader/x-fragment">
precision highp float;
varying vec2 vTextureCoord;
varying vec3 vLightWeighting;
uniform sampler2D autopista;
uniform sampler2D concreto;
uniform sampler2D poste;
uniform sampler2D puerta;
uniform sampler2D rueda;
uniform sampler2D carroceria;
uniform sampler2D autopistaNormalMap;
uniform sampler2D concretoNormalMap;
//uniform sampler2D posteNormalMap;
//uniform sampler2D puertaNormalMap;
//uniform sampler2D ruedaNormalMap;
//uniform sampler2D carroceriaNormalMap;
// Variables utilizadas para la iluminación
uniform vec3 uAmbientColor;
uniform vec3 uDirectionalColor;
uniform float uShininess;
varying vec3 vNormal;
varying vec3 vLightDir;
varying vec3 vViewDir;
varying vec3 vSpotLightDir1;
varying vec3 vSpotLight1;
varying vec3 vSpotLight2;
varying vec3 vSpotLight3;
varying vec3 vSpotLight4;
varying vec3 vSpotLight5;
varying vec3 vSpotLight6;
varying vec3 vSpotLight7;
varying vec3 vSpotLight8;
varying vec3 vSpotLight9;
varying vec3 vSpotLight10;
varying vec3 vSpotLight11;
varying float vID;
void main(void) {
vec4 textureColor;
bool sinSpot = false;
//variables iluminacion
float shininess = 10.0;
const float spotlightCutOff = 0.7;//CAMBIAR A 0.2 // en radianes
const float spotLightExponent = 10.0;
// Attenuation constants
const float constantAtt = 4.0;
const float linearAtt = 0.0001;
const float quadraticAtt = 0.01;
vec3 normal = vNormal;
vec3 lightDir = normalize(vLightDir);
vec3 viewDir = vViewDir;
float specular = 1.0;
vec3 lightColor = vec3(0.9, 0.9, 0.7);
vec2 auxUv = vTextureCoord;
// Calculos spotlights
vec3 vectorToLightSource = vSpotLight1;
vec3 vectorToLightSource2 = vSpotLight2;
vec3 vectorToLightSource3 = vSpotLight3;
vec3 vectorToLightSource4 = vSpotLight4;
vec3 vectorToLightSource5 = vSpotLight5;
vec3 vectorToLightSource6 = vSpotLight6;
vec3 vectorToLightSource7 = vSpotLight7;
vec3 vectorToLightSource8 = vSpotLight8;
vec3 vectorToLightSource9 = vSpotLight9;
vec3 vectorToLightSource10 = vSpotLight10;
vec3 vectorToLightSource11 = vSpotLight11;
vec3 spotLightIntensity = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity2 = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity3 = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity4 = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity5 = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity6 = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity7 = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity8 = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity9 = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity10 = vec3(0.0,0.0,0.0);
vec3 spotLightIntensity11 = vec3(0.0,0.0,0.0);
if(vID >18.5 && vID <19.5){
auxUv.x = (auxUv.x * 5.0) - 0.48;
textureColor = texture2D(autopista, vec2(auxUv.s, auxUv.t));
// Extrae la normal desde el normalMap
normal = normalize(vec3(2.0 * texture2D(autopistaNormalMap, auxUv) - 1.0));
}
if(vID >20.5 && vID <21.5){
auxUv.y = auxUv.y*10.0;
textureColor = texture2D(concreto, vec2(auxUv.s, auxUv.t));
// Extrae la normal desde el normalMap
normal = normalize(vec3(2.0 * texture2D(concretoNormalMap, auxUv) - 1.0));
}
if(vID >21.5 && vID <22.5){
textureColor = texture2D(poste, vec2(auxUv.s, auxUv.t));
sinSpot = true;
specular = 2.0;
// Extrae la normal desde el normalMap
//normal = normalize(vec3(2.0 * texture2D(posteNormalMap, auxUv) - 1.0));
}
if(vID > 22.5 && vID < 23.5){
textureColor = texture2D(puerta, vec2(auxUv.s, auxUv.t));
}
if(vID > 249.5 && vID < 250.5){
textureColor = texture2D(rueda, vec2(auxUv.s, auxUv.t));
}
if(vID >= 25.5 && vID < 26.5){
textureColor = texture2D(carroceria, vec2(auxUv.s, auxUv.t));
}
if(vID >49.5 && vID <50.5){
textureColor = texture2D(poste, vec2(auxUv.s, auxUv.t));
sinSpot = false;
specular = 2.0;
}
if(vID >50.5 && vID <51.5){
textureColor = texture2D(poste, vec2(auxUv.s, auxUv.t));
sinSpot = false;
specular = 2.0;
}
//mat3 tbn = mat3(vvtangent, vvbinormal, vvnormal);
//normal = normalize(tbn * normal);
float lambertian = max(dot(lightDir, normal), 0.0);
if(lambertian > 0.0) {
vec3 reflectDir = reflect(-lightDir, normal);
float specAngle = max(dot(reflectDir, viewDir), 0.0);
specular = pow(specAngle, shininess);
}
//
float diffuseLightWeighting = max(dot(normal, vectorToLightSource), 0.0);
float diffuseLightWeighting2 = max(dot(normal, vectorToLightSource2), 0.0);
float diffuseLightWeighting3 = max(dot(normal, vectorToLightSource3), 0.0);
float diffuseLightWeighting4 = max(dot(normal, vectorToLightSource4), 0.0);
float diffuseLightWeighting5 = max(dot(normal, vectorToLightSource5), 0.0);
float diffuseLightWeighting6 = max(dot(normal, vectorToLightSource6), 0.0);
float diffuseLightWeighting7 = max(dot(normal, vectorToLightSource7), 0.0);
float diffuseLightWeighting8 = max(dot(normal, vectorToLightSource8), 0.0);
float diffuseLightWeighting9 = max(dot(normal, vectorToLightSource9), 0.0);
float diffuseLightWeighting10 = max(dot(normal, vectorToLightSource10), 0.0);
float diffuseLightWeighting11 = max(dot(normal, vectorToLightSource11), 0.0);
if (diffuseLightWeighting > 0.0) {
// Calculate attenuation
float distance = length(vectorToLightSource);
float att = 1.0/(constantAtt+linearAtt * distance + quadraticAtt * distance * distance);
float spotEffect = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource));
if (spotEffect > spotlightCutOff) {
spotEffect = pow(spotEffect, spotLightExponent);
vec3 reflectionVector = normalize(reflect(-vectorToLightSource, normal));
float rdotv = max(dot(reflectionVector, vViewDir), 0.0);
float specularLightWeighting = pow(rdotv, shininess);
spotLightIntensity = spotEffect * att * (lightColor * diffuseLightWeighting + lightColor * specularLightWeighting);
}
}
if (diffuseLightWeighting2 > 0.0) {
// Calculate attenuation
float distance2 = length(vectorToLightSource2);
float att2 = 1.0/(constantAtt+linearAtt * distance2 + quadraticAtt * distance2 * distance2);
float spotEffect2 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource2));
if (spotEffect2 > spotlightCutOff) {
spotEffect2 = pow(spotEffect2, spotLightExponent);
vec3 reflectionVector2 = normalize(reflect(-vectorToLightSource2, normal));
float rdotv2 = max(dot(reflectionVector2, vViewDir), 0.0);
float specularLightWeighting2 = pow(rdotv2, shininess);
spotLightIntensity2 = spotEffect2 * att2 * (lightColor * diffuseLightWeighting2 + lightColor * specularLightWeighting2);
}
}
if (diffuseLightWeighting3 > 0.0) {
// Calculate attenuation
float distance3 = length(vectorToLightSource3);
float att3 = 1.0/(constantAtt+linearAtt * distance3 + quadraticAtt * distance3 * distance3);
float spotEffect3 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource3));
if (spotEffect3 > spotlightCutOff) {
spotEffect3 = pow(spotEffect3, spotLightExponent);
vec3 reflectionVector3 = normalize(reflect(-vectorToLightSource3, normal));
float rdotv3 = max(dot(reflectionVector3, vViewDir), 0.0);
float specularLightWeighting3 = pow(rdotv3, shininess);
spotLightIntensity3 = spotEffect3 * att3 * (lightColor * diffuseLightWeighting3 + lightColor * specularLightWeighting3);
}
}
if (diffuseLightWeighting4 > 0.0) {
// Calculate attenuation
float distance4 = length(vectorToLightSource4);
float att4 = 1.0/(constantAtt+linearAtt * distance4 + quadraticAtt * distance4 * distance4);
float spotEffect4 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource4));
if (spotEffect4 > spotlightCutOff) {
spotEffect4 = pow(spotEffect4, spotLightExponent);
vec3 reflectionVector4 = normalize(reflect(-vectorToLightSource4, normal));
float rdotv4 = max(dot(reflectionVector4, vViewDir), 0.0);
float specularLightWeighting4 = pow(rdotv4, shininess);
spotLightIntensity4 = spotEffect4 * att4 * (lightColor * diffuseLightWeighting4 + lightColor * specularLightWeighting4);
}
}
if (diffuseLightWeighting5 > 0.0) {
// Calculate attenuation
float distance5 = length(vectorToLightSource5);
float att5 = 1.0/(constantAtt+linearAtt * distance5 + quadraticAtt * distance5 * distance5);
float spotEffect5 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource5));
if (spotEffect5 > spotlightCutOff) {
spotEffect5 = pow(spotEffect5, spotLightExponent);
vec3 reflectionVector5 = normalize(reflect(-vectorToLightSource5, normal));
float rdotv5 = max(dot(reflectionVector5, vViewDir), 0.0);
float specularLightWeighting5 = pow(rdotv5, shininess);
spotLightIntensity5 = spotEffect5 * att5 * (lightColor * diffuseLightWeighting5 + lightColor * specularLightWeighting5);
}
}
if (diffuseLightWeighting6 > 0.0) {
// Calculate attenuation
float distance6 = length(vectorToLightSource6);
float att6 = 1.0/(constantAtt+linearAtt * distance6 + quadraticAtt * distance6 * distance6);
float spotEffect6 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource6));
if (spotEffect6 > spotlightCutOff) {
spotEffect6 = pow(spotEffect6, spotLightExponent);
vec3 reflectionVector6 = normalize(reflect(-vectorToLightSource6, normal));
float rdotv6 = max(dot(reflectionVector6, vViewDir), 0.0);
float specularLightWeighting6 = pow(rdotv6, shininess);
spotLightIntensity6 = spotEffect6 * att6 * (lightColor * diffuseLightWeighting6 + lightColor * specularLightWeighting6);
}
}
if (diffuseLightWeighting7 > 0.0) {
// Calculate attenuation
float distance7 = length(vectorToLightSource7);
float att7 = 1.0/(constantAtt+linearAtt * distance7 + quadraticAtt * distance7 * distance7);
float spotEffect7 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource7));
if (spotEffect7 > spotlightCutOff) {
spotEffect7 = pow(spotEffect7, spotLightExponent);
vec3 reflectionVector7 = normalize(reflect(-vectorToLightSource7, normal));
float rdotv7 = max(dot(reflectionVector7, vViewDir), 0.0);
float specularLightWeighting7 = pow(rdotv7, shininess);
spotLightIntensity7 = spotEffect7 * att7 * (lightColor * diffuseLightWeighting7 + lightColor * specularLightWeighting7);
}
}
if (diffuseLightWeighting8 > 0.0) {
// Calculate attenuation
float distance8 = length(vectorToLightSource8);
float att8 = 1.0/(constantAtt+linearAtt * distance8 + quadraticAtt * distance8 * distance8);
float spotEffect8 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource8));
if (spotEffect8 > spotlightCutOff) {
spotEffect8 = pow(spotEffect8, spotLightExponent);
vec3 reflectionVector8 = normalize(reflect(-vectorToLightSource8, normal));
float rdotv8 = max(dot(reflectionVector8, vViewDir), 0.0);
float specularLightWeighting8 = pow(rdotv8, shininess);
spotLightIntensity8 = spotEffect8 * att8 * (lightColor * diffuseLightWeighting8 + lightColor * specularLightWeighting8);
}
}
if (diffuseLightWeighting9 > 0.0) {
// Calculate attenuation
float distance9 = length(vectorToLightSource9);
float att9 = 1.0/(constantAtt+linearAtt * distance9 + quadraticAtt * distance9 * distance9);
float spotEffect9 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource9));
if (spotEffect9 > spotlightCutOff) {
spotEffect9 = pow(spotEffect9, spotLightExponent);
vec3 reflectionVector9 = normalize(reflect(-vectorToLightSource9, normal));
float rdotv9 = max(dot(reflectionVector9, vViewDir), 0.0);
float specularLightWeighting9 = pow(rdotv9, shininess);
spotLightIntensity9 = spotEffect9 * att9 * (lightColor * diffuseLightWeighting9 + lightColor * specularLightWeighting9);
}
}
if (diffuseLightWeighting10 > 0.0) {
// Calculate attenuation
float distance10 = length(vectorToLightSource10);
float att10 = 1.0/(constantAtt+linearAtt * distance10 + quadraticAtt * distance10 * distance10);
float spotEffect10 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource10));
if (spotEffect10 > spotlightCutOff) {
spotEffect10 = pow(spotEffect10, spotLightExponent);
vec3 reflectionVector10 = normalize(reflect(-vectorToLightSource10, normal));
float rdotv10 = max(dot(reflectionVector10, vViewDir), 0.0);
float specularLightWeighting10 = pow(rdotv10, shininess);
spotLightIntensity10 = spotEffect10 * att10 * (lightColor * diffuseLightWeighting10 + lightColor * specularLightWeighting10);
}
}
if (diffuseLightWeighting11 > 0.0) {
// Calculate attenuation
float distance11 = length(vectorToLightSource11);
float att11 = 1.0/(constantAtt+linearAtt * distance11 + quadraticAtt * distance11 * distance11);
float spotEffect11 = dot(normalize(vSpotLightDir1), normalize(-vectorToLightSource11));
if (spotEffect11 > spotlightCutOff) {
spotEffect11 = pow(spotEffect11, spotLightExponent);
vec3 reflectionVector11 = normalize(reflect(-vectorToLightSource11, normal));
float rdotv11 = max(dot(reflectionVector11, vViewDir), 0.0);
float specularLightWeighting11 = pow(rdotv11, shininess);
spotLightIntensity11 = spotEffect11 * att11 * (lightColor * diffuseLightWeighting11 + lightColor * specularLightWeighting11);
}
}
vec3 lightIntensity = uAmbientColor + spotLightIntensity + spotLightIntensity2 + spotLightIntensity3 + spotLightIntensity4 + spotLightIntensity5 + spotLightIntensity6 + spotLightIntensity7 + spotLightIntensity8 + spotLightIntensity9 + spotLightIntensity10 + spotLightIntensity11 + lambertian*uDirectionalColor*20.0 + (specular)*uDirectionalColor ;
if(sinSpot){
lightIntensity = uAmbientColor + lambertian*uDirectionalColor*15.0 + (specular)*uDirectionalColor ;
}
//vec4 lightMapColor = vec4(1.0,1.0,1.0,1.0);
//vec4 reflectionColor = vec4(0.0,0.0,0.0,1.0);
//vec4 mixedColor = textureColor * lightMapColor + reflectionColor;
gl_FragColor = vec4(textureColor.rgb * lightIntensity, textureColor.a);
}
</script>
<script id="fs-buildingTop" type="x-shader/x-fragment">
precision highp float;
varying vec2 vTextureCoord;
varying vec3 vLightWeighting;
uniform float t;
uniform float count;
// Variables utilizadas para la iluminación
uniform vec3 uAmbientColor;
uniform vec3 uDirectionalColor;
uniform float uShininess;
varying vec3 vNormal;
varying vec3 vLightDir;
varying vec3 vViewDir;
//TOMAMOS ID'S CRECIENTES COMENZANDO POR 0.0
//uniform sampler2D building1;
uniform sampler2D building2;
uniform sampler2D building3;
uniform sampler2D building4;
uniform sampler2D building5;
uniform sampler2D building6;
uniform sampler2D building7;
uniform sampler2D building8;
uniform sampler2D building9;
//uniform sampler2D building10;
uniform sampler2D building11;
uniform sampler2D building12;
uniform sampler2D pb1;
uniform sampler2D pb2;
uniform sampler2D pb3;
uniform sampler2D pb4;
varying float vID;
varying float maxY;
void main(void) {
vec4 textureColor;
vec4 textureColor2;
float factor;
// Coordenada de textura sin modifiaciones
vec4 color = vec4(1.0,0.0,0.0, 1.0);
vec2 auxUv = vTextureCoord;
vec2 auxUv2 = vTextureCoord;
//ajusto la altura de la entrada a partir de la del edificio
factor = 2.8/maxY;
float factorX = 4.0;
float factorpbY = maxY / 2.8;
float factoredY = 5.0;
//variables iluminacion
float shininess = 1.0;
// Attenuation constants
const float constantAtt = 1.0;
const float linearAtt = 0.0001;
const float quadraticAtt = 0.01;
vec3 normal = vNormal;
vec3 lightDir = normalize(vLightDir);
vec3 viewDir = vViewDir;
float lambertian = max(dot(lightDir, normal), 0.0);
float specular = 10.0;
if(lambertian > 0.0) {
vec3 reflectDir = reflect(-lightDir, normal);
float specAngle = max(dot(reflectDir, viewDir), 0.0);
specular = pow(specAngle, shininess);
}
/*if(maxY>= 15.1 && maxY<16.1){
auxUv2.x = auxUv2.x * factorX;
auxUv2.y = auxUv2.y * factoredY;
auxUv.x = auxUv.x * factorX;
auxUv.y = auxUv.y * factorpbY;
if(vID >= 1.5 && vID < 5.5){
textureColor = texture2D(building2, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb2, vec2(auxUv.s, auxUv.t));
}
if(vID >= 5.5 && vID < 9.5){
textureColor = texture2D(building3, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb3, vec2(auxUv.s, auxUv.t));
}
if(vID >= 9.5 && vID < 13.5){
textureColor = texture2D(building5, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
}
else{
auxUv2.x = auxUv2.x * factorX;
auxUv2.y = auxUv2.y * factoredY;
auxUv.x = auxUv.x * factorX;
auxUv.y = auxUv.y * factorpbY;
if(vID >= 1.5 && vID < 5.5){
textureColor = texture2D(building1, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
if(vID >= 5.5 && vID < 9.5){
textureColor = texture2D(building8, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
}
if(vID >= 9.5 && vID < 13.5){
textureColor = texture2D(building9, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
}
}*/
if(maxY>= 14.0 && maxY<15.8){
auxUv2.x = auxUv2.x * factorX;
auxUv2.y = auxUv2.y * factoredY;
auxUv.x = auxUv.x * factorX;
auxUv.y = auxUv.y * factorpbY;
if(vID >= 1.5 && vID < 3.5){
textureColor = texture2D(building3, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb3, vec2(auxUv.s, auxUv.t));
}
if( vID >= 3.5 && vID < 4.5){
textureColor = texture2D(building5, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb2, vec2(auxUv.s, auxUv.t));
}
if( vID >= 4.5 && vID < 5.5){
textureColor = texture2D(building2, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
if(vID >= 5.5 && vID < 6.5){
textureColor = texture2D(building3, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
}
if(vID >= 6.5 && vID < 8.5 ){
textureColor = texture2D(building5, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
if( vID >= 8.5 && vID < 11.5 ){
textureColor = texture2D(building2, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb2, vec2(auxUv.s, auxUv.t));
}
if(vID >= 11.5 && vID < 12.5){
textureColor = texture2D(building3, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb3, vec2(auxUv.s, auxUv.t));
}
if(vID >= 12.5 && vID < 13.5){
textureColor = texture2D(building5, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
}
}
else if(maxY>= 15.8 && maxY<16.2){
auxUv2.x = auxUv2.x * factorX;
auxUv2.y = auxUv2.y * factoredY;
auxUv.x = auxUv.x * factorX;
auxUv.y = auxUv.y * factorpbY;
if(vID >= 1.5 && vID < 3.5){
textureColor = texture2D(building6, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
if(vID >= 3.5 && vID < 5.5){
textureColor = texture2D(building12, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb2, vec2(auxUv.s, auxUv.t));
}
if(vID >= 5.5 && vID < 6.5){
textureColor = texture2D(building6, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb3, vec2(auxUv.s, auxUv.t));
}
if(vID >= 6.5 && vID < 7.5){
textureColor = texture2D(building12, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
}
if(vID >= 7.5 && vID < 9.5){
textureColor = texture2D(building6, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
if(vID >= 9.5 && vID < 12.5){
textureColor = texture2D(building12, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb2, vec2(auxUv.s, auxUv.t));
}
if(vID >= 12.5 && vID < 13.5){
textureColor = texture2D(building6, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb3, vec2(auxUv.s, auxUv.t));
}
}
else if(maxY>= 16.2 && maxY<19.1){
auxUv2.x = auxUv2.x * factorX;
auxUv2.y = auxUv2.y * factoredY;
auxUv.x = auxUv.x * factorX;
auxUv.y = auxUv.y * factorpbY;
if(vID >= 1.5 && vID < 3.5){
textureColor = texture2D(building9, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
}
if( vID >= 3.5 && vID < 4.5){
textureColor = texture2D(building8, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
if( vID >= 4.5 && vID < 5.5){
textureColor = texture2D(building9, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb2, vec2(auxUv.s, auxUv.t));
}
if(vID >= 5.5 && vID < 6.5){
textureColor = texture2D(building8, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb3, vec2(auxUv.s, auxUv.t));
}
if( vID >= 6.5 && vID < 8.5){
textureColor = texture2D(building8, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
}
if(vID >= 8.5 && vID < 11.5 ){
textureColor = texture2D(building9, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
if(vID >= 11.5 && vID < 12.5){
textureColor = texture2D(building8, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb2, vec2(auxUv.s, auxUv.t));
}
if( vID >= 12.5 && vID < 13.5){
textureColor = texture2D(building9, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb3, vec2(auxUv.s, auxUv.t));
}
}
else if(maxY>= 19.1 && maxY<23.1){
auxUv2.x = auxUv2.x * factorX;
auxUv2.y = auxUv2.y * factoredY;
auxUv.x = auxUv.x * factorX;
auxUv.y = auxUv.y * factorpbY;
if(vID >= 1.5 && vID < 3.5){
textureColor = texture2D(building4, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
}
if(vID >= 3.5 && vID < 5.5){
textureColor = texture2D(building7, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
if(vID >= 5.5 && vID < 6.5){
textureColor = texture2D(building4, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb2, vec2(auxUv.s, auxUv.t));
}
if(vID >= 6.5 && vID < 7.5){
textureColor = texture2D(building7, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb3, vec2(auxUv.s, auxUv.t));
}
if(vID >= 7.5 && vID < 9.5){
textureColor = texture2D(building4, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
}
if(vID >= 9.5 && vID < 12.5){
textureColor = texture2D(building7, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
if(vID >= 12.5 && vID < 13.5){
textureColor = texture2D(building4, vec2(auxUv2.s, auxUv2.t));
textureColor2 = texture2D(pb1, vec2(auxUv.s, auxUv.t));
}
}
// else{
//
// auxUv2.x = auxUv2.x * factorX;
// auxUv2.y = auxUv2.y * factoredY;
// auxUv.x = auxUv.x * factorX;
// auxUv.y = auxUv.y * factorpbY;
//
// textureColor = texture2D(building11, vec2(auxUv2.s, auxUv2.t));
// textureColor2 = texture2D(pb4, vec2(auxUv.s, auxUv.t));
//
//
// }
if((vTextureCoord.y) < factor){
color.x=textureColor2.x;
color.y=textureColor2.y;
color.z=textureColor2.z;
}
else{
color.x=textureColor.x;
color.y=textureColor.y;
color.z=textureColor.z;
}
textureColor = color;
vec3 lightIntensity = uAmbientColor + lambertian*uDirectionalColor*2.0 + specular*uDirectionalColor ;
//vec4 lightMapColor = vec4(1.0,1.0,1.0,1.0);
//vec4 reflectionColor = vec4(0.0,0.0,0.0,1.0);
//vec4 mixedColor = textureColor * lightMapColor + reflectionColor;
gl_FragColor = vec4(textureColor.rgb * lightIntensity, textureColor.a);
}
</script>
<script id="vs-buildingTop" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;
//attribute vec3 aVertexTangent;
uniform float aID;
uniform mat4 uViewMatrix;
uniform mat4 uModelMatrix;
uniform mat4 uPMatrix;