-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
116 lines (92 loc) · 3.9 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
<!doctype html>
<html>
<head>
<title>VR 3D Reconstruction</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="description" content="Photorealistic 3D Moon using satellite imagery." />
<!-- Allow fullscreen app install in Android and IOS respectively -->
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<!-- Import external stylesheets -->
<link type="text/css" href="css/main.css" rel="stylesheet" />
</head>
<body>
<!-- Three.JS Container DOM Element -->
<div id="container"></div>
<!-- Overlay HUD -->
<div id="hud">
<div class="hud-panel top-center">
<h3 class="title">VR 3D Reconstruction of the Moon</h3>
<p>by Mohammad Seifanvari</p>
</div>
<div class="hud-panel top-right">
<em>h</em> to toggle HUD
<br /><em>p</em> for screenshot
<br /><em>f</em> for fullscreen
</div>
<div class="hud-panel bottom-right">
<a href="https://github.com/BlueKilvin/VR-3D-Reconstruction" target="_blank">source code</a>
</div>
<div class="hud-panel center"></div>
</div>
<div id="loading-container">
<h2>Loading Assets</h2>
<p id="loading-message"></p>
</div>
<!-- GLSL vertex shader for the moon -->
<script id="norm-vert-shader" type="x-shader/x-vertex">
attribute vec4 tangent;
uniform vec2 uvScale;
uniform vec3 lightPosition;
varying vec2 vUv;
varying mat3 tbn;
varying vec3 vLightVector;
void main() {
vUv = uvScale * uv;
/** Create tangent-binormal-normal matrix used to transform
coordinates from object space to tangent space */
vec3 vNormal = normalize(normalMatrix * normal);
vec3 vTangent = normalize( normalMatrix * tangent.xyz );
vec3 vBinormal = normalize(cross( vNormal, vTangent ) * tangent.w);
tbn = mat3(vTangent, vBinormal, vNormal);
/** Calculate the vertex-to-light vector */
vec4 lightVector = viewMatrix * vec4(lightPosition, 1.0);
vec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);
vLightVector = normalize(lightVector.xyz - modelViewPosition.xyz);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
</script>
<!-- GLSL fragment shader for the moon -->
<script id="norm-frag-shader" type="x-shader/x-fragment">
uniform sampler2D textureMap;
uniform sampler2D normalMap;
varying vec2 vUv;
varying mat3 tbn;
varying vec3 vLightVector;
void main() {
/** Transform texture coordinate of normal map to a range (-1, 1) */
vec3 normalCoordinate = texture2D(normalMap, vUv).xyz * 2.0 - 1.0;
/** Transform the normal vector in the RGB channels to tangent space */
vec3 normal = normalize(tbn * normalCoordinate.rgb);
/** Lighting intensity is calculated as dot of normal vector and
the vertex-to-light vector */
float intensity = max(0.07, dot(normal, vLightVector));
vec4 lighting = vec4(intensity, intensity, intensity, 1.0);
/** Final color is calculated with the lighting applied */
gl_FragColor = texture2D(textureMap, vUv) * lighting;
}
</script>
<!-- Include vendor scripts -->
<script type="text/javascript" src="vendor/three.min.js"></script>
<script type="text/javascript" src="vendor/TrackballControls.js"></script>
<script type="text/javascript" src="vendor/detector.min.js"></script>
<script type="text/javascript" src="vendor/stats.min.js"></script>
<script type="text/javascript" src="vendor/screenfull.min.js"></script>
<!-- Include Three.JS scene controller script -->
<script type="text/javascript" src="js/index.js"></script>
<noscript>
<p>You need javascript enabled in order to use this web application.</p>
</noscript>
</body>
</html>