-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
240 lines (212 loc) · 8.06 KB
/
Copy pathindex.html
File metadata and controls
240 lines (212 loc) · 8.06 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
<!DOCTYPE html>
<html>
<head>
<title>DOOM64 - CS 440 Virtual Worlds</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: #000;
overflow: hidden;
font-family: 'Courier New', monospace;
}
canvas { display: block; }
#hud {
position: fixed;
top: 0; left: 0; right: 0;
display: flex;
justify-content: space-between;
padding: 10px 14px;
pointer-events: none;
color: #ff4400;
font-size: 12px;
text-shadow: 0 0 6px #ff4400;
z-index: 10;
}
#hud-left { display: flex; flex-direction: column; gap: 3px; }
#hud-right { display: flex; flex-direction: column; gap: 3px; text-align: right; }
#crosshair {
position: fixed;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
color: #ff4400;
font-size: 22px;
pointer-events: none;
text-shadow: 0 0 6px #ff4400;
}
#bar {
position: fixed;
bottom: 40px; left: 50%;
transform: translateX(-50%);
display: flex;
gap: 8px;
}
.sbtn {
background: rgba(0, 0, 0, 0.8);
border: 1px solid #ff4400;
color: #ff4400;
padding: 5px 14px;
cursor: pointer;
font-family: 'Courier New', monospace;
font-size: 11px;
transition: background 0.15s;
}
.sbtn:hover { background: rgba(255, 68, 0, 0.25); }
.sbtn.on { background: #ff4400; color: #000; }
#overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.9);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 100;
color: #ff4400;
font-family: 'Courier New', monospace;
}
#overlay h1 {
font-size: 56px;
letter-spacing: 12px;
text-shadow: 0 0 28px #ff4400;
margin-bottom: 4px;
}
#overlay h2 {
font-size: 13px;
letter-spacing: 4px;
color: #ff8844;
margin-bottom: 34px;
}
#overlay table { font-size: 12px; border-collapse: collapse; margin-bottom: 28px; }
#overlay td { padding: 2px 14px; color: #ff8844; }
#overlay td:first-child { color: #ffcc88; text-align: right; font-weight: bold; }
#gobtn {
border: 2px solid #ff4400;
background: none;
color: #ff4400;
padding: 10px 40px;
font-size: 15px;
letter-spacing: 4px;
cursor: pointer;
font-family: 'Courier New', monospace;
animation: pulse 1.5s ease-in-out infinite;
}
#gobtn:hover { background: #ff4400; color: #000; }
@keyframes pulse {
0%, 100% { box-shadow: 0 0 10px #ff440022; }
50% { box-shadow: 0 0 28px #ff4400bb; }
}
</style>
<script id="vertex-shader" type="x-shader/x-vertex">
attribute vec3 aPos;
attribute vec3 aNorm;
attribute vec3 aCol;
uniform mat4 uMVP;
uniform mat4 uModel;
uniform mat3 uNM;
uniform int uMode;
varying vec3 vCol;
varying vec3 vNorm;
varying vec3 vWorldPos;
void main() {
gl_Position = uMVP * vec4(aPos, 1.0);
vWorldPos = (uModel * vec4(aPos, 1.0)).xyz;
vNorm = normalize(uNM * aNorm);
vCol = aCol;
}
</script>
<script id="fragment-shader" type="x-shader/x-fragment">
#extension GL_OES_standard_derivatives : enable
precision mediump float;
varying vec3 vCol;
varying vec3 vNorm;
varying vec3 vWorldPos;
uniform int uMode;
uniform vec3 uLightPos;
uniform vec3 uEye;
const vec3 DIR_LIGHT = normalize(vec3(0.3, 0.8, 0.4));
void main() {
if (uMode == 0) {
// Wireframe
gl_FragColor = vec4(min(vCol * 1.6, vec3(1.0)), 1.0);
} else if (uMode == 1) {
// TRUE flat shading: reconstruct face normal from
// screen-space derivatives so each triangle gets
// one constant normal (faceted look).
vec3 dx = dFdx(vWorldPos);
vec3 dy = dFdy(vWorldPos);
vec3 N = normalize(cross(dx, dy));
float dif = max(dot(N, DIR_LIGHT), 0.0);
float fill = max(dot(N, vec3(0.0, 1.0, 0.0)), 0.0) * 0.18;
vec3 col = vCol * (0.30 + 0.70 * dif + fill);
gl_FragColor = vec4(min(col, vec3(1.0)), 1.0);
} else {
// Smooth Phong shading: interpolated normals +
// directional light + point light + specular.
vec3 N = normalize(vNorm);
// Directional diffuse
float dif1 = max(dot(N, DIR_LIGHT), 0.0);
// Point light from room centre for local variation
vec3 L2 = uLightPos - vWorldPos;
float dist = length(L2);
L2 = L2 / dist;
float att = 1.0 / (1.0 + 0.045 * dist + 0.007 * dist * dist);
float dif2 = max(dot(N, L2), 0.0) * att * 0.55;
// Up-fill
float fill = max(dot(N, vec3(0.0, 1.0, 0.0)), 0.0) * 0.15;
// Specular (directional)
vec3 V = normalize(uEye - vWorldPos);
vec3 R = reflect(-DIR_LIGHT, N);
float spe = pow(max(dot(V, R), 0.0), 48.0) * 0.40;
// Specular (point light)
vec3 R2 = reflect(-L2, N);
float spe2 = pow(max(dot(V, R2), 0.0), 48.0) * 0.25 * att;
vec3 col = vCol * (0.25 + 0.60 * dif1 + dif2 + fill) + vec3(spe + spe2);
gl_FragColor = vec4(min(col, vec3(1.0)), 1.0);
}
}
</script>
</head>
<body>
<canvas id="gl-canvas" width="800" height="600"></canvas>
<div id="hud">
<div id="hud-left">
<span id="hpos">POS: 0.0, 0.0, 0.0</span>
<span id="hang">YAW: 0° PITCH: 0° ROLL: 0°</span>
<span id="hfov">FOV: 75° NEAR: 0.15 FAR: 250</span>
<span id="hspd">SPEED: 5.0</span>
</div>
<div id="hud-right">
<span id="hshd">SHADING: FLAT</span>
<span id="hfps">FPS: --</span>
</div>
</div>
<div id="crosshair">+</div>
<div id="bar">
<button class="sbtn" onclick="setSh(0)">WIREFRAME</button>
<button class="sbtn on" onclick="setSh(1)">FLAT</button>
<button class="sbtn" onclick="setSh(2)">SMOOTH</button>
</div>
<div id="overlay">
<h1>DOOM64</h1>
<h2>CS 440 · VIRTUAL WORLDS</h2>
<table>
<tr><td>W A S D</td> <td>Move / Strafe</td></tr>
<tr><td>MOUSE</td> <td>Look (Yaw + Pitch)</td></tr>
<tr><td>Q / E</td> <td>Roll left / right</td></tr>
<tr><td>R / F</td> <td>Fly up / down</td></tr>
<tr><td>SHIFT</td> <td>Sprint</td></tr>
<tr><td>, / .</td><td>Speed down / up</td></tr>
<tr><td>↑ / ↓</td><td>FOV zoom in / out</td></tr>
<tr><td>← / →</td><td>Yaw (keyboard)</td></tr>
<tr><td>[ / ]</td> <td>Near / Far plane</td></tr>
<tr><td>Z / X</td> <td>Left / right view shift</td></tr>
<tr><td>1 / 2 / 3</td> <td>Wireframe / Flat / Smooth</td></tr>
</table>
<button id="gobtn" onclick="startGame()">[ CLICK TO ENTER ]</button>
</div>
<script src="common.js"></script>
<script src="webgl-utils.js"></script>
<script src="initShaders.js"></script>
<script src="main.js"></script>
</body>
</html>