-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlecture.html
More file actions
226 lines (158 loc) · 7.51 KB
/
lecture.html
File metadata and controls
226 lines (158 loc) · 7.51 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
<html>
<head>
<meta charset="utf-8">
<title>DataX</title>
<h1> <li><a href="lecture.html">Lecture Materials for DataX</a></li></h1>
<ul>
<p><a href="https://github.com/ikhlaqsidhu/data-x">GitHub</a> </p>
<p><a href="http://tinyurl.com/IEOR290"> Slides </a> </p>
<p><a href="https://github.com/vbartle/dialogsystems.github.io/blob/master/LEC3.14%20%40%20DataX.ipynb">Jupyter Notebook</a> </p>
</ul>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.16/p5.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.16/p5.min.js"></script>
<!-- <script src="../../../../src/p5.js/lib/p5.js"></script> -->
<link rel="stylesheet" type="text/css" href="style.css">
<script id="phong.vert" type="x-shader/x-vertex">
#ifdef GL_ES
precision highp float;
precision mediump int;
#endif
// attributes, in
attribute vec3 aPosition;
attribute vec3 aNormal;
attribute vec2 aTexCoord;
attribute vec4 aVertexColor;
// attributes, out
varying vec3 var_vertPos;
varying vec4 var_vertCol;
varying vec3 var_vertNormal;
varying vec2 var_vertTexCoord;
// matrices
uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;
uniform mat3 uNormalMatrix;
void main() {
gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
// just passing things through
var_vertPos = aPosition;
var_vertCol = aVertexColor;
var_vertNormal = aNormal;
var_vertTexCoord = aTexCoord;
}
</script>
<script id="phong.frag" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
precision mediump int;
#endif
// vertex-data, passing through
varying vec3 var_vertPos;
varying vec4 var_vertCol;
varying vec3 var_vertNormal;
varying vec2 var_vertTexCoord;
// matrices
uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;
uniform mat3 uNormalMatrix;
struct Ambientlight{
vec3 col;
};
struct DirectLight {
vec3 dir;
vec3 col;
};
struct PointLight {
vec3 pos;
vec3 col;
float att;
};
struct Material {
vec3 diff;
vec3 spec;
float spec_exp;
};
// lights
uniform Ambientlight ambientlight;
#define NUM_DIRECTLIGHTS 1
uniform DirectLight directlights[NUM_DIRECTLIGHTS];
#define NUM_POINTLIGHTS 3
uniform PointLight pointlights[NUM_POINTLIGHTS];
// materials
uniform Material material;
float smootherstep(float edge0, float edge1, float x) {
x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return x * x * x * (x * (x * 6.0 - 15.0) + 10.0);
}
float attenuation(float att, float dist){
float attinv = 1.0 / att;
// return 1.0 / (1.0 + attinv*dist + attinv*attinv*dist*dist);
return smootherstep(att, 0.0, dist);
}
float getKd(vec3 vertNormal, vec3 lightDir){
return max(dot(-lightDir, vertNormal), 0.0);
}
float getKs(vec3 vertNormal, vec3 lightDir, vec3 vertDir){
lightDir = normalize(reflect(lightDir, vertNormal));
return pow(max(dot(lightDir, vertDir), 0.0), material.spec_exp);
}
void main() {
// camera/eye space
vec3 vertNormal = normalize(uNormalMatrix * var_vertNormal);
vec3 vertPos = (uModelViewMatrix * vec4(var_vertPos, 1)).xyz;
vec3 vertDir = -normalize(vertPos);
// summed up light contributions
vec3 fragcol = vec3(0.0);
float kdView = 1.0;// - sqrt(max(dot(vertNormal, vertDir), 0.0));
// if(!gl_FrontFacing)
{
// ambientlight
{
fragcol += material.diff * ambientlight.col;
}
// directlights
for(int i = 0; i < NUM_DIRECTLIGHTS; i++)
{
DirectLight light = directlights[i];
// light direction
vec3 lightDir = light.dir;
// diffuse, specular
float kd = getKd(vertNormal, lightDir);
float ks = getKs(vertNormal, lightDir, vertDir) * kdView;
fragcol += material.diff * light.col * kd;
fragcol += material.spec * light.col * ks * (1.0 - step(kd, 0.0));
}
// pointlights
for(int i = 0; i < NUM_POINTLIGHTS; i++)
{
PointLight light = pointlights[i];
// light direction
vec3 lightDir = normalize(vertPos - light.pos);
// attenuation/fallofff
float lightDist = distance(light.pos, vertPos);
float att = attenuation(light.att, lightDist);
// diffuse specular
float kd = getKd(vertNormal, lightDir );
float ks = getKs(vertNormal, lightDir, vertDir) * kdView;
fragcol += material.diff * light.col * kd * att;
fragcol += material.spec * light.col * ks * att * (1.0 - step(kd, 0.0));
}
}
fragcol = clamp(fragcol, 0.0, 1.0);
// frag, out
gl_FragColor = vec4(fragcol, 1);
// gamma, 2.2
gl_FragColor.xyz = pow(gl_FragColor.xyz, vec3(1.0/2.2));
gl_FragColor = clamp(gl_FragColor, vec4(0.0), vec4(1.0));
}
</script>
</head>
<body oncontextmenu="return false;">
<div id="hud" class="unselectable"><ul></ul></div>
<script src="p5.easycam.js"></script>
<script src="Letter.js" type="text/javascript"></script>
<script src="Word.js" type="text/javascript"></script>
<script src="mySketch.js" type="text/javascript"></script>
</body>
</html>