-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
89 lines (81 loc) · 3.01 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
<!DOCTYPE html>
<html>
<head>
<title>3D Arwing Model</title>
<link rel="stylesheet" href="style/style.css" />
<meta charset="UTF-8" />
<link
rel="icon"
type="image/png"
sizes="64x64"
href="../style/images/favicon.png"
/>
</head>
<body>
<script id="vertexShader" type="not-js">
attribute vec3 vPosition;
attribute vec3 vNormal;
attribute vec3 vColor;
attribute vec2 vTexCoord;
varying vec3 fPosition;
varying vec3 fColor;
varying vec3 fNormal;
varying vec2 fTexCoord;
uniform mat4 uMV;
uniform mat4 uMVP;
void main(void) {
gl_Position = uMVP * vec4(vPosition, 1.0);
fPosition = (uMV * vec4(vPosition, 1.0)).xyz; // In camera coordinates
fColor = vColor;
fNormal = vNormal;
fTexCoord = vTexCoord;// In local coordinates
}
</script>
<script id="fragmentShader" type="not-js">
precision highp float;
//value unchanging for scene unless by host program, accessible by both v/s and f/s
uniform float time;
varying vec3 fPosition;
varying vec3 fColor;
varying vec3 fNormal;
varying vec2 fTexCoord;
uniform mat4 uMV;
uniform mat3 uMVn;
uniform sampler2D texSampler1;
uniform sampler2D texSampler2;
//model-view coordinates accesible between v/s and f/s
varying vec3 fRawX;
const vec3 lightV = vec3(0.0,-0.3,1.0);
const float lightI = 1.0; // only for diffuse component
const float ambientC = 0.75;
const float diffuseC = 0.75;
const float specularC = 0.75;
const float specularE = 32.0;
const vec3 lightCol = vec3(1.0,1.0,1.0);
const vec3 objectCol = vec3(1.0,1.0,1.0); // yellow-ish orange
vec2 blinnPhongDir(vec3 lightDir, vec3 n, float lightInt, float Ka,
float Kd, float Ks, float shininess) {
vec3 s = normalize(lightDir);
vec3 v = normalize(-fPosition);
vec3 h = normalize(v+s);
float diffuse = Ka + Kd * lightInt * max(0.0, dot(n, s));
float spec = Ks * pow(max(0.0, dot(n,h)), shininess);
return vec2(diffuse, spec);
}
void main(void) {
vec3 texColor=texture2D(texSampler1,fTexCoord).xyz;
vec3 n = normalize(uMVn * fNormal);
vec3 ColorS = blinnPhongDir(lightV,n,0.0 ,0.0, 0.0, specularC,specularE).y*lightCol;
vec3 ColorAD = blinnPhongDir(lightV,n,lightI,ambientC,diffuseC,0.0, 1.0 ).x*fColor;
gl_FragColor = vec4(ColorAD+ColorS,1.0);
}
</script>
<canvas id="mycanvas" width="500" height="500"></canvas>
<br />
<input id="slider1" type="range" min="-100" max="100" />
<input id="slider2" type="range" min="-100" max="100" />
<script type="text/javascript" src="scripts/gl-matrix-min.js"></script>
<script type="text/javascript" src="style/images/andross.imgjs"></script>
<script src="scripts/arwing.js" id="module"></script>
</body>
</html>