-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
1868 lines (1537 loc) · 82.6 KB
/
Copy pathmain.js
File metadata and controls
1868 lines (1537 loc) · 82.6 KB
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
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x000000);
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.set(4, 1.6, 4); // 最初の部屋に配置(中央付近)
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const roomSize = 10;
const mazeSize = 5;
// 迷路マップ (1=壁, 0=通路, 2=部屋) - 最適化された巨大迷宮
const mazeLayout = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,2,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,1],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
[1,2,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,1],
[1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1],
[1,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,2,1],
[1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,1],
[1,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,1],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
[1,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,2,1],
[1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,1,1,0,1,0,1],
[1,2,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,1],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
[1,2,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,1],
[1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1],
[1,2,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,1],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
[1,2,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,1],
[1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
[1,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,2,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];
// プレイヤーの状態
let playerPos = { x: 4, z: 4 }; // 最初の部屋の位置(中央付近の部屋)
let currentRoom = 1;
let rooms = new Map();
// マウス視線制御
let mouseX = 0, mouseY = 0;
let cameraRotationY = 0, cameraRotationX = 0;
let isMouseDown = false;
let mouseSensitivity = 0.002;
// タッチ制御用
let touchStartX = 0, touchStartY = 0;
let isTouchDragging = false;
let lastTouchTime = 0;
let touchMoveVector = { x: 0, z: 0 };
let isTouchMoving = false;
const patternVertexShader = `
varying vec2 vUv;
varying vec3 vPosition;
void main() {
vUv = uv;
vPosition = position;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const patternFragmentShader = `
uniform float time;
uniform float intensity;
uniform vec3 baseColor;
uniform float roomTheme;
varying vec2 vUv;
varying vec3 vPosition;
float noise(vec2 p) {
return fract(sin(dot(p.xy, vec2(12.9898,78.233))) * 43758.5453);
}
float fbm(vec2 p) {
float f = 0.0;
f += 0.5000 * noise(p); p = p * 2.01;
f += 0.2500 * noise(p); p = p * 2.02;
f += 0.1250 * noise(p); p = p * 2.03;
f += 0.0625 * noise(p);
return f;
}
// ガラスのようなキラキラ光沢アルミニウム効果を作成
vec3 createMirrorEffect(vec2 uv, float t, float intensity) {
// 非常に明るいアルミニウムベース色(ガラスのような透明感)
vec3 glassyAluminum = vec3(0.95, 0.97, 1.0);
// ガラスのような屈折効果
vec2 refraction = vec2(
sin(uv.x * 40.0 + t * 2.5) * 0.005,
cos(uv.y * 35.0 + t * 2.0) * 0.005
);
vec2 glossyUV = uv + refraction;
// 強力なフレネル効果(ガラス特有)
vec2 center = vec2(0.5, 0.5);
float distFromCenter = length(uv - center);
float glassFresnel = pow(1.0 - dot(normalize(vec3(uv - center, 0.1)), vec3(0, 0, 1)), 3.0);
glassFresnel = clamp(glassFresnel, 0.3, 1.0);
// 虹色の分散効果(プリズム効果)
float dispersion = sin(glossyUV.x * 50.0 + t * 3.0) * cos(glossyUV.y * 45.0 + t * 2.5);
vec3 spectrum = vec3(
sin(dispersion * 3.14159 + t) * 0.5 + 0.5,
sin(dispersion * 3.14159 + t + 2.09) * 0.5 + 0.5,
sin(dispersion * 3.14159 + t + 4.19) * 0.5 + 0.5
) * 0.15;
// キラキラ効果(スパークル)
float sparkle1 = noise(glossyUV * 150.0 + t * 10.0);
sparkle1 = pow(max(sparkle1 - 0.8, 0.0) * 5.0, 4.0);
float sparkle2 = noise(glossyUV * 120.0 + t * 8.0 + vec2(100.0));
sparkle2 = pow(max(sparkle2 - 0.85, 0.0) * 6.67, 6.0);
float sparkle3 = noise(glossyUV * 180.0 + t * 12.0 + vec2(200.0));
sparkle3 = pow(max(sparkle3 - 0.9, 0.0) * 10.0, 8.0);
// 超強力なハイライト(鏡面反射)
float specular1 = sin(glossyUV.x * 20.0 + t * 4.0) * cos(glossyUV.y * 18.0 + t * 3.5);
specular1 = pow(max(specular1, 0.0), 25.0) * 1.5;
float specular2 = cos(glossyUV.x * 12.0 - t * 2.5) * sin(glossyUV.y * 15.0 - t * 2.0);
specular2 = pow(max(specular2, 0.0), 20.0) * 1.2;
// 動的な光線効果
float rayEffect = sin(glossyUV.x * 8.0 + glossyUV.y * 3.0 + t * 5.0);
rayEffect = pow(max(rayEffect, 0.0), 30.0) * 0.8;
// 環境マッピング風の反射
float envMapping = sin(glossyUV.x * 6.0 + t * 0.8) * sin(glossyUV.y * 4.0 + t * 1.2) * 0.1 + 0.98;
// すべての効果を合成
vec3 finalColor = glassyAluminum * envMapping * glassFresnel;
// スペクトラム効果を追加
finalColor += spectrum;
// キラキラ効果を追加
finalColor += vec3(sparkle1 + sparkle2 + sparkle3) * 2.0;
// 鏡面反射を追加
finalColor += vec3(specular1 + specular2 + rayEffect);
// 超超高輝度
finalColor *= (1.8 + intensity * 0.8);
// ガラス特有の色調(より鮮やかに)
finalColor.r *= 1.05;
finalColor.g *= 1.1;
finalColor.b *= 1.15;
return clamp(finalColor, 0.0, 1.0);
}
void main() {
vec2 uv = vUv * 20.0; // 解像度を大幅に上げる
float t = time * 0.8 + roomTheme * 15.0; // 速度も少し上げる
vec2 morphedUV = uv + vec2(
sin(uv.y * 6.0 + t) * 0.5 * intensity,
cos(uv.x * 4.0 + t * 2.0) * 0.5 * intensity
) + vec2(
sin(uv.x * 8.0 + t * 1.3) * 0.2,
cos(uv.y * 10.0 + t * 0.7) * 0.2
);
float pattern1, pattern2, pattern3;
// 部屋のテーマによってパターンを変更(催眠渦模様を追加)
if (roomTheme < 1.0) {
// 催眠的な渦模様(画像のような)
vec2 center = vec2(10.0, 10.0);
float angle = atan(morphedUV.y - center.y, morphedUV.x - center.x);
float radius = length(morphedUV - center);
// 催眠渦の基本パターン
float spiral = angle + radius * 0.3 - t * 3.0;
float hypnoticRings = sin(radius * 4.0 - t * 2.0) * 0.5 + 0.5;
float spiralWave = sin(spiral * 8.0) * 0.5 + 0.5;
pattern1 = mix(hypnoticRings, spiralWave, sin(t * 0.5) * 0.5 + 0.5);
pattern2 = sin(angle * 12.0 + radius * 2.0 - t * 4.0) * cos(radius * 6.0 + t * 2.5);
} else if (roomTheme < 2.0) {
// 多重催眠渦
vec2 center1 = vec2(8.0, 8.0);
vec2 center2 = vec2(12.0, 12.0);
float angle1 = atan(morphedUV.y - center1.y, morphedUV.x - center1.x);
float radius1 = length(morphedUV - center1);
float angle2 = atan(morphedUV.y - center2.y, morphedUV.x - center2.x);
float radius2 = length(morphedUV - center2);
float spiral1 = sin(angle1 * 10.0 + radius1 * 3.0 - t * 4.0);
float spiral2 = cos(angle2 * 8.0 - radius2 * 2.5 + t * 3.5);
pattern1 = (spiral1 + spiral2) * 0.5;
pattern2 = sin(radius1 * 5.0 - t * 3.0) * cos(radius2 * 4.0 + t * 2.0);
} else if (roomTheme < 3.0) {
// 高解像度チェッカーボード + 渦
float angle = atan(morphedUV.y - 10.0, morphedUV.x - 10.0);
float radius = length(morphedUV - vec2(10.0));
pattern1 = step(0.5, mod(morphedUV.x + t + sin(angle * 4.0), 1.0)) * step(0.5, mod(morphedUV.y + t * 1.3, 0.8));
pattern2 = sin(angle * 16.0 + radius * 2.0 - t * 5.0) * step(0.3, mod(radius + t, 1.2));
} else {
// 放射状催眠パターン
vec2 center = vec2(10.0, 10.0);
float angle = atan(morphedUV.y - center.y, morphedUV.x - center.x);
float radius = length(morphedUV - center);
// 放射状の線
float radialLines = sin(angle * 24.0 + t * 2.0) * 0.5 + 0.5;
// 同心円
float concentricCircles = sin(radius * 8.0 - t * 4.0) * 0.5 + 0.5;
// 螺旋
float hypnoSpiral = sin(angle * 6.0 + radius * 1.5 - t * 3.0) * 0.5 + 0.5;
pattern1 = mix(radialLines, concentricCircles, sin(t * 0.3) * 0.5 + 0.5);
pattern2 = mix(hypnoSpiral, fbm(morphedUV * 0.8 + t * 0.1), cos(t * 0.4) * 0.5 + 0.5);
}
pattern3 = sin(length(morphedUV - vec2(10.0)) * 16.0 - t * 6.0) * cos(length(morphedUV - vec2(5.0)) * 12.0 + t * 4.0);
float noisePattern = fbm(morphedUV + t * 0.2) * 2.0 - 1.0;
float kaleidoscope = sin(atan(morphedUV.y - 10.0, morphedUV.x - 10.0) * (12.0 + roomTheme * 4.0) + t * 4.0);
kaleidoscope *= sin(length(morphedUV - vec2(10.0)) * 8.0 - t * 4.0) * cos(length(morphedUV - vec2(5.0)) * 6.0 + t * 3.0);
float combined = (pattern1 + pattern2 + pattern3 + noisePattern + kaleidoscope) * 0.2;
combined = smoothstep(-0.8, 0.8, combined);
// 円形マスクを作成(中心のみサイケデリック、外側は黒)
vec2 center = vec2(0.5, 0.5); // テクスチャ座標の中心
float radius = 0.4; // 円の半径
float distanceFromCenter = length(vUv - center);
float circleMask = smoothstep(radius, radius - 0.05, distanceFromCenter); // ソフトエッジ
// 部屋テーマによる色の変更(黒を含むサイケデリック)
vec3 color1, color2, color3, color4, color5, color6, color7, color8, color9, color10, color11, color12;
if (roomTheme < 1.0) {
// 青・シアン系 超鮮やか
color1 = vec3(0.0, 1.0, 1.0); color2 = vec3(1.0, 0.0, 1.0); // シアン→マゼンタ
color3 = vec3(1.0, 0.3, 1.0); color4 = vec3(0.0, 0.6, 1.0);
color5 = vec3(0.0, 1.0, 1.0); color6 = vec3(0.2, 1.0, 0.8); // 明るいシアン
color7 = vec3(0.6, 0.8, 1.0); color8 = vec3(1.0, 0.5, 1.0); // ライトブルー→マゼンタ
color9 = vec3(0.8, 0.3, 1.0); color10 = vec3(0.2, 1.0, 1.0);
color11 = vec3(0.5, 0.5, 1.0); color12 = vec3(0.2, 0.9, 1.0); // ブルー
} else if (roomTheme < 2.0) {
// 赤・マゼンタ系 超鮮やか
color1 = vec3(1.0, 0.3, 0.3); color2 = vec3(1.0, 1.0, 0.0); // レッド→イエロー
color3 = vec3(1.0, 0.0, 0.8); color4 = vec3(1.0, 0.5, 0.0); // マゼンタ→オレンジ
color5 = vec3(1.0, 0.6, 0.9); color6 = vec3(1.0, 0.2, 1.0);
color7 = vec3(1.0, 0.8, 0.0); color8 = vec3(1.0, 0.4, 1.0); // ゴールド→マゼンタ
color9 = vec3(1.0, 0.9, 0.5); color10 = vec3(1.0, 0.0, 0.5); // ライトオレンジ→ピンク
color11 = vec3(1.0, 0.5, 0.2); color12 = vec3(1.0, 0.3, 0.9);
} else if (roomTheme < 3.0) {
// 緑・ライム系 超鮮やか
color1 = vec3(0.5, 1.0, 0.5); color2 = vec3(0.8, 1.0, 0.0); // ライトグリーン→ライム
color3 = vec3(0.0, 1.0, 0.8); color4 = vec3(1.0, 1.0, 0.3); // ターコイズ→イエロー
color5 = vec3(0.7, 1.0, 0.7); color6 = vec3(0.3, 1.0, 0.3); // 明るい緑
color7 = vec3(0.9, 1.0, 0.4); color8 = vec3(0.3, 1.0, 0.9);
color9 = vec3(0.6, 1.0, 0.0); color10 = vec3(0.0, 1.0, 0.6); // ライム→緑
color11 = vec3(1.0, 1.0, 0.2); color12 = vec3(0.4, 1.0, 0.4); // イエロー→グリーン
} else {
// レインボー 超鮮やか
color1 = vec3(1.0, 0.0, 1.0); color2 = vec3(1.0, 0.5, 0.0); // マゼンタ→オレンジ
color3 = vec3(0.0, 1.0, 1.0); color4 = vec3(0.5, 1.0, 0.0); // シアン→ライムグリーン
color5 = vec3(0.6, 0.0, 1.0); color6 = vec3(1.0, 0.0, 0.6);
color7 = vec3(1.0, 1.0, 0.0); color8 = vec3(1.0, 0.9, 0.3); // イエロー→ゴールド
color9 = vec3(0.9, 0.3, 1.0); color10 = vec3(0.0, 0.8, 1.0); // バイオレット→スカイブルー
color11 = vec3(1.0, 0.7, 0.9); color12 = vec3(0.3, 1.0, 0.7); // ピンク→ミント
}
float colorCycle = t * 3.0 + combined * 6.0 + roomTheme * 4.0; // より速い色変化
float colorIndex = mod(colorCycle, 12.0); // 12色に拡張
vec3 finalColor;
if (colorIndex < 1.0) {
finalColor = mix(color1, color2, fract(colorIndex));
} else if (colorIndex < 2.0) {
finalColor = mix(color2, color3, fract(colorIndex));
} else if (colorIndex < 3.0) {
finalColor = mix(color3, color4, fract(colorIndex));
} else if (colorIndex < 4.0) {
finalColor = mix(color4, color5, fract(colorIndex));
} else if (colorIndex < 5.0) {
finalColor = mix(color5, color6, fract(colorIndex));
} else if (colorIndex < 6.0) {
finalColor = mix(color6, color7, fract(colorIndex));
} else if (colorIndex < 7.0) {
finalColor = mix(color7, color8, fract(colorIndex));
} else if (colorIndex < 8.0) {
finalColor = mix(color8, color9, fract(colorIndex));
} else if (colorIndex < 9.0) {
finalColor = mix(color9, color10, fract(colorIndex));
} else if (colorIndex < 10.0) {
finalColor = mix(color10, color11, fract(colorIndex));
} else if (colorIndex < 11.0) {
finalColor = mix(color11, color12, fract(colorIndex));
} else {
finalColor = mix(color12, color1, fract(colorIndex));
}
// 黒いベース色(床)の場合は完全に黒を維持
if (baseColor.r < 0.01 && baseColor.g < 0.01 && baseColor.b < 0.01) {
// 床は完全に黒
finalColor = vec3(0.0, 0.0, 0.0);
} else {
// 全面サイケデリック効果
float saturation = 5.0 + intensity * 3.0; // 超強い彩度
vec3 grayScale = vec3(dot(finalColor, vec3(0.299, 0.587, 0.114)));
finalColor = mix(grayScale, finalColor, saturation);
// 追加のサイケデリック効果(高解像度)
float wave1 = sin(uv.x * 16.0 + t * 4.0) * sin(uv.y * 12.0 + t * 3.0);
float wave2 = cos(uv.x * 10.0 - t * 3.6) * cos(uv.y * 20.0 + t * 4.6);
float wave3 = sin(uv.x * 8.0 + t * 2.5) * cos(uv.y * 14.0 - t * 3.2);
float extraPsych = (wave1 + wave2 + wave3) * 0.33;
// 強力なレインボー効果
float rainbow = sin(colorCycle * 0.8 + extraPsych * 2.0) * 0.5 + 0.5;
vec3 rainbowColor = vec3(
sin(rainbow * 6.28 * 2.0),
sin(rainbow * 6.28 * 2.0 + 2.09),
sin(rainbow * 6.28 * 2.0 + 4.19)
) * 0.5 + 0.5;
// より強力なサイケデリックカラーミックス
vec3 psychColor1 = vec3(1.0, 0.0, 1.0); // ピュアマゼンタ
vec3 psychColor2 = vec3(0.0, 1.0, 0.0); // ピュア緑
vec3 psychColor3 = vec3(0.0, 0.0, 1.0); // ピュア青
vec3 psychColor4 = vec3(1.0, 1.0, 0.0); // ピュア黄
vec3 psychColor5 = vec3(1.0, 0.0, 0.0); // ピュア赤
vec3 psychColor6 = vec3(0.0, 1.0, 1.0); // ピュアシアン
float psychPhase = combined * 6.0 + t * 1.6;
vec3 psychMix1 = mix(
mix(psychColor1, psychColor2, sin(psychPhase) * 0.5 + 0.5),
mix(psychColor3, psychColor4, cos(psychPhase * 1.3) * 0.5 + 0.5),
sin(psychPhase * 0.7) * 0.5 + 0.5
);
vec3 psychMix2 = mix(
mix(psychColor5, psychColor6, sin(psychPhase * 1.7) * 0.5 + 0.5),
mix(psychColor1, psychColor3, cos(psychPhase * 0.9) * 0.5 + 0.5),
sin(psychPhase * 1.2) * 0.5 + 0.5
);
// 全ての色を超強力に混合
finalColor = mix(finalColor, rainbowColor, intensity * 0.8 + 0.5);
finalColor = mix(finalColor, psychMix1, 0.6 + intensity * 0.5);
finalColor = mix(finalColor, psychMix2, 0.5 + intensity * 0.4);
finalColor = mix(finalColor, baseColor, 0.01); // ベース色の影響を最小化
// 明るさを超強化
float brightness = 1.5 + intensity * 1.5 + combined * 1.2;
finalColor *= brightness;
// 最低限の明るさを保証(超明るく)
finalColor = max(finalColor, vec3(0.4, 0.4, 0.4));
// 色の彩度を最大化
finalColor = clamp(finalColor, 0.0, 1.0);
}
gl_FragColor = vec4(finalColor, 1.0);
}
`;
const mirrorVertexShader = `
varying vec2 vUv;
varying vec3 vWorldPosition;
void main() {
vUv = uv;
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorldPosition = worldPosition.xyz;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const mirrorFragmentShader = `
uniform float time;
uniform float intensity;
uniform samplerCube envMap;
varying vec2 vUv;
varying vec3 vWorldPosition;
void main() {
vec3 viewDirection = normalize(vWorldPosition - cameraPosition);
vec3 reflected = reflect(viewDirection, normalize(vWorldPosition));
vec3 envColor = textureCube(envMap, reflected).rgb;
float fresnel = pow(1.0 - abs(dot(normalize(vWorldPosition), viewDirection)), 2.0);
vec3 baseReflection = mix(envColor, vec3(0.2, 0.4, 0.8), 0.3);
float ripple = sin(length(vUv - vec2(0.5)) * 20.0 - time * 3.0) * 0.1 * intensity;
baseReflection += vec3(ripple);
gl_FragColor = vec4(baseReflection * (0.7 + fresnel * 0.3), 0.9);
}
`;
// マテリアルプール - 同じパターンのマテリアルを再利用
const materialPool = new Map();
const sharedUniforms = {
time: { value: 0 },
intensity: { value: 0 }
};
function getMaterialKey(baseColor, roomTheme) {
return `${baseColor.r}_${baseColor.g}_${baseColor.b}_${roomTheme}`;
}
function createPatternMaterial(baseColor, roomTheme) {
const key = getMaterialKey(baseColor, roomTheme);
// 既存のマテリアルがあれば再利用
if (materialPool.has(key)) {
return materialPool.get(key);
}
// 新しいマテリアルを作成
const material = new THREE.ShaderMaterial({
uniforms: {
time: sharedUniforms.time, // 共有uniform
intensity: sharedUniforms.intensity, // 共有uniform
baseColor: { value: baseColor },
roomTheme: { value: roomTheme }
},
vertexShader: patternVertexShader,
fragmentShader: patternFragmentShader,
side: THREE.DoubleSide
});
materialPool.set(key, material);
return material;
}
const cubeRenderTarget = new THREE.WebGLCubeRenderTarget(256);
const cubeCamera = new THREE.CubeCamera(0.1, 1000, cubeRenderTarget);
scene.add(cubeCamera);
const mirrorMaterial = new THREE.ShaderMaterial({
uniforms: {
time: { value: 0 },
intensity: { value: 0 },
envMap: { value: cubeRenderTarget.texture }
},
vertexShader: mirrorVertexShader,
fragmentShader: mirrorFragmentShader,
transparent: true,
side: THREE.DoubleSide
});
// 迷路構造を作成
const cellSize = 4;
const wallHeight = 4;
const mazeGroup = new THREE.Group();
scene.add(mazeGroup);
// 共有ジオメトリ - 同じ形状を再利用
const sharedFloorGeometry = new THREE.PlaneGeometry(cellSize, cellSize);
const sharedWallGeometry = new THREE.PlaneGeometry(cellSize, wallHeight);
const sharedBlockGeometry = new THREE.BoxGeometry(cellSize, wallHeight, cellSize);
function createRoom(x, z, theme, mazeX, mazeZ, mazeData) {
const roomGroup = new THREE.Group();
// 床と天井は純粋な黒のマテリアルを使用
const blackMaterial = new THREE.MeshBasicMaterial({ color: 0x000000, side: THREE.DoubleSide });
// 床
const floor = new THREE.Mesh(sharedFloorGeometry, blackMaterial);
floor.rotation.x = -Math.PI / 2;
floor.position.set(x * cellSize, -wallHeight / 2, z * cellSize);
roomGroup.add(floor);
// 天井(同じマテリアルを再利用)
const ceiling = new THREE.Mesh(sharedFloorGeometry, blackMaterial);
ceiling.rotation.x = Math.PI / 2;
ceiling.position.set(x * cellSize, wallHeight / 2, z * cellSize);
roomGroup.add(ceiling);
// 壁を追加(部屋を立方体として認識できるように)
// 各部屋の4面に壁を追加(通路がある方向は開ける)
const wallColors = [
new THREE.Vector3(0.8, 0.3, 0.5),
new THREE.Vector3(0.3, 0.8, 0.5),
new THREE.Vector3(0.5, 0.3, 0.8),
new THREE.Vector3(0.8, 0.8, 0.3)
];
// 迷路データから隣接セルをチェック
const hasNorthOpening = mazeData && mazeZ > 0 && mazeData[mazeZ-1][mazeX] === 0;
const hasSouthOpening = mazeData && mazeZ < mazeData.length-1 && mazeData[mazeZ+1][mazeX] === 0;
const hasEastOpening = mazeData && mazeX < mazeData[0].length-1 && mazeData[mazeZ][mazeX+1] === 0;
const hasWestOpening = mazeData && mazeX > 0 && mazeData[mazeZ][mazeX-1] === 0;
// 北壁(通路がなければ設置)
if (!hasNorthOpening) {
const northWall = new THREE.Mesh(
sharedWallGeometry,
createPatternMaterial(wallColors[0], theme)
);
northWall.position.set(x * cellSize, 0, (z - 0.5) * cellSize);
roomGroup.add(northWall);
}
// 南壁(通路がなければ設置)
if (!hasSouthOpening) {
const southWall = new THREE.Mesh(
sharedWallGeometry,
createPatternMaterial(wallColors[1], theme)
);
southWall.position.set(x * cellSize, 0, (z + 0.5) * cellSize);
southWall.rotation.y = Math.PI;
roomGroup.add(southWall);
}
// 東壁(通路がなければ設置)
if (!hasEastOpening) {
const eastWall = new THREE.Mesh(
sharedWallGeometry,
createPatternMaterial(wallColors[2], theme)
);
eastWall.position.set((x + 0.5) * cellSize, 0, z * cellSize);
eastWall.rotation.y = -Math.PI / 2;
roomGroup.add(eastWall);
}
// 西壁(通路がなければ設置)
if (!hasWestOpening) {
const westWall = new THREE.Mesh(
sharedWallGeometry,
createPatternMaterial(wallColors[3], theme)
);
westWall.position.set((x - 0.5) * cellSize, 0, z * cellSize);
westWall.rotation.y = Math.PI / 2;
roomGroup.add(westWall);
}
return roomGroup;
}
function createWall(x, z, direction) {
// 位置に基づいて決定的な色とテーマを生成(同じ位置の壁は常に同じ見た目)
const seed = x * 1000 + z;
const colorIndex = Math.abs(seed) % 5;
const themeIndex = Math.abs(seed) % 4;
// 事前定義された色パレット
const colors = [
new THREE.Vector3(0.6, 0.4, 0.8),
new THREE.Vector3(0.8, 0.6, 0.4),
new THREE.Vector3(0.4, 0.8, 0.6),
new THREE.Vector3(0.7, 0.5, 0.7),
new THREE.Vector3(0.5, 0.7, 0.8)
];
const wallMaterial = createPatternMaterial(colors[colorIndex], themeIndex);
const wall = new THREE.Mesh(sharedWallGeometry, wallMaterial);
if (direction === 'north') {
wall.position.set(x * cellSize, 0, (z - 0.5) * cellSize);
} else if (direction === 'south') {
wall.position.set(x * cellSize, 0, (z + 0.5) * cellSize);
wall.rotation.y = Math.PI;
} else if (direction === 'east') {
wall.position.set((x + 0.5) * cellSize, 0, z * cellSize);
wall.rotation.y = -Math.PI / 2;
} else if (direction === 'west') {
wall.position.set((x - 0.5) * cellSize, 0, z * cellSize);
wall.rotation.y = Math.PI / 2;
}
return wall;
}
// エンドレス迷路のためのチャンク管理
const chunkSize = mazeLayout[0].length;
const loadedChunks = new Map();
const renderDistance = 1; // プレイヤーの周囲1チャンク分をロード(パフォーマンス最適化)
let roomCount = 1;
function getChunkKey(chunkX, chunkZ) {
return `${chunkX},${chunkZ}`;
}
function createMazeChunk(chunkX, chunkZ) {
const chunkGroup = new THREE.Group();
// メインの構造を作成
for (let z = 0; z < mazeLayout.length; z++) {
for (let x = 0; x < mazeLayout[z].length; x++) {
const cell = mazeLayout[z][x];
const worldX = chunkX * chunkSize + x - Math.floor(mazeLayout[0].length / 2);
const worldZ = chunkZ * chunkSize + z - Math.floor(mazeLayout.length / 2);
if (cell === 2) { // 部屋
const room = createRoom(worldX, worldZ, (roomCount + chunkX + chunkZ) % 4, x, z, mazeLayout);
chunkGroup.add(room);
rooms.set(`${worldX},${worldZ}`, roomCount);
roomCount++;
} else if (cell === 1) { // 壁
// 位置に基づいて決定的なマテリアルを選択
const wallSeed = (worldX + chunkX * 100) * 1000 + (worldZ + chunkZ * 100);
const wallColorIndex = Math.abs(wallSeed) % 3;
const wallThemeIndex = Math.abs(wallSeed) % 4;
const wallColors = [
new THREE.Vector3(0.3, 0.2, 0.4),
new THREE.Vector3(0.4, 0.3, 0.5),
new THREE.Vector3(0.5, 0.2, 0.3)
];
const wallBlock = new THREE.Mesh(
sharedBlockGeometry,
createPatternMaterial(wallColors[wallColorIndex], wallThemeIndex)
);
wallBlock.position.set(worldX * cellSize, 0, worldZ * cellSize);
chunkGroup.add(wallBlock);
}
}
}
// 通路の壁を追加
for (let z = 0; z < mazeLayout.length; z++) {
for (let x = 0; x < mazeLayout[z].length; x++) {
const cell = mazeLayout[z][x];
const worldX = chunkX * chunkSize + x - Math.floor(mazeLayout[0].length / 2);
const worldZ = chunkZ * chunkSize + z - Math.floor(mazeLayout.length / 2);
if (cell === 0) { // 通路
// 隣接セルをチェックして必要な壁を作成
if (z > 0 && mazeLayout[z-1][x] === 1) {
chunkGroup.add(createWall(worldX, worldZ, 'north'));
}
if (z < mazeLayout.length-1 && mazeLayout[z+1][x] === 1) {
chunkGroup.add(createWall(worldX, worldZ, 'south'));
}
if (x > 0 && mazeLayout[z][x-1] === 1) {
chunkGroup.add(createWall(worldX, worldZ, 'west'));
}
if (x < mazeLayout[z].length-1 && mazeLayout[z][x+1] === 1) {
chunkGroup.add(createWall(worldX, worldZ, 'east'));
}
}
}
}
return chunkGroup;
}
function updateChunks() {
const playerChunkX = Math.floor(camera.position.x / (cellSize * chunkSize));
const playerChunkZ = Math.floor(camera.position.z / (cellSize * chunkSize));
// 新しいチャンクをロード
for (let dx = -renderDistance; dx <= renderDistance; dx++) {
for (let dz = -renderDistance; dz <= renderDistance; dz++) {
const chunkX = playerChunkX + dx;
const chunkZ = playerChunkZ + dz;
const key = getChunkKey(chunkX, chunkZ);
if (!loadedChunks.has(key)) {
const chunk = createMazeChunk(chunkX, chunkZ);
mazeGroup.add(chunk);
loadedChunks.set(key, chunk);
}
}
}
// 遠いチャンクをアンロード
for (const [key, chunk] of loadedChunks.entries()) {
const [chunkX, chunkZ] = key.split(',').map(Number);
const distance = Math.max(Math.abs(chunkX - playerChunkX), Math.abs(chunkZ - playerChunkZ));
if (distance > renderDistance + 1) {
mazeGroup.remove(chunk);
loadedChunks.delete(key);
}
}
}
// 初期チャンクをロード
updateChunks();
// 幻想的なBGM
let audioContext;
let masterGain;
let isAudioStarted = false;
let ambientVoices = [];
let rainSound = null;
let waterSound = null;
let dynamicOscillators = [];
let movementIntensity = 0;
let lastPosition = { x: 0, z: 0 };
let frictionSounds = [];
let isCollidingX = false;
let isCollidingZ = false;
let noiseGenerators = [];
function initAudio() {
if (isAudioStarted) return;
audioContext = new (window.AudioContext || window.webkitAudioContext)();
masterGain = audioContext.createGain();
masterGain.gain.value = 0.3;
masterGain.connect(audioContext.destination);
// アンビエント和音
const frequencies = [130.81, 164.81, 196.00, 246.94, 293.66]; // C3, E3, G3, B3, D4
frequencies.forEach((freq, index) => {
const voice = createAmbientVoice(freq, index);
ambientVoices.push(voice);
});
// 雨音と水音を追加
rainSound = createRainSound();
waterSound = createWaterSound();
// 動的オシレーターを作成
createDynamicOscillators();
// 摩擦音システムを作成
createFrictionSounds();
// ノイズジェネレーターを作成
createNoiseGenerators();
isAudioStarted = true;
}
function createAmbientVoice(baseFreq, voiceIndex) {
// オシレーター(基本波形)
const osc1 = audioContext.createOscillator();
const osc2 = audioContext.createOscillator();
osc1.type = 'triangle';
osc2.type = 'sine';
// 少しデチューンして厚みを出す
osc1.frequency.value = baseFreq;
osc2.frequency.value = baseFreq * 1.007; // わずかにずらす
// LFO(低周波振動)でビブラートを作る
const lfo = audioContext.createOscillator();
const lfoGain = audioContext.createGain();
lfo.type = 'sine';
lfo.frequency.value = 0.1 + voiceIndex * 0.05; // 各声部で異なる速度
lfoGain.gain.value = 2; // ビブラートの深さ
lfo.connect(lfoGain);
lfoGain.connect(osc1.frequency);
lfoGain.connect(osc2.frequency);
// フィルター(音色を柔らかく)
const filter1 = audioContext.createBiquadFilter();
const filter2 = audioContext.createBiquadFilter();
filter1.type = 'lowpass';
filter1.frequency.value = 800 + voiceIndex * 200;
filter1.Q.value = 1;
filter2.type = 'lowpass';
filter2.frequency.value = 600 + voiceIndex * 150;
filter2.Q.value = 1;
// ゲイン(音量制御)
const voiceGain = audioContext.createGain();
voiceGain.gain.value = 0.15 + Math.sin(voiceIndex) * 0.05;
// ディレイエフェクト(エコー)
const delay = audioContext.createDelay();
const delayFeedback = audioContext.createGain();
const delayMix = audioContext.createGain();
delay.delayTime.value = 0.3 + voiceIndex * 0.1;
delayFeedback.gain.value = 0.3;
delayMix.gain.value = 0.4;
// 接続
osc1.connect(filter1);
osc2.connect(filter2);
filter1.connect(voiceGain);
filter2.connect(voiceGain);
voiceGain.connect(delay);
delay.connect(delayFeedback);
delayFeedback.connect(delay);
delay.connect(delayMix);
voiceGain.connect(masterGain);
delayMix.connect(masterGain);
// LFOでフィルターも変調
const filterLfo = audioContext.createOscillator();
const filterLfoGain = audioContext.createGain();
filterLfo.type = 'sine';
filterLfo.frequency.value = 0.05 + voiceIndex * 0.02;
filterLfoGain.gain.value = 100;
filterLfo.connect(filterLfoGain);
filterLfoGain.connect(filter1.frequency);
// 開始
osc1.start();
osc2.start();
lfo.start();
filterLfo.start();
// 音量の変調(呼吸するような効果)
function modulateVolume() {
const now = audioContext.currentTime;
const breathRate = 0.03 + voiceIndex * 0.01;
const breathDepth = 0.1;
const targetVolume = 0.15 + Math.sin(now * breathRate) * breathDepth;
voiceGain.gain.setTargetAtTime(targetVolume, now, 1);
setTimeout(modulateVolume, 100);
}
modulateVolume();
// 音楽制御用オブジェクトを返す
return {
voiceGain: voiceGain,
filter1: filter1,
filter2: filter2,
delay: delay,
delayMix: delayMix
};
}
function createRainSound() {
// ホワイトノイズで雨音ベースを作る
const bufferSize = audioContext.sampleRate * 2; // 2秒のバッファ
const noiseBuffer = audioContext.createBuffer(1, bufferSize, audioContext.sampleRate);
const output = noiseBuffer.getChannelData(0);
// ホワイトノイズ生成
for (let i = 0; i < bufferSize; i++) {
output[i] = Math.random() * 2 - 1;
}
// ノイズソース
const whiteNoise = audioContext.createBufferSource();
whiteNoise.buffer = noiseBuffer;
whiteNoise.loop = true;
// 雨音用フィルター(高周波をカット)
const rainFilter1 = audioContext.createBiquadFilter();
rainFilter1.type = 'lowpass';
rainFilter1.frequency.value = 3000;
rainFilter1.Q.value = 1;
const rainFilter2 = audioContext.createBiquadFilter();
rainFilter2.type = 'highpass';
rainFilter2.frequency.value = 500;
rainFilter2.Q.value = 0.5;
// 雨音用ゲイン
const rainGain = audioContext.createGain();
rainGain.gain.value = 0.12;
// LFOで雨の強さを変調
const rainLfo = audioContext.createOscillator();
const rainLfoGain = audioContext.createGain();
rainLfo.type = 'sine';
rainLfo.frequency.value = 0.1;
rainLfoGain.gain.value = 0.03;
rainLfo.connect(rainLfoGain);
rainLfoGain.connect(rainGain.gain);
// 接続
whiteNoise.connect(rainFilter1);
rainFilter1.connect(rainFilter2);
rainFilter2.connect(rainGain);
rainGain.connect(masterGain);
// 開始
whiteNoise.start();
rainLfo.start();
return {
rainGain: rainGain,
rainFilter1: rainFilter1,
rainFilter2: rainFilter2
};
}
function createWaterSound() {
// 水の流れる音(低周波ノイズ + ゆらぎ)
const bufferSize = audioContext.sampleRate * 3; // 3秒のバッファ
const noiseBuffer = audioContext.createBuffer(1, bufferSize, audioContext.sampleRate);
const output = noiseBuffer.getChannelData(0);
// より滑らかなノイズ生成(水音用)
let previous = 0;
for (let i = 0; i < bufferSize; i++) {
const raw = Math.random() * 2 - 1;
output[i] = previous * 0.7 + raw * 0.3; // ローパス的な効果
previous = output[i];
}
// 水音ソース
const waterNoise = audioContext.createBufferSource();
waterNoise.buffer = noiseBuffer;
waterNoise.loop = true;
// 水音用フィルター(より低域)
const waterFilter1 = audioContext.createBiquadFilter();
waterFilter1.type = 'lowpass';
waterFilter1.frequency.value = 800;
waterFilter1.Q.value = 2;
const waterFilter2 = audioContext.createBiquadFilter();
waterFilter2.type = 'highpass';
waterFilter2.frequency.value = 100;
waterFilter2.Q.value = 0.3;
// 水音用ゲイン
const waterGain = audioContext.createGain();
waterGain.gain.value = 0.08;
// 水の流れの変調
const waterLfo1 = audioContext.createOscillator();
const waterLfoGain1 = audioContext.createGain();
waterLfo1.type = 'sine';
waterLfo1.frequency.value = 0.05;
waterLfoGain1.gain.value = 200;
waterLfo1.connect(waterLfoGain1);
waterLfoGain1.connect(waterFilter1.frequency);
// 水音のリバーブ効果
const waterDelay = audioContext.createDelay();
const waterDelayGain = audioContext.createGain();
const waterDelayFeedback = audioContext.createGain();
waterDelay.delayTime.value = 0.15;
waterDelayGain.gain.value = 0.3;
waterDelayFeedback.gain.value = 0.4;
// 接続
waterNoise.connect(waterFilter1);
waterFilter1.connect(waterFilter2);
waterFilter2.connect(waterGain);
waterGain.connect(waterDelay);
waterDelay.connect(waterDelayFeedback);
waterDelayFeedback.connect(waterDelay);
waterDelay.connect(waterDelayGain);
waterGain.connect(masterGain);
waterDelayGain.connect(masterGain);
// 開始
waterNoise.start();
waterLfo1.start();
return {
waterGain: waterGain,
waterFilter1: waterFilter1,
waterFilter2: waterFilter2,
waterDelayGain: waterDelayGain
};
}
function createDynamicOscillators() {
// 動的に変化する追加音源(音階なし)
const baseFrequencies = [80, 120, 160, 200]; // 低周波の基本周波数
// 複数の動的オシレーターを作成
for (let i = 0; i < 4; i++) {