-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
237 lines (191 loc) · 6.41 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
<!DOCTYPE html>
<html>
<p>SWITCHING OF LIGHT MODEL:
<input type="button" id="ButtonG" value="Shading"/>
</p>
<div>
<label for="slide_scaling">SCALING (%): 0</label>
<input id="slide_scaling" type="range" min="0.01" max="2" step="0.01" value="1"/>
<label for="slide_scaling">200</label>
</div>
<div>
<p> TRANSLATING ALONG AXES:
<label for="slide_translating_x"> X: </label>
<input id="slide_translating_x" type="range" min="-1" max="1" step="0.01" value="0"/>
<label for="slide_translating_x"> </label>
<label for="slide_translating_y"> Y:</label>
<input id="slide_translating_y" type="range" min="-1" max="1" step="0.01" value="0"/>
<label for="slide_translating_y"> </label>
<label for="slide_translating_z"> Z:</label>
<input id="slide_translating_z" type="range" min="-1" max="1" step="0.01" value="0"/>
<label for="slide_translating_z"> </label>
</p>
</div>
<div>
<p> VIEW PARAMETERS:
<label for="slide_radius">Radius 0.01</label>
<input id="slide_radius" type="range" min="0.01" max="10" step="0.01" value="3"/>
<label for="slide_radius">10</label>
<label for="slide_theta">Theta </label>
<input id="slide_theta" type="range" min="0" max="1000" step="0.1" value="0"/>
<label for="slide_theta"> </label>
<label for="slide_phi">Phi </label>
<input id="slide_phi" type="range" min="0" max="1000" step="0.1" value="0"/>
<label for="slide_phi"> </label>
</p>
</div>
<div>
<p> PROJECTION PARAMETERS:
<label for="slide_near"> Near 0.01</label>
<input id="slide_near" type="range" min="0.01" max="3" step="0.03" value="1.1"/>
<label for="slide_near">3</label>
<label for="slide_far">Far 5</label>
<input id="slide_far" type="range" min="5" max="20" step="0.01" value="15"/>
<label for="slide_far">20</label>
<label for="slide_fov">Fov 10</label>
<input id="slide_fov" type="range" min="10" max="120" step="1" value="60"/>
<label for="slide_fov">120</label>
</p>
</div>
<script id="phong-vertex-shader" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec4 vNormal;
varying vec3 N, L, E;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform vec4 lightPosition;
attribute vec4 vColor;
attribute vec2 vTexCoord;
varying vec4 fColor;
varying vec2 fTexCoord;
uniform vec3 theta;
void main()
{
vec3 pos = -(modelViewMatrix * vPosition).xyz;
vec3 light = (modelViewMatrix * lightPosition).xyz;
L = normalize( light - pos );
E = normalize(-pos);
N = normalize( (modelViewMatrix*vNormal).xyz);
// Compute the sines and cosines of theta for each of
// the three axes in one computation.
vec3 angles = radians( theta );
vec3 c = cos( angles );
vec3 s = sin( angles );
// Remeber: these matrices are column-major
mat4 rx = mat4( 1.0, 0.0, 0.0, 0.0,
0.0, c.x, s.x, 0.0,
0.0, -s.x, c.x, 0.0,
0.0, 0.0, 0.0, 1.0 );
mat4 ry = mat4( c.y, 0.0, -s.y, 0.0,
0.0, 1.0, 0.0, 0.0,
s.y, 0.0, c.y, 0.0,
0.0, 0.0, 0.0, 1.0 );
mat4 rz = mat4( c.z, s.z, 0.0, 0.0,
-s.z, c.z, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 );
fColor = vColor;
fTexCoord = vTexCoord;
gl_Position = projectionMatrix * modelViewMatrix * rz * ry * rx * vPosition;
gl_Position.z = gl_Position.z;
}
</script>
<script id="phong-fragment-shader" type="x-shader/x-fragment">
precision mediump float;
uniform vec4 ambientProduct;
uniform vec4 diffuseProduct;
uniform vec4 specularProduct;
uniform float shininess;
varying vec3 N, L, E;
varying vec4 fColor;
varying vec2 fTexCoord;
uniform sampler2D texture;
void main()
{
vec4 fColor;
vec3 H = normalize( L + E );
vec4 ambient = ambientProduct;
float Kd = max( dot(L, N), 0.0 );
vec4 diffuse = Kd*diffuseProduct;
float Ks = pow( max(dot(N, H), 0.0), shininess );
vec4 specular = Ks * specularProduct;
if( dot(L, N) < 0.0 ) specular = vec4(0.0, 0.0, 0.0, 1.0);
fColor = ambient + diffuse +specular;
fColor.a = 1.0;
gl_FragColor = fColor*texture2D( texture, fTexCoord );
}
</script>
<script id="gouraud-vertex-shader" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec4 vNormal;
varying vec4 fColor;
uniform vec4 ambientProduct, diffuseProduct, specularProduct;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform vec4 lightPosition;
uniform float shininess;
attribute vec4 vColor;
attribute vec2 vTexCoord;
varying vec2 fTexCoord;
uniform vec3 theta;
void main()
{
vec3 pos = -(modelViewMatrix * vPosition).xyz;
vec3 light = (modelViewMatrix * lightPosition).xyz;
vec3 L = normalize( light - pos );
vec3 E = normalize( -pos );
vec3 H = normalize( L + E );
// Transform vertex normal into eye coordinates
vec3 N = normalize( (modelViewMatrix*vNormal).xyz);
// Compute terms in the illumination equation
vec4 ambient = ambientProduct;
float Kd = max( dot(L, N), 0.0 );
vec4 diffuse = Kd*diffuseProduct;
float Ks = pow( max(dot(N, H), 0.0), shininess );
vec4 specular = Ks * specularProduct;
if( dot(L, N) < 0.0 ) specular = vec4(0.0, 0.0, 0.0, 1.0);
// Compute the sines and cosines of theta for each of
// the three axes in one computation.
vec3 angles = radians( theta );
vec3 c = cos( angles );
vec3 s = sin( angles );
// Remeber: these matrices are column-major
mat4 rx = mat4( 1.0, 0.0, 0.0, 0.0,
0.0, c.x, s.x, 0.0,
0.0, -s.x, c.x, 0.0,
0.0, 0.0, 0.0, 1.0 );
mat4 ry = mat4( c.y, 0.0, -s.y, 0.0,
0.0, 1.0, 0.0, 0.0,
s.y, 0.0, c.y, 0.0,
0.0, 0.0, 0.0, 1.0 );
mat4 rz = mat4( c.z, s.z, 0.0, 0.0,
-s.z, c.z, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 );
fColor = vColor;
fTexCoord = vTexCoord;
gl_Position = projectionMatrix * modelViewMatrix * rz * ry * rx * vPosition;
fColor = ambient + diffuse + specular;
fColor.a = 1.0;
}
</script>
<script id="gouraud-fragment-shader" type="x-shader/x-fragment">
precision mediump float;
varying vec4 fColor;
varying vec2 fTexCoord;
uniform sampler2D texture;
void main()
{
gl_FragColor = fColor * texture2D( texture, fTexCoord );
}
</script>
<script type="text/javascript" src="Common/webgl-utils.js"></script>
<script type="text/javascript" src="Common/initShaders.js"></script>
<script type="text/javascript" src="Common/MV.js"></script>
<script type="text/javascript" src="homework1.js"></script>
<body>
<canvas id="gl-canvas" width="1300" height="440">
Oops ... your browser doesn't support the HTML5 canvas element
</canvas>
</body>
</html>