-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
279 lines (231 loc) · 9.93 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="A WebGL FPS game with interactive controls and customizable settings.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Guns N' Poses - WebGL Edition</title>
<style>
body {
display: flex;
flex-direction: row;
margin: 0;
padding: 0;
}
#canvas {
border: 3px solid #000;
}
.controls {
margin-left: 30px;
margin-top: 30px;
font-size: 18px;
}
.controls h1 {
font-size: 22px;
}
#cooldown-container {
position: absolute;
bottom: 20px;
left: 42%;
transform: translateX(-50%);
width: 200px;
height: 40px;
background-color: rgb(37, 33, 33);
border: 2px solid black;
border-radius: 5px;
overflow: hidden;
z-index: 100;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 5px 0;
}
#cooldown-label {
font-size: 14px;
font-weight: bold;
margin-bottom: 5px;
color: white;
}
#cooldownBar {
width: 0%;
height: 20px;
background-color: rgb(143, 5, 5);
border-radius: 3px;
transition: width 0.1s linear;
}
</style>
</head>
<body>
<canvas id="canvas" width="1600" height="900"></canvas>
<div id="cooldown-container">
<span id="cooldown-label">Weapon Cooldown</span>
<div id="cooldownBar"></div>
</div>
<div class="controls">
<!-- <label for="slider1">Mouse Sensitivity:</label>
<input id="slider1" type="range" min="1" max="10" /> -->
<label for="fovSlider">Field of View:</label>
<input id="fovSlider" type="range" min="55" max="95" step="1" value="65">
<p>FOV: <span id="fovValue">65</span>°</p>
<h1>Game Controls</h1>
<ul>
<li><strong>W</strong>: Walk Forward</li>
<li><strong>S</strong>: Walk Backward</li>
<li><strong>A</strong>: Move Left</li>
<li><strong>D</strong>: Move Right</li>
<li><strong>Shift</strong>: Sprint</li>
<!-- <li><strong>C</strong>: Crouch</li> -->
<li><strong>Space</strong>: Jump</li>
<li><strong>Mouse Button</strong>: Shoot</li>
<!-- <li><strong>Right Mouse Button</strong>: Charged Shot</li>
<li><strong>V</strong>: Display Path</li> -->
</ul>
<p><strong>Instructions:</strong> Click on the game to take pointer control. Press <strong>Esc</strong> to exit pointer control.</p>
<p>The game features physics-driven mechanics that allow players to jump between surfaces, climb and fall from stairs, and travel on moving platforms. Platforms are dynamically animated, with their speed and rotation influenced by the rate of fire. The gun animations, inspired by the service weapon from Control by Remedy Entertainment, include rotational effects and changes in distance from the barrel, both intensifying with the rate of fire. Ground, stairs, and platforms are enhanced with texture and normal maps for detailed 3D surface realism.</p>
</div>
<!-- Vertex Shader -->
<script id="vertex-shader" type="x-shader/x-vertex">
attribute vec3 aPosition;
attribute vec3 aNormal;
uniform mat4 uModelMatrix;
uniform mat4 uViewMatrix;
uniform mat4 uProjectionMatrix;
uniform mat3 uNormalMatrix;
varying vec3 vNormal;
varying vec3 vPosition;
void main() {
vec4 worldPosition = uModelMatrix * vec4(aPosition, 1.0);
vPosition = worldPosition.xyz;
vNormal = normalize(uNormalMatrix * aNormal);
gl_Position = uProjectionMatrix * uViewMatrix * worldPosition;
}
</script>
<script id="vertex-texture" type="x-shader/x-vertex">
attribute vec3 aPosition;
attribute vec3 aNormal;
attribute vec2 aTexCoord;
uniform mat4 uModelMatrix;
uniform mat4 uViewMatrix;
uniform mat4 uProjectionMatrix;
uniform mat3 uNormalMatrix;
varying vec3 vNormal;
varying vec3 vPosition;
varying vec2 vTexCoord;
void main() {
vec4 worldPosition = uModelMatrix * vec4(aPosition, 1.0);
vPosition = worldPosition.xyz;
vNormal = normalize(uNormalMatrix * aNormal);
vTexCoord = aTexCoord;
gl_Position = uProjectionMatrix * uViewMatrix * worldPosition;
}
</script>
<script id="fragment-bullet" type="x-shader/x-fragment">
precision mediump float;
varying vec3 vNormal;
varying vec3 vPosition;
uniform vec3 uLightDirection;
uniform vec3 uLightColor;
uniform vec3 uObjectColor;
uniform vec3 uViewPosition;
const float reflectionStrength = 0.07;
void main() {
vec3 lightDir = normalize(uLightDirection);
vec3 viewDir = normalize(uViewPosition - vPosition);
float ambientStrength = 0.5;
vec3 ambient = ambientStrength * uLightColor;
float diffuseStrength = max(dot(vNormal, -lightDir), 0.0);
vec3 diffuse = diffuseStrength * uLightColor;
vec3 reflectDir = reflect(lightDir, vNormal);
float shininess = 10.0;
float specularStrength = 40.0;
float spec = 0.0;
if (diffuseStrength > 0.0) {
spec = pow(max(dot(viewDir, reflectDir), 0.0), shininess);
}
vec3 specular = specularStrength * spec * uLightColor;
vec3 finalColor = (ambient + diffuse) * uObjectColor + specular * uLightColor ;
gl_FragColor = vec4(finalColor, 1.0);
//gl_FragColor = vec4(vNormal * 0.5 + 0.5, 1.0);
}
</script>
<script id="fragment-bpd" type="x-shader/x-fragment">
precision mediump float;
varying vec3 vNormal;
varying vec3 vPosition;
uniform vec3 uLightDirection;
uniform vec3 uLightColor;
uniform vec3 uObjectColor;
uniform vec3 uViewPosition;
const float reflectionStrength = 0.07;
void main() {
vec3 lightDir = normalize(uLightDirection);
vec3 viewDir = normalize(uViewPosition - vPosition);
float ambientStrength = 0.02;
vec3 ambient = ambientStrength * uLightColor;
float diffuseStrength = max(dot(vNormal, -lightDir), 0.0);
vec3 diffuse = diffuseStrength * uLightColor;
vec3 reflectDir = reflect(lightDir, vNormal);
float shininess = 100.0;
float specularStrength = 40.0;
float spec = 0.0;
if (diffuseStrength > 0.0) {
spec = pow(max(dot(viewDir, reflectDir), 0.0), shininess);
}
vec3 specular = specularStrength * spec * uLightColor;
vec3 reflectionDir = reflect(viewDir, vNormal);
vec3 reflectionColor = vec3(0.8, 0.9, 1.0);
float reflectionIntensity = pow(max(dot(viewDir, reflectionDir), 0.0), 4.0);
vec3 reflection = reflectionStrength * reflectionIntensity * reflectionColor;
vec3 finalColor = (ambient + diffuse) * uObjectColor + specular * uLightColor + reflection;
gl_FragColor = vec4(finalColor, 1.0);
//gl_FragColor = vec4(vNormal * 0.5 + 0.5, 1.0);
}
</script>
<script id="fragment-texture" type="x-shader/x-fragment">
precision mediump float;
varying vec3 vNormal;
varying vec3 vPosition;
varying vec2 vTexCoord;
uniform vec3 uLightDirection;
uniform vec3 uLightColor;
uniform vec3 uViewPosition;
uniform sampler2D uTexture;
uniform sampler2D uNormalMap;
void main() {
vec3 normalMap = texture2D(uNormalMap, vTexCoord).rgb;
vec3 tangentNormal = normalize(normalMap * 2.0 - 1.0);
vec3 worldNormal = normalize(tangentNormal);
vec3 lightDir = normalize(-uLightDirection);
vec3 viewDir = normalize(uViewPosition - vPosition);
float diffuseStrength = max(dot(worldNormal, lightDir), 0.0);
vec3 diffuse = diffuseStrength * uLightColor;
vec3 reflectDir = reflect(-lightDir, worldNormal);
float shininess = 32.0;
float specularStrength = 0.4;
float spec = pow(max(dot(viewDir, reflectDir), 0.0), shininess);
vec3 specular = specularStrength * spec * uLightColor;
float ambientStrength = 0.1;
vec3 ambient = ambientStrength * uLightColor;
vec4 texColor = texture2D(uTexture, vTexCoord);
vec3 finalColor = texColor.rgb * (ambient + diffuse) + specular;
gl_FragColor = vec4(finalColor, texColor.a);
}
</script>
<!-- JavaScript Modules -->
<script type="module">
document.addEventListener('DOMContentLoaded', function() {
const fovSlider = document.getElementById('fovSlider');
const fovValueDisplay = document.getElementById('fovValue');
// Set the initial FOV value
fovValueDisplay.textContent = fovSlider.value;
// Update FOV value when slider is moved
fovSlider.addEventListener('input', function() {
fovValueDisplay.textContent = this.value;
});
});
</script>
<script type="text/javascript" src="gl-matrix-min.js"></script>
<script type="module" src="mainGL.js"></script>
</body>
</html>